[SCM] WebKit Debian packaging branch, webkit-1.3, updated. upstream/1.3.7-4207-g178b198

yurys at chromium.org yurys at chromium.org
Sun Feb 20 23:24:07 UTC 2011


The following commit has been merged in the webkit-1.3 branch:
commit c8a06eb946ed0cbe5c144daa894c1fdb5d9f190a
Author: yurys at chromium.org <yurys at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Thu Jan 20 09:28:54 2011 +0000

    2010-12-27  yury semikhatsky  <yurys at chromium.org>
    
            reviewed by pavel feldman.
    
            webcore doesn't fire window.onerror event when uncaught javascript exceptions are thrown
            https://bugs.webkit.org/show_bug.cgi?id=8519
    
            uncaught exceptions are propagated to window.onerror hander if one is present.
            the handler is expected to be a function accepting three arguments: error message,
            resource url and line number where the exception occured.
    
            it was decided to dispatch errorevent to all listeners/handlers no matter if they
            were created in the same isolated world where the exception occured or not.
    
            tests: fast/events/window-onerror1.html
                   fast/events/window-onerror10.html
                   fast/events/window-onerror11.html
                   fast/events/window-onerror12.html
                   fast/events/window-onerror2.html
                   fast/events/window-onerror3.html
                   fast/events/window-onerror4.html
                   fast/events/window-onerror5.html
                   fast/events/window-onerror6.html
                   fast/events/window-onerror7.html
                   fast/events/window-onerror8.html
                   fast/events/window-onerror9.html
                   http/tests/security/window-onerror-exception-in-iframe.html
                   userscripts/window-onerror-for-isolated-world-1.html
                   userscripts/window-onerror-for-isolated-world-2.html
    
            * android.jscbindings.mk:
            * cmakelists.txt:
            * gnumakefile.am:
            * webcore.gypi:
            * webcore.order:
            * webcore.pro:
            * webcore.vcproj/webcore.vcproj:
            * webcore.xcodeproj/project.pbxproj:
            * bindings/js/jsbindingsallinone.cpp:
            * bindings/js/jsdombinding.cpp:
            (webcore::reportexception):
            * bindings/js/jserrorhandler.cpp: renamed from webcore/bindings/js/jsworkercontexterrorhandler.cpp.
            (webcore::jserrorhandler::jserrorhandler):
            (webcore::jserrorhandler::~jserrorhandler):
            (webcore::jserrorhandler::handleevent):
            * bindings/js/jserrorhandler.h: copied from webcore/bindings/js/jsworkercontexterrorhandler.h.
            (webcore::jserrorhandler::create):
            (webcore::createjserrorhandler):
            * bindings/js/jseventlistener.h:
            * bindings/scripts/codegeneratorjs.pm:
            * bindings/scripts/codegeneratorv8.pm:
            * bindings/v8/v8consolemessage.cpp:
            (webcore::v8consolemessage::dispatchnow):
            (webcore::v8consolemessage::handler): the method was changed to use generic webcore exception
            reporting mechanism which is also used by jsc bindings.
            * bindings/v8/v8consolemessage.h:
            * bindings/v8/v8eventlistener.h:
            * bindings/v8/v8windowerrorhandler.cpp: renamed from webcore/bindings/js/jsworkercontexterrorhandler.h.
            (webcore::v8windowerrorhandler::v8windowerrorhandler):
            (webcore::v8windowerrorhandler::calllistenerfunction):
            * bindings/v8/v8windowerrorhandler.h: copied from webcore/dom/errorevent.cpp.
            (webcore::v8windowerrorhandler::create):
            * bindings/v8/workercontextexecutionproxy.cpp:
            (webcore::v8messagehandler):
            * bindings/v8/workerscriptcontroller.cpp:
            (webcore::workerscriptcontroller::evaluate):
            * dom/document.cpp:
            (webcore::document::erroreventtarget):
            (webcore::document::logexceptiontoconsole):
            (webcore::document::addmessage):
            * dom/document.h:
            * dom/errorevent.cpp:
            * dom/errorevent.h:
            * dom/event.cpp:
            (webcore::event::iserrorevent):
            * dom/event.h:
            * dom/scriptexecutioncontext.cpp:
            (webcore::scriptexecutioncontext::pendingexception::pendingexception):
            (webcore::scriptexecutioncontext::scriptexecutioncontext):
            (webcore::scriptexecutioncontext::reportexception): this method is not virtual anymore to
            ensure that error event dispatching algorithm is the same in workercontext and in document.
            (webcore::scriptexecutioncontext::dispatcherrorevent):
            * dom/scriptexecutioncontext.h:
            * websockets/websocket.cpp:
            (webcore::websocket::connect):
            * websockets/websocketchannel.cpp:
            (webcore::websocketchannel::didopen):
            (webcore::websocketchannel::didfail):
            (webcore::websocketchannel::appendtobuffer):
            * websockets/websockethandshake.cpp:
            (webcore::websockethandshake::readserverhandshake):
            (webcore::websockethandshake::readstatusline):
            (webcore::websockethandshake::readhttpheaders):
            (webcore::websockethandshake::checkresponseheaders):
            * workers/defaultsharedworkerrepository.cpp:
            (webcore::postexceptiontask):
            (webcore::postconsolemessagetask):
            * workers/workercontext.cpp:
            (webcore::workercontext::workercontext):
            (webcore::workercontext::erroreventtarget):
            (webcore::workercontext::logexceptiontoconsole):
            (webcore::workercontext::addmessage):
            * workers/workercontext.h:
            * workers/workermessagingproxy.cpp:
            (webcore::workerexceptiontask::performtask):
            (webcore::postconsolemessagetask):
            * xml/xmlhttprequest.cpp:
            (webcore::reportunsafeusage):
    
    2010-12-27  Yury Semikhatsky  <yurys at chromium.org>
    
            Reviewed by Pavel Feldman.
    
            WebCore doesn't fire window.onerror event when uncaught JavaScript exceptions are thrown
            https://bugs.webkit.org/show_bug.cgi?id=8519
    
            Uncaught exceptions are propagated to window.onerror hander if one is present.
            The handler is expected to be a function accepting three arguments: error message,
            resource url and line number where the exception occured.
    
            * fast/events/resources/window-onerror.js: Added.
            (throwException):
            * fast/events/window-onerror1-expected.txt: Added.
            * fast/events/window-onerror1.html: Added.
            * fast/events/window-onerror10-expected.txt: Added.
            * fast/events/window-onerror10.html: Added.
            * fast/events/window-onerror11-expected.txt: Added.
            * fast/events/window-onerror11.html: Added.
            * fast/events/window-onerror12-expected.txt: Added.
            * fast/events/window-onerror12.html: Added.
            * fast/events/window-onerror2-expected.txt: Added.
            * fast/events/window-onerror2.html: Added.
            * fast/events/window-onerror3-expected.txt: Added.
            * fast/events/window-onerror3.html: Added.
            * fast/events/window-onerror4-expected.txt: Added.
            * fast/events/window-onerror4.html: Added.
            * fast/events/window-onerror5-expected.txt: Added.
            * fast/events/window-onerror5.html: Added.
            * fast/events/window-onerror6-expected.txt: Added.
            * fast/events/window-onerror6.html: Added.
            * fast/events/window-onerror7-expected.txt: Added.
            * fast/events/window-onerror7.html: Added.
            * fast/events/window-onerror8-expected.txt: Added.
            * fast/events/window-onerror8.html: Added.
            * fast/events/window-onerror9-expected.txt: Added.
            * fast/events/window-onerror9.html: Added.
            * fast/workers/worker-script-error-expected.txt:
            * http/tests/security/resources/onerror-iframe.html: Added.
            * http/tests/security/window-onerror-exception-in-iframe-expected.txt: Added.
            * http/tests/security/window-onerror-exception-in-iframe.html: Added.
            * platform/chromium-win/fast/workers/worker-script-error-expected.txt:
            * platform/chromium/fast/events/window-onerror1-expected.txt: Added.
            * platform/chromium/fast/events/window-onerror10-expected.txt: Added.
            * platform/chromium/fast/events/window-onerror11-expected.txt: Added.
            * platform/chromium/fast/events/window-onerror2-expected.txt: Added.
            * platform/chromium/fast/events/window-onerror3-expected.txt: Added.
            * platform/chromium/fast/events/window-onerror4-expected.txt: Added.
            * platform/chromium/fast/events/window-onerror5-expected.txt: Added.
            * platform/chromium/fast/events/window-onerror6-expected.txt: Added.
            * platform/chromium/fast/events/window-onerror7-expected.txt: Added.
            * platform/chromium/fast/events/window-onerror8-expected.txt: Added.
            * platform/chromium/fast/events/window-onerror9-expected.txt: Added.
            * platform/chromium/http/tests/security/window-onerror-exception-in-iframe-expected.txt: Added.
            * platform/chromium/userscripts/window-onerror-for-isolated-world-1-expected.txt: Added.
            * platform/chromium/userscripts/window-onerror-for-isolated-world-2-expected.txt: Added.
            * platform/gtk/Skipped:
            * userscripts/window-onerror-for-isolated-world-1-expected.txt: Added.
            * userscripts/window-onerror-for-isolated-world-1.html: Added.
            * userscripts/window-onerror-for-isolated-world-2-expected.txt: Added.
            * userscripts/window-onerror-for-isolated-world-2.html: Added.
    
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@76216 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index f8a469c..263c9da 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,65 @@
+2010-12-27  Yury Semikhatsky  <yurys at chromium.org>
+
+        Reviewed by Pavel Feldman.
+
+        WebCore doesn't fire window.onerror event when uncaught JavaScript exceptions are thrown
+        https://bugs.webkit.org/show_bug.cgi?id=8519
+
+        Uncaught exceptions are propagated to window.onerror hander if one is present.
+        The handler is expected to be a function accepting three arguments: error message,
+        resource url and line number where the exception occured.
+
+        * fast/events/resources/window-onerror.js: Added.
+        (throwException):
+        * fast/events/window-onerror1-expected.txt: Added.
+        * fast/events/window-onerror1.html: Added.
+        * fast/events/window-onerror10-expected.txt: Added.
+        * fast/events/window-onerror10.html: Added.
+        * fast/events/window-onerror11-expected.txt: Added.
+        * fast/events/window-onerror11.html: Added.
+        * fast/events/window-onerror12-expected.txt: Added.
+        * fast/events/window-onerror12.html: Added.
+        * fast/events/window-onerror2-expected.txt: Added.
+        * fast/events/window-onerror2.html: Added.
+        * fast/events/window-onerror3-expected.txt: Added.
+        * fast/events/window-onerror3.html: Added.
+        * fast/events/window-onerror4-expected.txt: Added.
+        * fast/events/window-onerror4.html: Added.
+        * fast/events/window-onerror5-expected.txt: Added.
+        * fast/events/window-onerror5.html: Added.
+        * fast/events/window-onerror6-expected.txt: Added.
+        * fast/events/window-onerror6.html: Added.
+        * fast/events/window-onerror7-expected.txt: Added.
+        * fast/events/window-onerror7.html: Added.
+        * fast/events/window-onerror8-expected.txt: Added.
+        * fast/events/window-onerror8.html: Added.
+        * fast/events/window-onerror9-expected.txt: Added.
+        * fast/events/window-onerror9.html: Added.
+        * fast/workers/worker-script-error-expected.txt:
+        * http/tests/security/resources/onerror-iframe.html: Added.
+        * http/tests/security/window-onerror-exception-in-iframe-expected.txt: Added.
+        * http/tests/security/window-onerror-exception-in-iframe.html: Added.
+        * platform/chromium-win/fast/workers/worker-script-error-expected.txt:
+        * platform/chromium/fast/events/window-onerror1-expected.txt: Added.
+        * platform/chromium/fast/events/window-onerror10-expected.txt: Added.
+        * platform/chromium/fast/events/window-onerror11-expected.txt: Added.
+        * platform/chromium/fast/events/window-onerror2-expected.txt: Added.
+        * platform/chromium/fast/events/window-onerror3-expected.txt: Added.
+        * platform/chromium/fast/events/window-onerror4-expected.txt: Added.
+        * platform/chromium/fast/events/window-onerror5-expected.txt: Added.
+        * platform/chromium/fast/events/window-onerror6-expected.txt: Added.
+        * platform/chromium/fast/events/window-onerror7-expected.txt: Added.
+        * platform/chromium/fast/events/window-onerror8-expected.txt: Added.
+        * platform/chromium/fast/events/window-onerror9-expected.txt: Added.
+        * platform/chromium/http/tests/security/window-onerror-exception-in-iframe-expected.txt: Added.
+        * platform/chromium/userscripts/window-onerror-for-isolated-world-1-expected.txt: Added.
+        * platform/chromium/userscripts/window-onerror-for-isolated-world-2-expected.txt: Added.
+        * platform/gtk/Skipped:
+        * userscripts/window-onerror-for-isolated-world-1-expected.txt: Added.
+        * userscripts/window-onerror-for-isolated-world-1.html: Added.
+        * userscripts/window-onerror-for-isolated-world-2-expected.txt: Added.
+        * userscripts/window-onerror-for-isolated-world-2.html: Added.
+
 2011-01-19  MORITA Hajime  <morrita at google.com>
 
         Reviewed by Ryosuke Niwa.
diff --git a/LayoutTests/fast/events/resources/window-onerror.js b/LayoutTests/fast/events/resources/window-onerror.js
new file mode 100644
index 0000000..344574b
--- /dev/null
+++ b/LayoutTests/fast/events/resources/window-onerror.js
@@ -0,0 +1,3 @@
+function throwException() {
+    throw new Error("An exception");
+}
diff --git a/LayoutTests/fast/events/window-onerror1-expected.txt b/LayoutTests/fast/events/window-onerror1-expected.txt
new file mode 100644
index 0000000..fe51b72
--- /dev/null
+++ b/LayoutTests/fast/events/window-onerror1-expected.txt
@@ -0,0 +1,3 @@
+This page tests setting onerror handlers through the DOM. If it passes, you will see "PASS" messages below.Bug 8519.
+
+PASS: caught global error: ReferenceError: Can't find variable: hahaha_good_luck_finding_me at window-onerror1.html:25
diff --git a/LayoutTests/fast/events/window-onerror1.html b/LayoutTests/fast/events/window-onerror1.html
new file mode 100644
index 0000000..59d2495
--- /dev/null
+++ b/LayoutTests/fast/events/window-onerror1.html
@@ -0,0 +1,35 @@
+<html>
+<head>
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+function print(message, color)
+{
+    var paragraph = document.createElement("div");
+    paragraph.appendChild(document.createTextNode(message));
+    paragraph.style.fontFamily = "monospace";
+    if (color)
+        paragraph.style.color = color;
+    document.getElementById("console").appendChild(paragraph);
+}
+
+function test()
+{
+    // must be last because the exception ends JavaScript execution
+    window.onerror = function (error, url, line) {
+        url = url ? url.match( /[^\/]+\/?$/ )[0] : url;
+        print("PASS: caught global error: " + error + " at " + url + ":" + line, "green");
+        return false;
+    };
+    hahaha_good_luck_finding_me(); // caught by window.onerror
+}
+</script>
+</head>
+<body onload="test();">
+<p>This page tests setting onerror handlers through the DOM. If it passes, you will
+   see "PASS" messages below.<a href="https://bugs.webkit.org/show_bug.cgi?id=8519">Bug 8519</a>.</p>
+<hr>
+<div id='console'></div>
+</body>
+</html>
diff --git a/LayoutTests/fast/events/window-onerror10-expected.txt b/LayoutTests/fast/events/window-onerror10-expected.txt
new file mode 100644
index 0000000..bff5636
--- /dev/null
+++ b/LayoutTests/fast/events/window-onerror10-expected.txt
@@ -0,0 +1,11 @@
+Test that "error" event listener added with window.addEventListener is invoked for uncaucht exceptions. Bug 8519.
+
+event passed to the listener is the same as window.event: true
+Event details:
+type: error
+phase: 2
+currentTarget is the global object: true
+message: Error: My fault.
+filename: window-onerror10.html
+lineno: 29
+
diff --git a/LayoutTests/fast/events/window-onerror10.html b/LayoutTests/fast/events/window-onerror10.html
new file mode 100644
index 0000000..26ed018
--- /dev/null
+++ b/LayoutTests/fast/events/window-onerror10.html
@@ -0,0 +1,33 @@
+<html>
+<body>
+<p>Test that "error" event listener added with window.addEventListener is invoked for uncaucht exceptions. <a href="https://bugs.webkit.org/show_bug.cgi?id=8519">Bug 8519</a>.</p>
+<div id="console"></div>
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+function log(msg) {
+    document.getElementById("console").innerHTML += msg + "<br>";
+}
+
+function lastPathComponent(url) {
+    return url ? url.match( /[^\/]+\/?$/ )[0] : url;
+}
+
+window.addEventListener("error", function(e) {
+    log("event passed to the listener is the same as window.event: " + (window.event === e));
+    log("Event details:");
+    log("type: " + e.type);
+    log("phase: " + e.eventPhase)
+    log("currentTarget is the global object: " + (e.currentTarget === window));
+    log("message: " + e.message);
+    log("filename: " + lastPathComponent(e.filename));
+    log("lineno: " + e.lineno);
+    e.preventDefault();
+}, false);
+
+throw new Error("My fault.");
+
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/events/window-onerror11-expected.txt b/LayoutTests/fast/events/window-onerror11-expected.txt
new file mode 100644
index 0000000..96e20cc
--- /dev/null
+++ b/LayoutTests/fast/events/window-onerror11-expected.txt
@@ -0,0 +1,4 @@
+Test that window.onerror is called on window object. Bug 8519.
+
+Main frame window.onerror: Error: An exception at window-onerror.js:2
+
diff --git a/LayoutTests/fast/events/window-onerror11.html b/LayoutTests/fast/events/window-onerror11.html
new file mode 100644
index 0000000..7655fa7
--- /dev/null
+++ b/LayoutTests/fast/events/window-onerror11.html
@@ -0,0 +1,28 @@
+<html>
+<head>
+<script src="resources/window-onerror.js">
+</script>
+</head>
+<body>
+<p>Test that window.onerror is called on window object. <a href="https://bugs.webkit.org/show_bug.cgi?id=8519">Bug 8519</a>.</p>
+<div id="console"></div>
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+function log(msg) {
+    document.getElementById("console").innerHTML += msg + "<br>";
+}
+
+window.onerror = function(msg, url, line)
+{
+    url = url ? url.match( /[^\/]+\/?$/ )[0] : url;
+    log("Main frame window.onerror: " + msg + " at " + url + ":" + line);
+    return false;
+}
+
+throwException();
+
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/events/window-onerror12-expected.txt b/LayoutTests/fast/events/window-onerror12-expected.txt
new file mode 100644
index 0000000..e16fe97
--- /dev/null
+++ b/LayoutTests/fast/events/window-onerror12-expected.txt
@@ -0,0 +1,8 @@
+Test that window.onerror is called on window object for events created using document.createEvent("error"). Bug 8519.
+
+Main frame window.onerror: 
+msg: [object Event]
+url: undefined
+line: undefined
+DONE.
+
diff --git a/LayoutTests/fast/events/window-onerror12.html b/LayoutTests/fast/events/window-onerror12.html
new file mode 100644
index 0000000..dede975
--- /dev/null
+++ b/LayoutTests/fast/events/window-onerror12.html
@@ -0,0 +1,33 @@
+<html>
+<head>
+<script src="resources/window-onerror.js">
+</script>
+</head>
+<body>
+<p>Test that window.onerror is called on window object for events created using document.createEvent("error"). <a href="https://bugs.webkit.org/show_bug.cgi?id=8519">Bug 8519</a>.</p>
+<div id="console"></div>
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+function log(msg) {
+    document.getElementById("console").innerHTML += msg + "<br>";
+}
+
+window.onerror = function(msg, url, line)
+{
+    log("Main frame window.onerror: ");
+    log("msg: " + msg);
+    log("url: " + url);
+    log("line: " + line);
+    return false;
+}
+
+var evt = document.createEvent("Event");
+evt.initEvent("error", true, true);
+window.dispatchEvent(evt);
+log("DONE.");
+
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/events/window-onerror2-expected.txt b/LayoutTests/fast/events/window-onerror2-expected.txt
new file mode 100644
index 0000000..93a2d3f
--- /dev/null
+++ b/LayoutTests/fast/events/window-onerror2-expected.txt
@@ -0,0 +1,6 @@
+Test that uncaught exceptions will be reported to the window.onerror handler. Bug 8519.
+
+Main frame window.onerror: Error: Inline script exception at window-onerror2.html:35
+Main frame window.onerror: Exception in onload at undefined:0
+Main frame window.onerror: Error: Exception in setTimeout at window-onerror2.html:29
+
diff --git a/LayoutTests/fast/events/window-onerror2.html b/LayoutTests/fast/events/window-onerror2.html
new file mode 100644
index 0000000..db9fb75
--- /dev/null
+++ b/LayoutTests/fast/events/window-onerror2.html
@@ -0,0 +1,41 @@
+<html>
+<body onload="throw 'Exception in onload';">
+<p>Test that uncaught exceptions will be reported to the window.onerror handler. <a href="https://bugs.webkit.org/show_bug.cgi?id=8519">Bug 8519</a>.</p>
+<div id="result"></div>
+<script>
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    layoutTestController.waitUntilDone();
+}
+
+function log(msg) {
+    document.getElementById("result").innerHTML += msg + "<br>";
+}
+
+var unhandledErrorCount = 0;
+window.onerror = function(msg, url, line)
+{
+    url = url ? url.match( /[^\/]+\/?$/ )[0] : url;
+    log("Main frame window.onerror: " + msg + " at " + url + ":" + line);
+    
+    if (++unhandledErrorCount === 3 && window.layoutTestController)
+        layoutTestController.notifyDone();
+
+    return false;
+}
+
+function delayedThrowException()
+{
+    throw new Error("Exception in setTimeout");
+}
+setTimeout(delayedThrowException, 0);
+
+function throwException()
+{
+    throw new Error("Inline script exception");
+}
+throwException();
+
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/events/window-onerror3-expected.txt b/LayoutTests/fast/events/window-onerror3-expected.txt
new file mode 100644
index 0000000..7025dbb
--- /dev/null
+++ b/LayoutTests/fast/events/window-onerror3-expected.txt
@@ -0,0 +1,4 @@
+You should see a message if window.onerror is working properly for this test.Bug 8519.
+
+Error caught successfully: ReferenceError: Can't find variable: unknownObject File: window-onerror3.html Line: 16
+
diff --git a/LayoutTests/fast/events/window-onerror3.html b/LayoutTests/fast/events/window-onerror3.html
new file mode 100644
index 0000000..ee2893f
--- /dev/null
+++ b/LayoutTests/fast/events/window-onerror3.html
@@ -0,0 +1,23 @@
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+function log(msg) {
+    document.getElementById("console").innerHTML += msg + "<br>";
+}
+
+function test1()
+{
+    window.onerror = function (error, url, line) {
+        url = url ? url.match( /[^\/]+\/?$/ )[0] : url;
+        log("Error caught successfully: " + error + "\nFile: " + url + "\nLine: " + line)
+        return false;
+    };
+    unknownObject.unknownProperty++;
+}
+</script>
+<body onload="test1();">
+<p>You should see a message if window.onerror is working properly for this test.<a href="https://bugs.webkit.org/show_bug.cgi?id=8519">Bug 8519</a>.</p>
+<hr>
+<div id='console'></div>
+</body>
diff --git a/LayoutTests/fast/events/window-onerror4-expected.txt b/LayoutTests/fast/events/window-onerror4-expected.txt
new file mode 100644
index 0000000..26af8a1
--- /dev/null
+++ b/LayoutTests/fast/events/window-onerror4-expected.txt
@@ -0,0 +1,4 @@
+You should see a log record if window.onerror is working properly for this test.Bug 8519.
+
+Error caught successfully: ReferenceError: Left side of assignment is not a reference. File: undefined Line: 1
+
diff --git a/LayoutTests/fast/events/window-onerror4.html b/LayoutTests/fast/events/window-onerror4.html
new file mode 100644
index 0000000..c51887d
--- /dev/null
+++ b/LayoutTests/fast/events/window-onerror4.html
@@ -0,0 +1,23 @@
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+function log(msg) {
+    document.getElementById("console").innerHTML += msg + "<br>";
+}
+
+function test1()
+{
+    window.onerror = function (error, url, line) {
+        url = url ? url.match( /[^\/]+\/?$/ )[0] : url;
+        log("Error caught successfully: " + error + "\nFile: " + url + "\nLine: " + line)
+        return false;
+    };
+    eval("1=2");
+}
+</script>
+<body onload="test1();">
+<p>You should see a log record if window.onerror is working properly for this test.<a href="https://bugs.webkit.org/show_bug.cgi?id=8519">Bug 8519</a>.</p>
+<hr>
+<div id='console'></div>
+</body>
diff --git a/LayoutTests/fast/events/window-onerror5-expected.txt b/LayoutTests/fast/events/window-onerror5-expected.txt
new file mode 100644
index 0000000..3ec7f5e
--- /dev/null
+++ b/LayoutTests/fast/events/window-onerror5-expected.txt
@@ -0,0 +1,4 @@
+Test that window.onerror is invoked for syntax error in eval. You should see a log record if window.onerror is working properly for this test.Bug 8519.
+
+Error caught successfully: SyntaxError: Parse error File: undefined Line: 1
+
diff --git a/LayoutTests/fast/events/window-onerror5.html b/LayoutTests/fast/events/window-onerror5.html
new file mode 100644
index 0000000..932d438
--- /dev/null
+++ b/LayoutTests/fast/events/window-onerror5.html
@@ -0,0 +1,23 @@
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+function log(msg) {
+    document.getElementById("console").innerHTML += msg + "<br>";
+}
+
+function test1()
+{
+    window.onerror = function (error, url, line) {
+        url = url ? url.match( /[^\/]+\/?$/ )[0] : url;
+        log("Error caught successfully: " + error + "\nFile: " + url + "\nLine: " + line)
+        return false;
+    };
+    eval("a(");
+}
+</script>
+<body onload="test1();">
+<p>Test that window.onerror is invoked for syntax error in eval. You should see a log record if window.onerror is working properly for this test.<a href="https://bugs.webkit.org/show_bug.cgi?id=8519">Bug 8519</a>.</p>
+<hr>
+<div id='console'></div>
+</body>
diff --git a/LayoutTests/fast/events/window-onerror6-expected.txt b/LayoutTests/fast/events/window-onerror6-expected.txt
new file mode 100644
index 0000000..e7c27bb
--- /dev/null
+++ b/LayoutTests/fast/events/window-onerror6-expected.txt
@@ -0,0 +1,4 @@
+Test that syntax error will be reported to the window.onerror handler. Bug 8519.
+
+Main frame window.onerror: SyntaxError: Parse error at window-onerror6.html:22
+
diff --git a/LayoutTests/fast/events/window-onerror6.html b/LayoutTests/fast/events/window-onerror6.html
new file mode 100644
index 0000000..1978436
--- /dev/null
+++ b/LayoutTests/fast/events/window-onerror6.html
@@ -0,0 +1,26 @@
+<html>
+<body>
+<p>Test that syntax error will be reported to the window.onerror handler. <a href="https://bugs.webkit.org/show_bug.cgi?id=8519">Bug 8519</a>.</p>
+<div id="console"></div>
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+function log(msg) {
+    document.getElementById("console").innerHTML += msg + "<br>";
+}
+
+window.onerror = function(msg, url, line)
+{
+    url = url ? url.match( /[^\/]+\/?$/ )[0] : url;
+    log("Main frame window.onerror: " + msg + " at " + url + ":" + line);
+    return false;
+}
+</script>
+<script>
+
+a) // syntax error
+
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/events/window-onerror7-expected.txt b/LayoutTests/fast/events/window-onerror7-expected.txt
new file mode 100644
index 0000000..5d22e7e
--- /dev/null
+++ b/LayoutTests/fast/events/window-onerror7-expected.txt
@@ -0,0 +1,6 @@
+CONSOLE MESSAGE: line 20: Error: Original error
+CONSOLE MESSAGE: line 17: Error: Nested error
+Test that exception in window.onerror won't lead to recursive window.onerror call. Bug 8519.
+
+Main frame window.onerror: Error: Original error at window-onerror7.html:20
+
diff --git a/LayoutTests/fast/events/window-onerror7.html b/LayoutTests/fast/events/window-onerror7.html
new file mode 100644
index 0000000..f665686
--- /dev/null
+++ b/LayoutTests/fast/events/window-onerror7.html
@@ -0,0 +1,24 @@
+<html>
+<body>
+<p>Test that exception in window.onerror won't lead to recursive window.onerror call. <a href="https://bugs.webkit.org/show_bug.cgi?id=8519">Bug 8519</a>.</p>
+<div id="console"></div>
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+function log(msg) {
+    document.getElementById("console").innerHTML += msg + "<br>";
+}
+
+window.onerror = function(msg, url, line)
+{
+    url = url ? url.match( /[^\/]+\/?$/ )[0] : url;
+    log("Main frame window.onerror: " + msg + " at " + url + ":" + line);
+    throw new Error("Nested error");
+}
+
+throw new Error("Original error");
+
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/events/window-onerror8-expected.txt b/LayoutTests/fast/events/window-onerror8-expected.txt
new file mode 100644
index 0000000..efc6308
--- /dev/null
+++ b/LayoutTests/fast/events/window-onerror8-expected.txt
@@ -0,0 +1,5 @@
+Test that window.onerror is called on window object. Bug 8519.
+
+Main frame window.onerror: 2010 at undefined:0
+PASSED: this === window
+
diff --git a/LayoutTests/fast/events/window-onerror8.html b/LayoutTests/fast/events/window-onerror8.html
new file mode 100644
index 0000000..bade538
--- /dev/null
+++ b/LayoutTests/fast/events/window-onerror8.html
@@ -0,0 +1,28 @@
+<html>
+<body>
+<p>Test that window.onerror is called on window object. <a href="https://bugs.webkit.org/show_bug.cgi?id=8519">Bug 8519</a>.</p>
+<div id="console"></div>
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+function log(msg) {
+    document.getElementById("console").innerHTML += msg + "<br>";
+}
+
+window.onerror = function(msg, url, line)
+{
+    url = url ? url.match( /[^\/]+\/?$/ )[0] : url;
+    log("Main frame window.onerror: " + msg + " at " + url + ":" + line);
+    if (this === window) 
+        log("PASSED: this === window");
+    else
+        log("FAILED: this === window");
+    return false;
+}
+
+throw 2010;
+
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/events/window-onerror9-expected.txt b/LayoutTests/fast/events/window-onerror9-expected.txt
new file mode 100644
index 0000000..94316d3
--- /dev/null
+++ b/LayoutTests/fast/events/window-onerror9-expected.txt
@@ -0,0 +1,8 @@
+Test that when window.onerror handler is called, window.event is the corresponding ErrorEvent object. Bug 8519.
+
+Main frame window.onerror: Error: 2010 at window-onerror9.html:31
+window.event.type = error
+window.event.message = Error: 2010
+window.event.filename = window-onerror9.html
+window.event.lineno = 31
+
diff --git a/LayoutTests/fast/events/window-onerror9.html b/LayoutTests/fast/events/window-onerror9.html
new file mode 100644
index 0000000..1086ace
--- /dev/null
+++ b/LayoutTests/fast/events/window-onerror9.html
@@ -0,0 +1,35 @@
+<html>
+<body>
+<p>Test that when window.onerror handler is called, window.event is the corresponding ErrorEvent object. <a href="https://bugs.webkit.org/show_bug.cgi?id=8519">Bug 8519</a>.</p>
+<div id="console"></div>
+<script>
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    layoutTestController.waitUntilDone();
+}
+
+function log(msg) {
+    document.getElementById("console").innerHTML += msg + "<br>";
+}
+
+function lastPathComponent(url) {
+    return url ? url.match( /[^\/]+\/?$/ )[0] : url;
+}
+
+window.onerror = function(msg, url, line)
+{
+    log("Main frame window.onerror: " + msg + " at " + lastPathComponent(url) + ":" + line);
+    log("window.event.type = " + window.event.type);
+    log("window.event.message = " + window.event.message);
+    log("window.event.filename = " + lastPathComponent(window.event.filename));
+    log("window.event.lineno = " + window.event.lineno);
+    if (window.layoutTestController)
+        layoutTestController.notifyDone();
+    return false;
+}
+
+throw new Error(2010);
+
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/workers/worker-script-error-expected.txt b/LayoutTests/fast/workers/worker-script-error-expected.txt
index 10ab049..4041640 100644
--- a/LayoutTests/fast/workers/worker-script-error-expected.txt
+++ b/LayoutTests/fast/workers/worker-script-error-expected.txt
@@ -4,8 +4,8 @@ Test Worker script error handling functionality. Should print a series of PASS m
 PASS: onerror invoked for a script that has invalid syntax.
 PASS: onerror invoked for a script that has script error 'ReferenceError: Can't find variable: foo' at line 1.
 PASS: event listener invoked for a script that has script error 'ReferenceError: Can't find variable: foo' at line 1.
-PASS: onerror invoked for a script that has script error 'ReferenceError: Can't find variable: bar' at line 3.
 PASS: onerror invoked for a script that has script error 'ReferenceError: Can't find variable: foo' at line 7.
+PASS: onerror invoked for a script that has script error 'ReferenceError: Can't find variable: bar' at line 3.
 PASS: onerror invoked for a script that has script error 'ReferenceError: Can't find variable: foo' at line 7.
 PASS: onerror invoked for a script that has script error 'ReferenceError: Can't find variable: foo' at line 7.
 PASS: message received from WorkerGlobalScope.onerror: onerror invoked for a script that has script error 'ReferenceError: Can't find variable: foo' at line 7.
diff --git a/LayoutTests/http/tests/security/resources/onerror-iframe.html b/LayoutTests/http/tests/security/resources/onerror-iframe.html
new file mode 100644
index 0000000..312fd12
--- /dev/null
+++ b/LayoutTests/http/tests/security/resources/onerror-iframe.html
@@ -0,0 +1,11 @@
+<script>
+function handleLoad()
+{
+    window.parent.postMessage("IFrameLoaded", "*");
+}
+
+throw "IframeException";
+
+</script>
+<body onload="handleLoad()">
+</body>
diff --git a/LayoutTests/http/tests/security/window-onerror-exception-in-iframe-expected.txt b/LayoutTests/http/tests/security/window-onerror-exception-in-iframe-expected.txt
new file mode 100644
index 0000000..8b17d92
--- /dev/null
+++ b/LayoutTests/http/tests/security/window-onerror-exception-in-iframe-expected.txt
@@ -0,0 +1,6 @@
+CONSOLE MESSAGE: line 0: IframeException
+Test that exceptions in iframe are not reported to the main frame window.onerror handler. window.onerror should print exactly one line.
+
+Main frame window.onerror: MainFrameException at undefined:0
+DONE
+
diff --git a/LayoutTests/http/tests/security/window-onerror-exception-in-iframe.html b/LayoutTests/http/tests/security/window-onerror-exception-in-iframe.html
new file mode 100644
index 0000000..0904e39
--- /dev/null
+++ b/LayoutTests/http/tests/security/window-onerror-exception-in-iframe.html
@@ -0,0 +1,39 @@
+<html>
+<body>
+<p>Test that exceptions in iframe are not reported to the main frame window.onerror handler.
+window.onerror should print exactly one line.</p>
+<div id="result"></div>
+<script>
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    layoutTestController.waitUntilDone();
+}
+
+function log(msg) {
+    document.getElementById("result").innerHTML += msg + "<br>";
+}
+
+window.onerror = function(msg, url, line)
+{
+    url = url ? url.match( /[^\/]+\/?$/ )[0] : url;
+    log("Main frame window.onerror: " + msg + " at " + url + ":" + line);
+    return false;
+}
+
+function receiveMessage(event) {
+    if (event.data === "IFrameLoaded") {
+        log("DONE");
+        if (window.layoutTestController)
+            layoutTestController.notifyDone();
+    } else
+        log("FAIL " + event.data);
+}
+
+window.addEventListener("message", receiveMessage, false);
+
+throw "MainFrameException";
+
+</script>
+<iframe src="http://localhost:8000/security/resources/onerror-iframe.html"/>
+</body>
+</html>
diff --git a/LayoutTests/platform/chromium-win/fast/workers/worker-script-error-expected.txt b/LayoutTests/platform/chromium-win/fast/workers/worker-script-error-expected.txt
index fdf660b..ef0a391 100644
--- a/LayoutTests/platform/chromium-win/fast/workers/worker-script-error-expected.txt
+++ b/LayoutTests/platform/chromium-win/fast/workers/worker-script-error-expected.txt
@@ -3,8 +3,8 @@ Test Worker script error handling functionality. Should print a series of PASS m
 PASS: onerror invoked for a script that has invalid syntax.
 PASS: onerror invoked for a script that has script error 'Uncaught ReferenceError: foo is not defined' at line 1.
 PASS: event listener invoked for a script that has script error 'Uncaught ReferenceError: foo is not defined' at line 1.
-PASS: onerror invoked for a script that has script error 'Uncaught ReferenceError: bar is not defined' at line 3.
 PASS: onerror invoked for a script that has script error 'Uncaught ReferenceError: foo is not defined' at line 7.
+PASS: onerror invoked for a script that has script error 'Uncaught ReferenceError: bar is not defined' at line 3.
 PASS: onerror invoked for a script that has script error 'Uncaught ReferenceError: foo is not defined' at line 7.
 PASS: onerror invoked for a script that has script error 'Uncaught ReferenceError: foo is not defined' at line 7.
 PASS: message received from WorkerGlobalScope.onerror: onerror invoked for a script that has script error 'Uncaught ReferenceError: foo is not defined' at line 7.
diff --git a/LayoutTests/platform/chromium/fast/events/window-onerror1-expected.txt b/LayoutTests/platform/chromium/fast/events/window-onerror1-expected.txt
new file mode 100644
index 0000000..65b624b
--- /dev/null
+++ b/LayoutTests/platform/chromium/fast/events/window-onerror1-expected.txt
@@ -0,0 +1,3 @@
+This page tests setting onerror handlers through the DOM. If it passes, you will see "PASS" messages below.Bug 8519.
+
+PASS: caught global error: Uncaught ReferenceError: hahaha_good_luck_finding_me is not defined at window-onerror1.html:25
diff --git a/LayoutTests/platform/chromium/fast/events/window-onerror10-expected.txt b/LayoutTests/platform/chromium/fast/events/window-onerror10-expected.txt
new file mode 100644
index 0000000..b3d2d39
--- /dev/null
+++ b/LayoutTests/platform/chromium/fast/events/window-onerror10-expected.txt
@@ -0,0 +1,11 @@
+Test that "error" event listener added with window.addEventListener is invoked for uncaucht exceptions. Bug 8519.
+
+event passed to the listener is the same as window.event: true
+Event details:
+type: error
+phase: 2
+currentTarget is the global object: true
+message: Uncaught Error: My fault.
+filename: window-onerror10.html
+lineno: 29
+
diff --git a/LayoutTests/platform/chromium/fast/events/window-onerror11-expected.txt b/LayoutTests/platform/chromium/fast/events/window-onerror11-expected.txt
new file mode 100644
index 0000000..92e3cf5
--- /dev/null
+++ b/LayoutTests/platform/chromium/fast/events/window-onerror11-expected.txt
@@ -0,0 +1,4 @@
+Test that window.onerror is called on window object. Bug 8519.
+
+Main frame window.onerror: Uncaught Error: An exception at window-onerror.js:2
+
diff --git a/LayoutTests/platform/chromium/fast/events/window-onerror2-expected.txt b/LayoutTests/platform/chromium/fast/events/window-onerror2-expected.txt
new file mode 100644
index 0000000..f7b1621
--- /dev/null
+++ b/LayoutTests/platform/chromium/fast/events/window-onerror2-expected.txt
@@ -0,0 +1,6 @@
+Test that uncaught exceptions will be reported to the window.onerror handler. Bug 8519.
+
+Main frame window.onerror: Uncaught Error: Inline script exception at window-onerror2.html:35
+Main frame window.onerror: Uncaught Exception in onload at window-onerror2.html:2
+Main frame window.onerror: Uncaught Error: Exception in setTimeout at window-onerror2.html:29
+
diff --git a/LayoutTests/platform/chromium/fast/events/window-onerror3-expected.txt b/LayoutTests/platform/chromium/fast/events/window-onerror3-expected.txt
new file mode 100644
index 0000000..a1b8bd5
--- /dev/null
+++ b/LayoutTests/platform/chromium/fast/events/window-onerror3-expected.txt
@@ -0,0 +1,4 @@
+You should see a message if window.onerror is working properly for this test.Bug 8519.
+
+Error caught successfully: Uncaught ReferenceError: unknownObject is not defined File: window-onerror3.html Line: 16
+
diff --git a/LayoutTests/platform/chromium/fast/events/window-onerror4-expected.txt b/LayoutTests/platform/chromium/fast/events/window-onerror4-expected.txt
new file mode 100644
index 0000000..50f09e0
--- /dev/null
+++ b/LayoutTests/platform/chromium/fast/events/window-onerror4-expected.txt
@@ -0,0 +1,4 @@
+You should see a log record if window.onerror is working properly for this test.Bug 8519.
+
+Error caught successfully: Uncaught ReferenceError: Invalid left-hand side in assignment File: window-onerror4.html Line: 1
+
diff --git a/LayoutTests/platform/chromium/fast/events/window-onerror5-expected.txt b/LayoutTests/platform/chromium/fast/events/window-onerror5-expected.txt
new file mode 100644
index 0000000..e45369e
--- /dev/null
+++ b/LayoutTests/platform/chromium/fast/events/window-onerror5-expected.txt
@@ -0,0 +1,4 @@
+Test that window.onerror is invoked for syntax error in eval. You should see a log record if window.onerror is working properly for this test.Bug 8519.
+
+Error caught successfully: Uncaught SyntaxError: Unexpected end of input File: window-onerror5.html Line: 1
+
diff --git a/LayoutTests/platform/chromium/fast/events/window-onerror6-expected.txt b/LayoutTests/platform/chromium/fast/events/window-onerror6-expected.txt
new file mode 100644
index 0000000..18ed81a
--- /dev/null
+++ b/LayoutTests/platform/chromium/fast/events/window-onerror6-expected.txt
@@ -0,0 +1,4 @@
+Test that syntax error will be reported to the window.onerror handler. Bug 8519.
+
+Main frame window.onerror: Uncaught SyntaxError: Unexpected token ) at window-onerror6.html:22
+
diff --git a/LayoutTests/platform/chromium/fast/events/window-onerror7-expected.txt b/LayoutTests/platform/chromium/fast/events/window-onerror7-expected.txt
new file mode 100644
index 0000000..23d0407
--- /dev/null
+++ b/LayoutTests/platform/chromium/fast/events/window-onerror7-expected.txt
@@ -0,0 +1,6 @@
+CONSOLE MESSAGE: line 20: Uncaught Error: Original error
+CONSOLE MESSAGE: line 17: Uncaught Error: Nested error
+Test that exception in window.onerror won't lead to recursive window.onerror call. Bug 8519.
+
+Main frame window.onerror: Uncaught Error: Original error at window-onerror7.html:20
+
diff --git a/LayoutTests/platform/chromium/fast/events/window-onerror8-expected.txt b/LayoutTests/platform/chromium/fast/events/window-onerror8-expected.txt
new file mode 100644
index 0000000..13f2b32
--- /dev/null
+++ b/LayoutTests/platform/chromium/fast/events/window-onerror8-expected.txt
@@ -0,0 +1,5 @@
+Test that window.onerror is called on window object. Bug 8519.
+
+Main frame window.onerror: Uncaught 2010 at window-onerror8.html:24
+PASSED: this === window
+
diff --git a/LayoutTests/platform/chromium/fast/events/window-onerror9-expected.txt b/LayoutTests/platform/chromium/fast/events/window-onerror9-expected.txt
new file mode 100644
index 0000000..1677e50
--- /dev/null
+++ b/LayoutTests/platform/chromium/fast/events/window-onerror9-expected.txt
@@ -0,0 +1,8 @@
+Test that when window.onerror handler is called, window.event is the corresponding ErrorEvent object. Bug 8519.
+
+Main frame window.onerror: Uncaught Error: 2010 at window-onerror9.html:31
+window.event.type = error
+window.event.message = Uncaught Error: 2010
+window.event.filename = window-onerror9.html
+window.event.lineno = 31
+
diff --git a/LayoutTests/platform/chromium/http/tests/security/window-onerror-exception-in-iframe-expected.txt b/LayoutTests/platform/chromium/http/tests/security/window-onerror-exception-in-iframe-expected.txt
new file mode 100644
index 0000000..9e9c2ea
--- /dev/null
+++ b/LayoutTests/platform/chromium/http/tests/security/window-onerror-exception-in-iframe-expected.txt
@@ -0,0 +1,6 @@
+CONSOLE MESSAGE: line 7: Uncaught IframeException
+Test that exceptions in iframe are not reported to the main frame window.onerror handler. window.onerror should print exactly one line.
+
+Main frame window.onerror: Uncaught MainFrameException at window-onerror-exception-in-iframe.html:34
+DONE
+
diff --git a/LayoutTests/platform/chromium/userscripts/window-onerror-for-isolated-world-1-expected.txt b/LayoutTests/platform/chromium/userscripts/window-onerror-for-isolated-world-1-expected.txt
new file mode 100644
index 0000000..2a3d068
--- /dev/null
+++ b/LayoutTests/platform/chromium/userscripts/window-onerror-for-isolated-world-1-expected.txt
@@ -0,0 +1,14 @@
+Test that window.onerror and "error" event listeners from main world are invoked for uncaught exceptions in user scripts running in isolate worlds as well as for exceptions in the main world.Bug 8519.
+
+Main world window.onerror: Uncaught Error: Error in main world inline script. at window-onerror-for-isolated-world-1.html:54
+Main world error event listener: Uncaught Error: Error in main world inline script. at window-onerror-for-isolated-world-1.html:54
+Main world window.onerror: Uncaught Error: Error in user script inline script. at :12
+Main world error event listener: Uncaught Error: Error in user script inline script. at :12
+Main world window.onerror: Uncaught Error: Error in main world load handler. at window-onerror-for-isolated-world-1.html:46
+Main world error event listener: Uncaught Error: Error in main world load handler. at window-onerror-for-isolated-world-1.html:46
+Main world window.onerror: Uncaught Error: Error in user script load handler. at :4
+Main world error event listener: Uncaught Error: Error in user script load handler. at :4
+Main world window.onerror: Uncaught Error: Error in main world setTimeout callback. at window-onerror-for-isolated-world-1.html:51
+Main world error event listener: Uncaught Error: Error in main world setTimeout callback. at window-onerror-for-isolated-world-1.html:51
+Main world window.onerror: Uncaught Error: Error in user script setTimeout callback. at :9
+Main world error event listener: Uncaught Error: Error in user script setTimeout callback. at :9
diff --git a/LayoutTests/platform/chromium/userscripts/window-onerror-for-isolated-world-2-expected.txt b/LayoutTests/platform/chromium/userscripts/window-onerror-for-isolated-world-2-expected.txt
new file mode 100644
index 0000000..93994db
--- /dev/null
+++ b/LayoutTests/platform/chromium/userscripts/window-onerror-for-isolated-world-2-expected.txt
@@ -0,0 +1,13 @@
+CONSOLE MESSAGE: line 30: Uncaught Error: Error in main world inline script.
+Test that window.onerror and "error" event listeners from isolated world are invoked for uncaught exceptions in user scripts running in isolate worlds as well as for exceptions in the main world.Bug 8519.
+
+user script window.onerror: Uncaught Error: Error in user script inline script. at :33
+user script error event listener: Uncaught Error: Error in user script inline script. at :33
+user script window.onerror: Uncaught Error: Error in main world load handler. at window-onerror-for-isolated-world-2.html:23
+user script error event listener: Uncaught Error: Error in main world load handler. at window-onerror-for-isolated-world-2.html:23
+user script window.onerror: Uncaught Error: Error in user script load handler. at :26
+user script error event listener: Uncaught Error: Error in user script load handler. at :26
+user script window.onerror: Uncaught Error: Error in main world setTimeout callback. at window-onerror-for-isolated-world-2.html:27
+user script error event listener: Uncaught Error: Error in main world setTimeout callback. at window-onerror-for-isolated-world-2.html:27
+user script window.onerror: Uncaught Error: Error in user script setTimeout callback. at :30
+user script error event listener: Uncaught Error: Error in user script setTimeout callback. at :30
diff --git a/LayoutTests/platform/gtk/Skipped b/LayoutTests/platform/gtk/Skipped
index 68be9d6..5253538 100644
--- a/LayoutTests/platform/gtk/Skipped
+++ b/LayoutTests/platform/gtk/Skipped
@@ -4711,6 +4711,8 @@ userscripts/user-script-plugin-document.html
 userscripts/user-script-top-frame-only.html
 userscripts/user-script-video-document.html
 userscripts/user-style-top-frame-only.html
+userscripts/window-onerror-for-isolated-world-1.html
+userscripts/window-onerror-for-isolated-world-2.html
 
 # XHR sends sometimes yield null bytes sent instead of 0.
 http/tests/xmlhttprequest/workers/shared-worker-methods.html
diff --git a/LayoutTests/platform/gtk/fast/events/window-onerror2-expected.txt b/LayoutTests/platform/gtk/fast/events/window-onerror2-expected.txt
new file mode 100755
index 0000000..fe78d16
--- /dev/null
+++ b/LayoutTests/platform/gtk/fast/events/window-onerror2-expected.txt
@@ -0,0 +1,6 @@
+Test that uncaught exceptions will be reported to the window.onerror handler. Bug 8519.
+
+Main frame window.onerror: Error: Inline script exception at window-onerror2.html:35
+Main frame window.onerror: Error: Exception in setTimeout at window-onerror2.html:29
+Main frame window.onerror: Exception in onload at undefined:0
+
diff --git a/LayoutTests/userscripts/window-onerror-for-isolated-world-1-expected.txt b/LayoutTests/userscripts/window-onerror-for-isolated-world-1-expected.txt
new file mode 100644
index 0000000..6895c41
--- /dev/null
+++ b/LayoutTests/userscripts/window-onerror-for-isolated-world-1-expected.txt
@@ -0,0 +1,14 @@
+Test that window.onerror and "error" event listeners from main world are invoked for uncaught exceptions in user scripts running in isolate worlds as well as for exceptions in the main world.Bug 8519.
+
+Main world window.onerror: Error: Error in main world inline script. at window-onerror-for-isolated-world-1.html:54
+Main world error event listener: Error: Error in main world inline script. at window-onerror-for-isolated-world-1.html:54
+Main world window.onerror: Error: Error in user script inline script. at undefined:11
+Main world error event listener: Error: Error in user script inline script. at undefined:11
+Main world window.onerror: Error: Error in main world load handler. at window-onerror-for-isolated-world-1.html:46
+Main world error event listener: Error: Error in main world load handler. at window-onerror-for-isolated-world-1.html:46
+Main world window.onerror: Error: Error in user script load handler. at undefined:3
+Main world error event listener: Error: Error in user script load handler. at undefined:3
+Main world window.onerror: Error: Error in main world setTimeout callback. at window-onerror-for-isolated-world-1.html:51
+Main world error event listener: Error: Error in main world setTimeout callback. at window-onerror-for-isolated-world-1.html:51
+Main world window.onerror: Error: Error in user script setTimeout callback. at undefined:8
+Main world error event listener: Error: Error in user script setTimeout callback. at undefined:8
diff --git a/LayoutTests/userscripts/window-onerror-for-isolated-world-1.html b/LayoutTests/userscripts/window-onerror-for-isolated-world-1.html
new file mode 100644
index 0000000..3c6bac2
--- /dev/null
+++ b/LayoutTests/userscripts/window-onerror-for-isolated-world-1.html
@@ -0,0 +1,67 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+</head>
+<body>
+<p>Test that window.onerror and "error" event listeners from main world are
+invoked for uncaught exceptions in user scripts running in isolate worlds as
+well as for exceptions in the main world.<a href="https://bugs.webkit.org/show_bug.cgi?id=8519">Bug 8519.</a>
+</p>
+<div id="console"></div>
+<script>
+
+var expectedRecordCount = 12;
+var recordCount = 0;
+document.getElementById("console").addEventListener("DOMNodeInserted", function(e) {
+    recordCount++;
+    if (recordCount === expectedRecordCount && window.layoutTestController)
+        layoutTestController.notifyDone();
+}, false);
+
+function log(msg) {
+    var record = document.createElement("div");
+    record.innerHTML = msg;
+    document.getElementById("console").appendChild(record);
+}
+
+function lastUrlComponent(url) {
+    return url ? url.match( /[^\/]+\/?$/ )[0] : url;
+}
+
+window.onerror = function(msg, url, line)
+{
+    log("Main world window.onerror: " + msg + " at " + lastUrlComponent(url) + ":" + line);
+    return false;
+}
+
+window.addEventListener("error", function(e)
+{
+    var url = lastUrlComponent(e.filename);
+    log("Main world error event listener: " + e.message + " at " + url + ":" + e.lineno);
+}, false);
+
+var exceptions = function(isolatedWorld)
+{
+    window.addEventListener("load", function(e) {
+        throw new Error("Error in " + isolatedWorld + " load handler.");
+    }, false);
+
+
+    setTimeout(function() {
+        throw new Error("Error in " + isolatedWorld + " setTimeout callback.");
+    }, 0);
+
+    throw new Error("Error in "+ isolatedWorld + " inline script.");
+}
+
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    layoutTestController.waitUntilDone();
+    layoutTestController.addUserScript("(" + exceptions + ")('user script')", false, true);
+}
+
+exceptions("main world");
+
+</script>
+</body>
+</html>
diff --git a/LayoutTests/userscripts/window-onerror-for-isolated-world-2-expected.txt b/LayoutTests/userscripts/window-onerror-for-isolated-world-2-expected.txt
new file mode 100644
index 0000000..b909a99
--- /dev/null
+++ b/LayoutTests/userscripts/window-onerror-for-isolated-world-2-expected.txt
@@ -0,0 +1,13 @@
+CONSOLE MESSAGE: line 30: Error: Error in main world inline script.
+Test that window.onerror and "error" event listeners from isolated world are invoked for uncaught exceptions in user scripts running in isolate worlds as well as for exceptions in the main world.Bug 8519.
+
+user script window.onerror: Error: Error in user script inline script. at undefined:31
+user script error event listener: Error: Error in user script inline script. at undefined:31
+user script window.onerror: Error: Error in main world load handler. at window-onerror-for-isolated-world-2.html:23
+user script error event listener: Error: Error in main world load handler. at window-onerror-for-isolated-world-2.html:23
+user script window.onerror: Error: Error in user script load handler. at undefined:24
+user script error event listener: Error: Error in user script load handler. at undefined:24
+user script window.onerror: Error: Error in main world setTimeout callback. at window-onerror-for-isolated-world-2.html:27
+user script error event listener: Error: Error in main world setTimeout callback. at window-onerror-for-isolated-world-2.html:27
+user script window.onerror: Error: Error in user script setTimeout callback. at undefined:28
+user script error event listener: Error: Error in user script setTimeout callback. at undefined:28
diff --git a/LayoutTests/userscripts/window-onerror-for-isolated-world-2.html b/LayoutTests/userscripts/window-onerror-for-isolated-world-2.html
new file mode 100644
index 0000000..a6ec699
--- /dev/null
+++ b/LayoutTests/userscripts/window-onerror-for-isolated-world-2.html
@@ -0,0 +1,67 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+</head>
+<body>
+<p>Test that window.onerror and "error" event listeners from isolated world are
+invoked for uncaught exceptions in user scripts running in isolate worlds as
+well as for exceptions in the main world.<a href="https://bugs.webkit.org/show_bug.cgi?id=8519">Bug 8519.</a>
+</p>
+<div id="console"></div>
+<script>
+
+var expectedRecordCount = 10;
+var recordCount = 0;
+document.getElementById("console").addEventListener("DOMNodeInserted", function(e) {
+    if (++recordCount === expectedRecordCount && window.layoutTestController)
+        layoutTestController.notifyDone();
+}, false);
+
+var throwExceptions = function(isolatedWorld)
+{
+    window.addEventListener("load", function(e) {
+        throw new Error("Error in " + isolatedWorld + " load handler.");
+    }, false);
+
+    setTimeout(function() {
+        throw new Error("Error in " + isolatedWorld + " setTimeout callback.");
+    }, 0);
+    
+    throw new Error("Error in "+ isolatedWorld + " inline script.");
+};
+
+var errorHandlers = function(isolatedWorld)
+{
+    function lastUrlComponent(url) {
+        return url ? url.match( /[^\/]+\/?$/ )[0] : url;
+    }
+
+    function log(msg) {
+        var record = document.createElement("div");
+        record.innerHTML = msg;
+        document.getElementById("console").appendChild(record);
+    }
+
+    window.onerror = function(msg, url, line) {
+        log(isolatedWorld + " window.onerror: " + msg + " at " + lastUrlComponent(url) + ":" + line, "*");
+        return false;
+    }
+
+    window.addEventListener("error", function(e) {
+        var url = lastUrlComponent(e.filename);
+        log(isolatedWorld + " error event listener: " + e.message + " at " + url + ":" + e.lineno, "*");
+        e.preventDefault();
+    }, false);
+};
+
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    layoutTestController.waitUntilDone();
+    layoutTestController.addUserScript("(" + errorHandlers + ")('user script'); (" + throwExceptions + ")('user script')", false, true);
+}
+
+throwExceptions("main world");
+
+</script>
+</body>
+</html>
diff --git a/Source/WebCore/Android.jscbindings.mk b/Source/WebCore/Android.jscbindings.mk
index a7713e3..d40b2ae 100644
--- a/Source/WebCore/Android.jscbindings.mk
+++ b/Source/WebCore/Android.jscbindings.mk
@@ -102,6 +102,7 @@ LOCAL_SRC_FILES += \
 	bindings/js/JSDeviceOrientationEventCustom.cpp \
 	bindings/js/JSDocumentCustom.cpp \
 	bindings/js/JSElementCustom.cpp \
+	bindings/js/JSErrorHandler.cpp \
 	bindings/js/JSEventCustom.cpp \
 	bindings/js/JSEventListener.cpp \
 	bindings/js/JSEventTarget.cpp \
@@ -170,7 +171,6 @@ LOCAL_SRC_FILES += \
 	bindings/js/JSWebKitPointCustom.cpp \
 	bindings/js/JSWorkerContextBase.cpp \
 	bindings/js/JSWorkerContextCustom.cpp \
-	bindings/js/JSWorkerContextErrorHandler.cpp \
 	bindings/js/JSWorkerCustom.cpp \
 	bindings/js/JSXMLHttpRequestCustom.cpp \
 	bindings/js/JSXMLHttpRequestUploadCustom.cpp \
diff --git a/Source/WebCore/CMakeLists.txt b/Source/WebCore/CMakeLists.txt
index 138c847..65d4576 100644
--- a/Source/WebCore/CMakeLists.txt
+++ b/Source/WebCore/CMakeLists.txt
@@ -638,6 +638,7 @@ SET(WebCore_SOURCES
     bindings/js/JSDeviceOrientationEventCustom.cpp
     bindings/js/JSDocumentCustom.cpp
     bindings/js/JSElementCustom.cpp
+    bindings/js/JSErrorHandler.cpp
     bindings/js/JSEventCustom.cpp
     bindings/js/JSEventListener.cpp
     bindings/js/JSEventSourceCustom.cpp
@@ -706,7 +707,6 @@ SET(WebCore_SOURCES
     bindings/js/JSWebSocketCustom.cpp
     bindings/js/JSWorkerContextBase.cpp
     bindings/js/JSWorkerContextCustom.cpp
-    bindings/js/JSWorkerContextErrorHandler.cpp
     bindings/js/JSWorkerCustom.cpp
     bindings/js/JSXMLHttpRequestCustom.cpp
     bindings/js/JSXMLHttpRequestUploadCustom.cpp
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index a182bb2..3a06a2e 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,112 @@
+2010-12-27  Yury Semikhatsky  <yurys at chromium.org>
+
+        Reviewed by Pavel Feldman.
+
+        WebCore doesn't fire window.onerror event when uncaught JavaScript exceptions are thrown
+        https://bugs.webkit.org/show_bug.cgi?id=8519
+
+        Uncaught exceptions are propagated to window.onerror hander if one is present.
+        The handler is expected to be a function accepting three arguments: error message,
+        resource url and line number where the exception occured.
+
+        It was decided to dispatch ErrorEvent to all listeners/handlers no matter if they
+        were created in the same isolated world where the exception occured or not.
+
+        Tests: fast/events/window-onerror1.html
+               fast/events/window-onerror10.html
+               fast/events/window-onerror11.html
+               fast/events/window-onerror12.html
+               fast/events/window-onerror2.html
+               fast/events/window-onerror3.html
+               fast/events/window-onerror4.html
+               fast/events/window-onerror5.html
+               fast/events/window-onerror6.html
+               fast/events/window-onerror7.html
+               fast/events/window-onerror8.html
+               fast/events/window-onerror9.html
+               http/tests/security/window-onerror-exception-in-iframe.html
+               userscripts/window-onerror-for-isolated-world-1.html
+               userscripts/window-onerror-for-isolated-world-2.html
+
+        * Android.jscbindings.mk:
+        * CMakeLists.txt:
+        * GNUmakefile.am:
+        * WebCore.gypi:
+        * WebCore.order:
+        * WebCore.pro:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/JSBindingsAllInOne.cpp:
+        * bindings/js/JSDOMBinding.cpp:
+        (WebCore::reportException):
+        * bindings/js/JSErrorHandler.cpp: Renamed from WebCore/bindings/js/JSWorkerContextErrorHandler.cpp.
+        (WebCore::JSErrorHandler::JSErrorHandler):
+        (WebCore::JSErrorHandler::~JSErrorHandler):
+        (WebCore::JSErrorHandler::handleEvent):
+        * bindings/js/JSErrorHandler.h: Copied from WebCore/bindings/js/JSWorkerContextErrorHandler.h.
+        (WebCore::JSErrorHandler::create):
+        (WebCore::createJSErrorHandler):
+        * bindings/js/JSEventListener.h:
+        * bindings/scripts/CodeGeneratorJS.pm:
+        * bindings/scripts/CodeGeneratorV8.pm:
+        * bindings/v8/V8ConsoleMessage.cpp:
+        (WebCore::V8ConsoleMessage::dispatchNow):
+        (WebCore::V8ConsoleMessage::handler): the method was changed to use generic WebCore exception
+        reporting mechanism which is also used by JSC bindings.
+        * bindings/v8/V8ConsoleMessage.h:
+        * bindings/v8/V8EventListener.h:
+        * bindings/v8/V8WindowErrorHandler.cpp: Renamed from WebCore/bindings/js/JSWorkerContextErrorHandler.h.
+        (WebCore::V8WindowErrorHandler::V8WindowErrorHandler):
+        (WebCore::V8WindowErrorHandler::callListenerFunction):
+        * bindings/v8/V8WindowErrorHandler.h: Copied from WebCore/dom/ErrorEvent.cpp.
+        (WebCore::V8WindowErrorHandler::create):
+        * bindings/v8/WorkerContextExecutionProxy.cpp:
+        (WebCore::v8MessageHandler):
+        * bindings/v8/WorkerScriptController.cpp:
+        (WebCore::WorkerScriptController::evaluate):
+        * dom/Document.cpp:
+        (WebCore::Document::errorEventTarget):
+        (WebCore::Document::logExceptionToConsole):
+        (WebCore::Document::addMessage):
+        * dom/Document.h:
+        * dom/ErrorEvent.cpp:
+        * dom/ErrorEvent.h:
+        * dom/Event.cpp:
+        (WebCore::Event::isErrorEvent):
+        * dom/Event.h:
+        * dom/ScriptExecutionContext.cpp:
+        (WebCore::ScriptExecutionContext::PendingException::PendingException):
+        (WebCore::ScriptExecutionContext::ScriptExecutionContext):
+        (WebCore::ScriptExecutionContext::reportException): this method is not virtual anymore to
+        ensure that error event dispatching algorithm is the same in WorkerContext and in Document.
+        (WebCore::ScriptExecutionContext::dispatchErrorEvent):
+        * dom/ScriptExecutionContext.h:
+        * websockets/WebSocket.cpp:
+        (WebCore::WebSocket::connect):
+        * websockets/WebSocketChannel.cpp:
+        (WebCore::WebSocketChannel::didOpen):
+        (WebCore::WebSocketChannel::didFail):
+        (WebCore::WebSocketChannel::appendToBuffer):
+        * websockets/WebSocketHandshake.cpp:
+        (WebCore::WebSocketHandshake::readServerHandshake):
+        (WebCore::WebSocketHandshake::readStatusLine):
+        (WebCore::WebSocketHandshake::readHTTPHeaders):
+        (WebCore::WebSocketHandshake::checkResponseHeaders):
+        * workers/DefaultSharedWorkerRepository.cpp:
+        (WebCore::postExceptionTask):
+        (WebCore::postConsoleMessageTask):
+        * workers/WorkerContext.cpp:
+        (WebCore::WorkerContext::WorkerContext):
+        (WebCore::WorkerContext::errorEventTarget):
+        (WebCore::WorkerContext::logExceptionToConsole):
+        (WebCore::WorkerContext::addMessage):
+        * workers/WorkerContext.h:
+        * workers/WorkerMessagingProxy.cpp:
+        (WebCore::WorkerExceptionTask::performTask):
+        (WebCore::postConsoleMessageTask):
+        * xml/XMLHttpRequest.cpp:
+        (WebCore::reportUnsafeUsage):
+
 2011-01-19  MORITA Hajime  <morrita at google.com>
 
         Reviewed by Ryosuke Niwa.
diff --git a/Source/WebCore/GNUmakefile.am b/Source/WebCore/GNUmakefile.am
index 2d65532..1330c01 100644
--- a/Source/WebCore/GNUmakefile.am
+++ b/Source/WebCore/GNUmakefile.am
@@ -777,6 +777,8 @@ webcore_sources += \
 	Source/WebCore/bindings/js/JSEventSourceCustom.cpp \
 	Source/WebCore/bindings/js/JSEventTarget.cpp \
 	Source/WebCore/bindings/js/JSEventTarget.h \
+	Source/WebCore/bindings/js/JSErrorHandler.cpp \
+	Source/WebCore/bindings/js/JSErrorHandler.h \
 	Source/WebCore/bindings/js/JSExceptionBase.cpp \
 	Source/WebCore/bindings/js/JSExceptionBase.h \
 	Source/WebCore/bindings/js/JSFileReaderCustom.cpp \
@@ -868,8 +870,6 @@ webcore_sources += \
 	Source/WebCore/bindings/js/JSWorkerContextBase.cpp \
 	Source/WebCore/bindings/js/JSWorkerContextBase.h \
 	Source/WebCore/bindings/js/JSWorkerContextCustom.cpp \
-	Source/WebCore/bindings/js/JSWorkerContextErrorHandler.cpp \
-	Source/WebCore/bindings/js/JSWorkerContextErrorHandler.h \
 	Source/WebCore/bindings/js/JSWorkerCustom.cpp \
 	Source/WebCore/bindings/js/JSXMLHttpRequestCustom.cpp \
 	Source/WebCore/bindings/js/JSXMLHttpRequestUploadCustom.cpp \
diff --git a/Source/WebCore/WebCore.gypi b/Source/WebCore/WebCore.gypi
index 5e2eee1..8492e1e 100644
--- a/Source/WebCore/WebCore.gypi
+++ b/Source/WebCore/WebCore.gypi
@@ -626,6 +626,8 @@
             'bindings/js/JSElementCustom.cpp',
             'bindings/js/JSEntryCustom.cpp',
             'bindings/js/JSEntrySyncCustom.cpp',
+            'bindings/js/JSErrorHandler.cpp',
+            'bindings/js/JSErrorHandler.h',
             'bindings/js/JSEventCustom.cpp',
             'bindings/js/JSEventListener.cpp',
             'bindings/js/JSEventListener.h',
@@ -723,8 +725,6 @@
             'bindings/js/JSWorkerContextBase.cpp',
             'bindings/js/JSWorkerContextBase.h',
             'bindings/js/JSWorkerContextCustom.cpp',
-            'bindings/js/JSWorkerContextErrorHandler.cpp',
-            'bindings/js/JSWorkerContextErrorHandler.h',
             'bindings/js/JSWorkerCustom.cpp',
             'bindings/js/JSXMLHttpRequestCustom.cpp',
             'bindings/js/JSXMLHttpRequestUploadCustom.cpp',
@@ -985,6 +985,8 @@
             'bindings/v8/V8Proxy.h',
             'bindings/v8/V8Utilities.cpp',
             'bindings/v8/V8Utilities.h',
+            'bindings/v8/V8WindowErrorHandler.cpp',
+            'bindings/v8/V8WindowErrorHandler.h',
             'bindings/v8/V8WorkerContextErrorHandler.cpp',
             'bindings/v8/V8WorkerContextErrorHandler.h',
             'bindings/v8/V8WorkerContextEventListener.cpp',
diff --git a/Source/WebCore/WebCore.order b/Source/WebCore/WebCore.order
index e88c444..136a34d 100644
--- a/Source/WebCore/WebCore.order
+++ b/Source/WebCore/WebCore.order
@@ -25208,13 +25208,9 @@ __ZN7WebCore15JSWorkerContext10setTimeoutEPN3JSC9ExecStateERKNS1_7ArgListE
 __ZN7WebCore13WorkerContext10setTimeoutEPNS_15ScheduledActionEi
 __ZN7WebCore17WorkerSharedTimer11setFireTimeEd
 __ZN7WebCore15ScheduledAction7executeEPNS_13WorkerContextE
-__ZN7WebCore27JSWorkerContextErrorHandlerC1EPN3JSC8JSObjectES3_bPNS_15DOMWrapperWorldE
-__ZN7WebCore27JSWorkerContextErrorHandlerC2EPN3JSC8JSObjectES3_bPNS_15DOMWrapperWorldE
 __ZN7WebCore10ErrorEventC1ERKNS_6StringES3_j
 __ZN7WebCore10ErrorEventC2ERKNS_6StringES3_j
-__ZN7WebCore27JSWorkerContextErrorHandler11handleEventEPNS_22ScriptExecutionContextEPNS_5EventE
 __ZN7WebCore10ErrorEventD0Ev
-__ZN7WebCore27JSWorkerContextErrorHandlerD0Ev
 __ZN7WebCore17jsWorkerOnmessageEPN3JSC9ExecStateENS0_7JSValueERKNS0_10IdentifierE
 __ZN7WebCore34jsWorkerPrototypeFunctionTerminateEPN3JSC9ExecStateEPNS0_8JSObjectENS0_7JSValueERKNS0_7ArgListE
 __ZThn8_N7WebCore20WorkerMessagingProxy19workerContextClosedEv
diff --git a/Source/WebCore/WebCore.pro b/Source/WebCore/WebCore.pro
index eef7e00..6758062 100644
--- a/Source/WebCore/WebCore.pro
+++ b/Source/WebCore/WebCore.pro
@@ -407,6 +407,7 @@ v8 {
         bindings/v8/V8NodeFilterCondition.cpp \
         bindings/v8/V8Proxy.cpp \
         bindings/v8/V8Utilities.cpp \
+        bindings/v8/V8WindowErrorHandler.cpp \
         bindings/v8/V8WorkerContextEventListener.cpp \
         bindings/v8/WorkerContextExecutionProxy.cpp \
         bindings/v8/WorkerScriptController.cpp \
@@ -548,6 +549,7 @@ v8 {
         bindings/js/JSDeviceOrientationEventCustom.cpp \
         bindings/js/JSDocumentCustom.cpp \
         bindings/js/JSElementCustom.cpp \
+        bindings/js/JSErrorHandler.cpp \
         bindings/js/JSEventCustom.cpp \
         bindings/js/JSEventListener.cpp \
         bindings/js/JSEventSourceCustom.cpp \
@@ -606,7 +608,6 @@ v8 {
         bindings/js/JSWebKitCSSKeyframesRuleCustom.cpp \
         bindings/js/JSWebKitCSSMatrixCustom.cpp \
         bindings/js/JSWebKitPointCustom.cpp \
-        bindings/js/JSWorkerContextErrorHandler.cpp \
         bindings/js/JSXMLHttpRequestCustom.cpp \
         bindings/js/JSXMLHttpRequestUploadCustom.cpp \
         bindings/js/ScheduledAction.cpp \
@@ -1482,6 +1483,7 @@ v8 {
         bindings/v8/V8NPUtils.h \
         bindings/v8/V8Proxy.h \
         bindings/v8/V8Utilities.h \
+        bindings/v8/V8WindowErrorHandler.h \
         bindings/v8/V8WorkerContextEventListener.h \
         bindings/v8/WorkerContextExecutionProxy.h \
         bindings/v8/WorkerScriptController.h \
@@ -1508,6 +1510,7 @@ v8 {
         bindings/js/JSDOMWindowCustom.h \
         bindings/js/JSDOMWindowShell.h \
         bindings/js/JSDOMWrapper.h \
+        bindings/js/JSErrorHandler.h \
         bindings/js/JSEventListener.h \
         bindings/js/JSEventTarget.h \
         bindings/js/JSHistoryCustom.h \
@@ -1525,7 +1528,6 @@ v8 {
         bindings/js/JSPluginElementFunctions.h \
         bindings/js/JSStorageCustom.h \
         bindings/js/JSWorkerContextBase.h \
-        bindings/js/JSWorkerContextErrorHandler.h \
         bindings/js/JavaScriptCallFrame.h \
         bindings/js/ScheduledAction.h \
         bindings/js/ScriptCachedFrameData.h \
diff --git a/Source/WebCore/WebCore.vcproj/WebCore.vcproj b/Source/WebCore/WebCore.vcproj/WebCore.vcproj
index 3daf5b9..5ce45cd 100755
--- a/Source/WebCore/WebCore.vcproj/WebCore.vcproj
+++ b/Source/WebCore/WebCore.vcproj/WebCore.vcproj
@@ -58201,6 +58201,62 @@
 					>
 				</File>
 				<File
+					RelativePath="..\bindings\js\JSErrorHandler.cpp"
+					>
+					<FileConfiguration
+						Name="Debug|Win32"
+						ExcludedFromBuild="true"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release|Win32"
+						ExcludedFromBuild="true"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug_Cairo_CFLite|Win32"
+						ExcludedFromBuild="true"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release_Cairo_CFLite|Win32"
+						ExcludedFromBuild="true"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug_All|Win32"
+						ExcludedFromBuild="true"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release_LTCG|Win32"
+						ExcludedFromBuild="true"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+						/>
+					</FileConfiguration>
+				</File>
+				<File
+					RelativePath="..\bindings\js\JSErrorHandler.h"
+					>
+				</File>
+				<File
 					RelativePath="..\bindings\js\JSEventCustom.cpp"
 					>
 					<FileConfiguration
@@ -61717,62 +61773,6 @@
 					</FileConfiguration>
 				</File>
 				<File
-					RelativePath="..\bindings\js\JSWorkerContextErrorHandler.cpp"
-					>
-					<FileConfiguration
-						Name="Debug|Win32"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release|Win32"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug_Cairo_CFLite|Win32"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release_Cairo_CFLite|Win32"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug_All|Win32"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release_LTCG|Win32"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-				</File>
-				<File
-					RelativePath="..\bindings\js\JSWorkerContextErrorHandler.h"
-					>
-				</File>
-				<File
 					RelativePath="..\bindings\js\JSWorkerCustom.cpp"
 					>
 					<FileConfiguration
diff --git a/Source/WebCore/WebCore.xcodeproj/project.pbxproj b/Source/WebCore/WebCore.xcodeproj/project.pbxproj
index 689c4d2..3af5015 100644
--- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj
+++ b/Source/WebCore/WebCore.xcodeproj/project.pbxproj
@@ -5619,8 +5619,8 @@
 		F392249D126F11AE00A926D9 /* ScriptCallStackFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = F392249B126F11AE00A926D9 /* ScriptCallStackFactory.h */; };
 		F39BE95B12673BF400E0A674 /* ScriptArguments.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F39BE95912673BF400E0A674 /* ScriptArguments.cpp */; };
 		F39BE95C12673BF400E0A674 /* ScriptArguments.h in Headers */ = {isa = PBXBuildFile; fileRef = F39BE95A12673BF400E0A674 /* ScriptArguments.h */; };
-		F3D461481161D53200CA0D09 /* JSWorkerContextErrorHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F3D461461161D53200CA0D09 /* JSWorkerContextErrorHandler.cpp */; };
-		F3D461491161D53200CA0D09 /* JSWorkerContextErrorHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = F3D461471161D53200CA0D09 /* JSWorkerContextErrorHandler.h */; };
+		F3D461481161D53200CA0D09 /* JSErrorHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F3D461461161D53200CA0D09 /* JSErrorHandler.cpp */; };
+		F3D461491161D53200CA0D09 /* JSErrorHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = F3D461471161D53200CA0D09 /* JSErrorHandler.h */; };
 		F3D4C47812E07663003DA150 /* InspectorBrowserDebuggerAgent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F3D4C47612E07663003DA150 /* InspectorBrowserDebuggerAgent.cpp */; };
 		F3D4C47912E07663003DA150 /* InspectorBrowserDebuggerAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = F3D4C47712E07663003DA150 /* InspectorBrowserDebuggerAgent.h */; };
 		F4EAF4AE10C742B1009100D3 /* OpenTypeSanitizer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F4EAF4AC10C742B1009100D3 /* OpenTypeSanitizer.cpp */; };
@@ -11974,8 +11974,8 @@
 		F392249B126F11AE00A926D9 /* ScriptCallStackFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptCallStackFactory.h; sourceTree = "<group>"; };
 		F39BE95912673BF400E0A674 /* ScriptArguments.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScriptArguments.cpp; sourceTree = "<group>"; };
 		F39BE95A12673BF400E0A674 /* ScriptArguments.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptArguments.h; sourceTree = "<group>"; };
-		F3D461461161D53200CA0D09 /* JSWorkerContextErrorHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWorkerContextErrorHandler.cpp; sourceTree = "<group>"; };
-		F3D461471161D53200CA0D09 /* JSWorkerContextErrorHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWorkerContextErrorHandler.h; sourceTree = "<group>"; };
+		F3D461461161D53200CA0D09 /* JSErrorHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSErrorHandler.cpp; sourceTree = "<group>"; };
+		F3D461471161D53200CA0D09 /* JSErrorHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSErrorHandler.h; sourceTree = "<group>"; };
 		F3D4C47612E07663003DA150 /* InspectorBrowserDebuggerAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorBrowserDebuggerAgent.cpp; sourceTree = "<group>"; };
 		F3D4C47712E07663003DA150 /* InspectorBrowserDebuggerAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorBrowserDebuggerAgent.h; sourceTree = "<group>"; };
 		F4EAF4AC10C742B1009100D3 /* OpenTypeSanitizer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = OpenTypeSanitizer.cpp; path = opentype/OpenTypeSanitizer.cpp; sourceTree = "<group>"; };
@@ -17706,6 +17706,8 @@
 				BCBFB53B0DCD29CF0019B3E5 /* JSDOMWindowShell.h */,
 				BC53DAC611433064000D817E /* JSDOMWrapper.cpp */,
 				65E0E9431133C89F00B4CB10 /* JSDOMWrapper.h */,
+				F3D461461161D53200CA0D09 /* JSErrorHandler.cpp */,
+				F3D461471161D53200CA0D09 /* JSErrorHandler.h */,
 				BC60901E0E91B8EC000C68B5 /* JSEventTarget.cpp */,
 				BC60901D0E91B8EC000C68B5 /* JSEventTarget.h */,
 				3314ACE910892086000F0E56 /* JSExceptionBase.cpp */,
@@ -17717,8 +17719,6 @@
 				14CD8D81106B529000A46D23 /* JSSharedWorkerCustom.cpp */,
 				E1C36D320EB0A094007410BC /* JSWorkerContextBase.cpp */,
 				E1C36D330EB0A094007410BC /* JSWorkerContextBase.h */,
-				F3D461461161D53200CA0D09 /* JSWorkerContextErrorHandler.cpp */,
-				F3D461471161D53200CA0D09 /* JSWorkerContextErrorHandler.h */,
 				BCA378BA0D15F64200B793D6 /* ScheduledAction.cpp */,
 				BCA378BB0D15F64200B793D6 /* ScheduledAction.h */,
 				41F1D21E0EF35C2A00DA8753 /* ScriptCachedFrameData.cpp */,
@@ -21384,7 +21384,7 @@
 				E1CAA5C60E8BD23600A73ECA /* JSWorker.h in Headers */,
 				E18256900EF2B02D00933242 /* JSWorkerContext.h in Headers */,
 				E1C36D350EB0A094007410BC /* JSWorkerContextBase.h in Headers */,
-				F3D461491161D53200CA0D09 /* JSWorkerContextErrorHandler.h in Headers */,
+				F3D461491161D53200CA0D09 /* JSErrorHandler.h in Headers */,
 				E1C362EF0EAF2AA9007410BC /* JSWorkerLocation.h in Headers */,
 				E1271A580EEECDE400F61213 /* JSWorkerNavigator.h in Headers */,
 				BC348BD40DB7F804004ABAB9 /* JSXMLHttpRequest.h in Headers */,
@@ -24227,7 +24227,7 @@
 				E182568F0EF2B02D00933242 /* JSWorkerContext.cpp in Sources */,
 				E1C36D340EB0A094007410BC /* JSWorkerContextBase.cpp in Sources */,
 				E18258AC0EF3CD7000933242 /* JSWorkerContextCustom.cpp in Sources */,
-				F3D461481161D53200CA0D09 /* JSWorkerContextErrorHandler.cpp in Sources */,
+				F3D461481161D53200CA0D09 /* JSErrorHandler.cpp in Sources */,
 				E1CA5CBC0E8CDCAF00E8EF90 /* JSWorkerCustom.cpp in Sources */,
 				E1C362F00EAF2AA9007410BC /* JSWorkerLocation.cpp in Sources */,
 				E1271A590EEECDE400F61213 /* JSWorkerNavigator.cpp in Sources */,
diff --git a/Source/WebCore/bindings/js/JSBindingsAllInOne.cpp b/Source/WebCore/bindings/js/JSBindingsAllInOne.cpp
index 853e2ef..af74e8c 100644
--- a/Source/WebCore/bindings/js/JSBindingsAllInOne.cpp
+++ b/Source/WebCore/bindings/js/JSBindingsAllInOne.cpp
@@ -71,6 +71,7 @@
 #include "JSDeviceOrientationEventCustom.cpp"
 #include "JSDocumentCustom.cpp"
 #include "JSElementCustom.cpp"
+#include "JSErrorHandler.cpp"
 #include "JSEventCustom.cpp"
 #include "JSEventListener.cpp"
 #include "JSEventSourceCustom.cpp"
@@ -139,7 +140,6 @@
 #include "JSWebSocketCustom.cpp"
 #include "JSWorkerContextBase.cpp"
 #include "JSWorkerContextCustom.cpp"
-#include "JSWorkerContextErrorHandler.cpp"
 #include "JSWorkerCustom.cpp"
 #include "JSXMLHttpRequestCustom.cpp"
 #include "JSXMLHttpRequestUploadCustom.cpp"
diff --git a/Source/WebCore/bindings/js/JSDOMBinding.cpp b/Source/WebCore/bindings/js/JSDOMBinding.cpp
index 72c7cd6..e53dcfb 100644
--- a/Source/WebCore/bindings/js/JSDOMBinding.cpp
+++ b/Source/WebCore/bindings/js/JSDOMBinding.cpp
@@ -53,6 +53,7 @@
 #include "ProcessingInstruction.h"
 #include "RangeException.h"
 #include "ScriptCachedFrameData.h"
+#include "ScriptCallStack.h"
 #include "ScriptController.h"
 #include "Settings.h"
 #include "WebCoreJSClientData.h"
@@ -589,7 +590,7 @@ void reportException(ExecState* exec, JSValue exception)
     if (!scriptExecutionContext)
         return;
 
-    scriptExecutionContext->reportException(ustringToString(errorMessage), lineNumber, ustringToString(exceptionSourceURL));
+    scriptExecutionContext->reportException(ustringToString(errorMessage), lineNumber, ustringToString(exceptionSourceURL), 0);
 }
 
 void reportCurrentException(ExecState* exec)
diff --git a/Source/WebCore/bindings/js/JSErrorHandler.cpp b/Source/WebCore/bindings/js/JSErrorHandler.cpp
new file mode 100644
index 0000000..ae8e363
--- /dev/null
+++ b/Source/WebCore/bindings/js/JSErrorHandler.cpp
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "JSErrorHandler.h"
+
+#include "ErrorEvent.h"
+#include "Event.h"
+#include "JSEvent.h"
+#include <runtime/JSLock.h>
+
+using namespace JSC;
+
+namespace WebCore {
+
+JSErrorHandler::JSErrorHandler(JSObject* function, JSObject* wrapper, bool isAttribute, DOMWrapperWorld* isolatedWorld)
+    : JSEventListener(function, wrapper, isAttribute, isolatedWorld)
+{
+}
+
+JSErrorHandler::~JSErrorHandler()
+{
+}
+
+void JSErrorHandler::handleEvent(ScriptExecutionContext* scriptExecutionContext, Event* event)
+{
+    if (!event->isErrorEvent())
+        return JSEventListener::handleEvent(scriptExecutionContext, event);
+
+    ASSERT(scriptExecutionContext);
+    if (!scriptExecutionContext)
+        return;
+
+    ErrorEvent* errorEvent = static_cast<ErrorEvent*>(event);
+
+    JSLock lock(SilenceAssertionsOnly);
+
+    JSObject* jsFunction = this->jsFunction(scriptExecutionContext);
+    if (!jsFunction)
+        return;
+
+    JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(scriptExecutionContext, isolatedWorld());
+    if (!globalObject)
+        return;
+
+    ExecState* exec = globalObject->globalExec();
+
+    CallData callData;
+    CallType callType = jsFunction->getCallData(callData);
+
+    if (callType != CallTypeNone) {
+        RefPtr<JSErrorHandler> protectedctor(this);
+
+        Event* savedEvent = globalObject->currentEvent();
+        globalObject->setCurrentEvent(event);
+
+        MarkedArgumentBuffer args;
+        args.append(jsString(exec, errorEvent->message()));
+        args.append(jsString(exec, errorEvent->filename()));
+        args.append(jsNumber(errorEvent->lineno()));
+
+        JSGlobalData& globalData = globalObject->globalData();
+        DynamicGlobalObjectScope globalObjectScope(exec, globalData.dynamicGlobalObject ? globalData.dynamicGlobalObject : globalObject);
+
+        JSValue thisValue = globalObject->toThisObject(exec);
+
+        globalData.timeoutChecker.start();
+        JSValue returnValue = JSC::call(exec, jsFunction, callType, callData, thisValue, args);
+        globalData.timeoutChecker.stop();
+
+        globalObject->setCurrentEvent(savedEvent);
+
+        if (exec->hadException())
+            reportCurrentException(exec);
+        else {
+            bool retvalbool;
+            if (returnValue.getBoolean(retvalbool) && !retvalbool)
+                event->preventDefault();
+        }
+    }
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/bindings/js/JSErrorHandler.h b/Source/WebCore/bindings/js/JSErrorHandler.h
new file mode 100644
index 0000000..957fd81
--- /dev/null
+++ b/Source/WebCore/bindings/js/JSErrorHandler.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef JSErrorHandler_h
+#define JSErrorHandler_h
+
+#include "JSEventListener.h"
+
+namespace WebCore {
+
+class JSErrorHandler : public JSEventListener {
+public:
+    static PassRefPtr<JSErrorHandler> create(JSC::JSObject* listener, JSC::JSObject* wrapper, bool isAttribute, DOMWrapperWorld* isolatedWorld)
+    {
+        return adoptRef(new JSErrorHandler(listener, wrapper, isAttribute, isolatedWorld));
+    }
+
+    virtual ~JSErrorHandler();
+
+private:
+    JSErrorHandler(JSC::JSObject* function, JSC::JSObject* wrapper, bool isAttribute, DOMWrapperWorld* isolatedWorld);
+    virtual void handleEvent(ScriptExecutionContext*, Event*);
+};
+
+// Creates a JS EventListener for "onerror" event handler in worker context. It has custom implementation because
+// unlike other event listeners it accepts three parameters.
+inline PassRefPtr<JSErrorHandler> createJSErrorHandler(JSC::ExecState* exec, JSC::JSValue listener, JSC::JSObject* wrapper)
+{
+    if (!listener.isObject())
+        return 0;
+
+    return JSErrorHandler::create(asObject(listener), wrapper, true, currentWorld(exec));
+}
+
+} // namespace WebCore
+
+#endif // JSErrorHandler_h
diff --git a/Source/WebCore/bindings/js/JSEventListener.h b/Source/WebCore/bindings/js/JSEventListener.h
index b15c589..83d0d2e 100644
--- a/Source/WebCore/bindings/js/JSEventListener.h
+++ b/Source/WebCore/bindings/js/JSEventListener.h
@@ -59,11 +59,11 @@ namespace WebCore {
         virtual JSC::JSObject* initializeJSFunction(ScriptExecutionContext*) const;
         virtual void markJSFunction(JSC::MarkStack&);
         virtual void invalidateJSFunction(JSC::JSObject*);
-        virtual void handleEvent(ScriptExecutionContext*, Event*);
         virtual bool virtualisAttribute() const;
 
     protected:
         JSEventListener(JSC::JSObject* function, JSC::JSObject* wrapper, bool isAttribute, DOMWrapperWorld* isolatedWorld);
+        virtual void handleEvent(ScriptExecutionContext*, Event*);
 
     private:
         mutable JSC::JSObject* m_jsFunction;
diff --git a/Source/WebCore/bindings/js/JSWorkerContextErrorHandler.cpp b/Source/WebCore/bindings/js/JSWorkerContextErrorHandler.cpp
deleted file mode 100644
index f7d2b02..0000000
--- a/Source/WebCore/bindings/js/JSWorkerContextErrorHandler.cpp
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright (C) 2010 Google Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- *     * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- *     * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-
-#if ENABLE(WORKERS)
-
-#include "JSWorkerContextErrorHandler.h"
-
-#include "ErrorEvent.h"
-#include "Event.h"
-#include "JSEvent.h"
-#include <runtime/JSLock.h>
-
-using namespace JSC;
-
-namespace WebCore {
-
-JSWorkerContextErrorHandler::JSWorkerContextErrorHandler(JSObject* function, JSObject* wrapper, bool isAttribute, DOMWrapperWorld* isolatedWorld)
-    : JSEventListener(function, wrapper, isAttribute, isolatedWorld)
-{
-}
-
-JSWorkerContextErrorHandler::~JSWorkerContextErrorHandler()
-{
-}
-
-void JSWorkerContextErrorHandler::handleEvent(ScriptExecutionContext* scriptExecutionContext, Event* event)
-{
-    ASSERT(scriptExecutionContext);
-    if (!scriptExecutionContext)
-        return;
-
-    JSLock lock(SilenceAssertionsOnly);
-
-    JSObject* jsFunction = this->jsFunction(scriptExecutionContext);
-    if (!jsFunction)
-        return;
-
-    JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(scriptExecutionContext, isolatedWorld());
-    if (!globalObject)
-        return;
-
-    ExecState* exec = globalObject->globalExec();
-
-    CallData callData;
-    CallType callType = jsFunction->getCallData(callData);
-
-    if (callType != CallTypeNone) {
-
-        ref();
-
-        Event* savedEvent = globalObject->currentEvent();
-        globalObject->setCurrentEvent(event);
-
-        ASSERT(event->isErrorEvent());
-        ErrorEvent* errorEvent = static_cast<ErrorEvent*>(event);
-
-        MarkedArgumentBuffer args;
-        args.append(jsString(exec, errorEvent->message()));
-        args.append(jsString(exec, errorEvent->filename()));
-        args.append(jsNumber(errorEvent->lineno()));
-
-        JSGlobalData& globalData = globalObject->globalData();
-        DynamicGlobalObjectScope globalObjectScope(exec, globalData.dynamicGlobalObject ? globalData.dynamicGlobalObject : globalObject);
-
-        JSValue thisValue = globalObject->toThisObject(exec);
-
-        globalData.timeoutChecker.start();
-        JSValue returnValue = JSC::call(exec, jsFunction, callType, callData, thisValue, args);
-        globalData.timeoutChecker.stop();
-
-        globalObject->setCurrentEvent(savedEvent);
-
-        if (exec->hadException())
-            reportCurrentException(exec);
-        else {
-            bool retvalbool;
-            if (returnValue.getBoolean(retvalbool) && !retvalbool)
-                event->preventDefault();
-        }
-
-        deref();
-    }
-}
-
-} // namespace WebCore
-
-#endif // ENABLE(WORKERS)
diff --git a/Source/WebCore/bindings/js/JSWorkerContextErrorHandler.h b/Source/WebCore/bindings/js/JSWorkerContextErrorHandler.h
deleted file mode 100644
index a188299..0000000
--- a/Source/WebCore/bindings/js/JSWorkerContextErrorHandler.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (C) 2010 Google Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- *     * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- *     * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef JSWorkerContextErrorHandler_h
-#define JSWorkerContextErrorHandler_h
-
-#include "JSEventListener.h"
-
-namespace WebCore {
-
-class JSWorkerContextErrorHandler : public JSEventListener {
-public:
-    static PassRefPtr<JSWorkerContextErrorHandler> create(JSC::JSObject* listener, JSC::JSObject* wrapper, bool isAttribute, DOMWrapperWorld* isolatedWorld)
-    {
-        return adoptRef(new JSWorkerContextErrorHandler(listener, wrapper, isAttribute, isolatedWorld));
-    }
-
-    virtual ~JSWorkerContextErrorHandler();
-
-private:
-    JSWorkerContextErrorHandler(JSC::JSObject* function, JSC::JSObject* wrapper, bool isAttribute, DOMWrapperWorld* isolatedWorld);
-    virtual void handleEvent(ScriptExecutionContext*, Event*);
-};
-
-// Creates a JS EventListener for "onerror" event handler in worker context. It has custom implementation because
-// unlike other event listeners it accepts three parameters.
-inline PassRefPtr<JSWorkerContextErrorHandler> createJSWorkerContextErrorHandler(JSC::ExecState* exec, JSC::JSValue listener, JSC::JSObject* wrapper)
-{
-    if (!listener.isObject())
-        return 0;
-
-    return JSWorkerContextErrorHandler::create(asObject(listener), wrapper, true, currentWorld(exec));
-}
-
-} // namespace WebCore
-
-#endif // JSWorkerContextErrorHandler_h
diff --git a/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm b/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
index cff51e9..abef04e 100644
--- a/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
+++ b/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
@@ -1721,9 +1721,9 @@ sub GenerateImplementation
                                 push(@implContent, "    JSDOMGlobalObject* globalObject = castedThis->globalObject();\n");
                             }
                             push(@implContent, "    $implClassName* imp = static_cast<$implClassName*>(static_cast<$className*>(thisObject)->impl());\n");
-                            if ($interfaceName eq "WorkerContext" and $name eq "onerror") {
-                                $implIncludes{"JSWorkerContextErrorHandler.h"} = 1;
-                                push(@implContent, "    imp->set$implSetterFunctionName(createJSWorkerContextErrorHandler(exec, value, thisObject));\n");
+                            if ((($interfaceName eq "DOMWindow") or ($interfaceName eq "WorkerContext")) and $name eq "onerror") {
+                                $implIncludes{"JSErrorHandler.h"} = 1;
+                                push(@implContent, "    imp->set$implSetterFunctionName(createJSErrorHandler(exec, value, thisObject));\n");
                             } else {
                                 push(@implContent, GenerateAttributeEventListenerCall($className, $implSetterFunctionName, $windowEventListener));
                             }
diff --git a/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm b/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm
index f50e74a..c06fe17 100644
--- a/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm
+++ b/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm
@@ -1001,6 +1001,10 @@ END
                 $implIncludes{"V8EventListenerList.h"} = 1;
                 $implIncludes{"V8WorkerContextErrorHandler.h"} = 1;
                 push(@implContentDecls, "    imp->set$implSetterFunctionName(V8EventListenerList::findOrCreateWrapper<V8WorkerContextErrorHandler>(value, true)");
+            } elsif ($interfaceName eq "DOMWindow" and $attribute->signature->name eq "onerror") {
+                $implIncludes{"V8EventListenerList.h"} = 1;
+                $implIncludes{"V8WindowErrorHandler.h"} = 1;
+                push(@implContentDecls, "    imp->set$implSetterFunctionName(V8EventListenerList::findOrCreateWrapper<V8WindowErrorHandler>(value, true)");
             } else {
                 push(@implContentDecls, "    imp->set$implSetterFunctionName(V8DOMWrapper::getEventListener(value, true, ListenerFindOrCreate)");
             }
diff --git a/Source/WebCore/bindings/v8/V8ConsoleMessage.cpp b/Source/WebCore/bindings/v8/V8ConsoleMessage.cpp
index e6871fd..d92822c 100644
--- a/Source/WebCore/bindings/v8/V8ConsoleMessage.cpp
+++ b/Source/WebCore/bindings/v8/V8ConsoleMessage.cpp
@@ -54,7 +54,14 @@ V8ConsoleMessage::V8ConsoleMessage(const String& string, const String& sourceID,
 
 void V8ConsoleMessage::dispatchNow(Page* page)
 {
-    dispatchNow(page, 0);
+    ASSERT(page);
+
+    // Process any delayed messages to make sure that messages
+    // appear in the right order in the console.
+    processDelayed();
+
+    Console* console = page->mainFrame()->domWindow()->console();
+    console->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, m_string, m_lineNumber, m_sourceID);
 }
 
 void V8ConsoleMessage::dispatchLater()
@@ -105,8 +112,8 @@ void V8ConsoleMessage::handler(v8::Handle<v8::Message> message, v8::Handle<v8::V
     Frame* frame = V8Proxy::retrieveFrameForEnteredContext();
     if (!frame)
         return;
-    Page* page = frame->page();
-    if (!page)
+    Document* document = frame->document();
+    if (!document)
         return;
 
     v8::Handle<v8::String> errorMessageString = message->Get();
@@ -122,21 +129,7 @@ void V8ConsoleMessage::handler(v8::Handle<v8::Message> message, v8::Handle<v8::V
     v8::Handle<v8::Value> resourceName = message->GetScriptResourceName();
     bool useURL = resourceName.IsEmpty() || !resourceName->IsString();
     String resourceNameString = useURL ? frame->document()->url() : toWebCoreString(resourceName);
-    V8ConsoleMessage consoleMessage(errorMessage, resourceNameString, message->GetLineNumber());
-    consoleMessage.dispatchNow(page, callStack);
-}
-
-void V8ConsoleMessage::dispatchNow(Page* page, PassRefPtr<ScriptCallStack> callStack)
-{
-    ASSERT(page);
-
-    // Process any delayed messages to make sure that messages
-    // appear in the right order in the console.
-    processDelayed();
-
-    Console* console = page->mainFrame()->domWindow()->console();
-    MessageType messageType = callStack ? UncaughtExceptionMessageType : LogMessageType;
-    console->addMessage(JSMessageSource, messageType, ErrorMessageLevel, m_string, m_lineNumber, m_sourceID, callStack);
+    document->reportException(errorMessage, message->GetLineNumber(), resourceNameString, callStack);
 }
 
 } // namespace WebCore
diff --git a/Source/WebCore/bindings/v8/V8ConsoleMessage.h b/Source/WebCore/bindings/v8/V8ConsoleMessage.h
index 97de24f..6183fc6 100644
--- a/Source/WebCore/bindings/v8/V8ConsoleMessage.h
+++ b/Source/WebCore/bindings/v8/V8ConsoleMessage.h
@@ -82,8 +82,6 @@ namespace WebCore {
         const String m_sourceID;
         const unsigned m_lineNumber;
 
-        void dispatchNow(Page*, PassRefPtr<ScriptCallStack>);
-
         // All delayed messages are stored in this vector. If the vector
         // is 0, there are no delayed messages.
         static Vector<V8ConsoleMessage>* m_delayedMessages;
diff --git a/Source/WebCore/bindings/v8/V8EventListener.h b/Source/WebCore/bindings/v8/V8EventListener.h
index fb6c0bc..bcf7213 100644
--- a/Source/WebCore/bindings/v8/V8EventListener.h
+++ b/Source/WebCore/bindings/v8/V8EventListener.h
@@ -54,8 +54,7 @@ namespace WebCore {
 
         v8::Local<v8::Function> getListenerFunction(ScriptExecutionContext*);
 
-    private:
-      virtual v8::Local<v8::Value> callListenerFunction(ScriptExecutionContext*, v8::Handle<v8::Value> jsEvent, Event*);
+        virtual v8::Local<v8::Value> callListenerFunction(ScriptExecutionContext*, v8::Handle<v8::Value> jsEvent, Event*);
      };
 
 } // namespace WebCore
diff --git a/Source/WebCore/bindings/v8/V8WindowErrorHandler.cpp b/Source/WebCore/bindings/v8/V8WindowErrorHandler.cpp
new file mode 100644
index 0000000..4203ad5
--- /dev/null
+++ b/Source/WebCore/bindings/v8/V8WindowErrorHandler.cpp
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "V8WindowErrorHandler.h"
+
+#include "ErrorEvent.h"
+#include "V8Binding.h"
+
+namespace WebCore {
+
+V8WindowErrorHandler::V8WindowErrorHandler(v8::Local<v8::Object> listener, bool isInline, const WorldContextHandle& worldContext)
+    : V8EventListener(listener, isInline, worldContext)
+{
+}
+
+v8::Local<v8::Value> V8WindowErrorHandler::callListenerFunction(ScriptExecutionContext* context, v8::Handle<v8::Value> jsEvent, Event* event)
+{
+    if (!event->isErrorEvent())
+        return V8EventListener::callListenerFunction(context, jsEvent, event);
+    
+    ErrorEvent* errorEvent = static_cast<ErrorEvent*>(event);
+    v8::Local<v8::Object> listener = getListenerObject(context);
+    v8::Local<v8::Value> returnValue;
+    if (!listener.IsEmpty() && listener->IsFunction()) {
+        v8::Local<v8::Function> callFunction = v8::Local<v8::Function>::Cast(listener);
+        v8::Local<v8::Object> thisValue = v8::Context::GetCurrent()->Global();
+        v8::Handle<v8::Value> parameters[3] = { v8String(errorEvent->message()), v8String(errorEvent->filename()), v8::Integer::New(errorEvent->lineno()) };
+        returnValue = callFunction->Call(thisValue, 3, parameters);
+        if (!returnValue.IsEmpty() && returnValue->IsBoolean() && !returnValue->BooleanValue())
+            event->preventDefault();
+    }
+    return returnValue;
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/bindings/v8/V8WindowErrorHandler.h b/Source/WebCore/bindings/v8/V8WindowErrorHandler.h
new file mode 100644
index 0000000..493a9bf
--- /dev/null
+++ b/Source/WebCore/bindings/v8/V8WindowErrorHandler.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef V8WindowErrorHandler_h
+#define V8WindowErrorHandler_h
+
+#include "V8EventListener.h"
+#include <v8.h>
+#include <wtf/PassRefPtr.h>
+
+namespace WebCore {
+
+class V8WindowErrorHandler : public V8EventListener {
+public:
+    static PassRefPtr<V8WindowErrorHandler> create(v8::Local<v8::Object> listener, bool isInline, const WorldContextHandle& worldContext)
+    {
+        return adoptRef(new V8WindowErrorHandler(listener, isInline, worldContext));
+    }
+
+private:
+    V8WindowErrorHandler(v8::Local<v8::Object> listener, bool isInline, const WorldContextHandle& worldContext);
+
+    virtual v8::Local<v8::Value> callListenerFunction(ScriptExecutionContext*, v8::Handle<v8::Value> jsEvent, Event*);
+};
+
+} // namespace WebCore
+
+#endif // V8WindowErrorHandler_h
diff --git a/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp b/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp
index cefb2fa..eb25814 100644
--- a/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp
+++ b/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp
@@ -37,6 +37,7 @@
 
 #include "DedicatedWorkerContext.h"
 #include "Event.h"
+#include "ScriptCallStack.h"
 #include "SharedWorker.h"
 #include "SharedWorkerContext.h"
 #include "V8Binding.h"
@@ -72,7 +73,7 @@ static void v8MessageHandler(v8::Handle<v8::Message> message, v8::Handle<v8::Val
         String errorMessage = toWebCoreString(message->Get());
         int lineNumber = message->GetLineNumber();
         String sourceURL = toWebCoreString(message->GetScriptResourceName());
-        context->reportException(errorMessage, lineNumber, sourceURL);
+        context->reportException(errorMessage, lineNumber, sourceURL, 0);
     }
 
     isReportingException = false;
diff --git a/Source/WebCore/bindings/v8/WorkerScriptController.cpp b/Source/WebCore/bindings/v8/WorkerScriptController.cpp
index b56d383..42e02e6 100644
--- a/Source/WebCore/bindings/v8/WorkerScriptController.cpp
+++ b/Source/WebCore/bindings/v8/WorkerScriptController.cpp
@@ -34,11 +34,10 @@
 
 #include "WorkerScriptController.h"
 
-#include <v8.h>
-
+#include "DOMTimer.h"
+#include "ScriptCallStack.h"
 #include "ScriptSourceCode.h"
 #include "ScriptValue.h"
-#include "DOMTimer.h"
 #include "V8DOMMap.h"
 #include "V8Proxy.h"
 #include "V8WorkerContext.h"
@@ -46,6 +45,7 @@
 #include "WorkerContextExecutionProxy.h"
 #include "WorkerObjectProxy.h"
 #include "WorkerThread.h"
+#include <v8.h>
 
 namespace WebCore {
 
@@ -80,7 +80,7 @@ ScriptValue WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode,
         if (exception)
             *exception = state.exception;
         else
-            m_workerContext->reportException(state.errorMessage, state.lineNumber, state.sourceURL);
+            m_workerContext->reportException(state.errorMessage, state.lineNumber, state.sourceURL, 0);
     }
 
     return result;
diff --git a/Source/WebCore/dom/Document.cpp b/Source/WebCore/dom/Document.cpp
index ce05a09..0bb025a 100644
--- a/Source/WebCore/dom/Document.cpp
+++ b/Source/WebCore/dom/Document.cpp
@@ -119,6 +119,7 @@
 #include "RenderTextControl.h"
 #include "RenderView.h"
 #include "RenderWidget.h"
+#include "ScriptCallStack.h"
 #include "ScriptController.h"
 #include "ScriptElement.h"
 #include "ScriptEventListener.h"
@@ -2298,6 +2299,17 @@ KURL Document::virtualCompleteURL(const String& url) const
     return completeURL(url);
 }
 
+EventTarget* Document::errorEventTarget()
+{
+    return domWindow();
+}
+
+void Document::logExceptionToConsole(const String& errorMessage, int lineNumber, const String& sourceURL, PassRefPtr<ScriptCallStack> callStack)
+{
+    MessageType messageType = callStack ? UncaughtExceptionMessageType : LogMessageType;
+    addMessage(JSMessageSource, messageType, ErrorMessageLevel, errorMessage, lineNumber, sourceURL, callStack);
+}
+
 void Document::setURL(const KURL& url)
 {
     const KURL& newURL = url.isEmpty() ? blankURL() : url;
@@ -4673,15 +4685,10 @@ void Document::parseDNSPrefetchControlHeader(const String& dnsPrefetchControl)
     m_haveExplicitlyDisabledDNSPrefetch = true;
 }
 
-void Document::reportException(const String& errorMessage, int lineNumber, const String& sourceURL)
-{
-    addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, errorMessage, lineNumber, sourceURL);
-}
-
-void Document::addMessage(MessageSource source, MessageType type, MessageLevel level, const String& message, unsigned lineNumber, const String& sourceURL)
+void Document::addMessage(MessageSource source, MessageType type, MessageLevel level, const String& message, unsigned lineNumber, const String& sourceURL, PassRefPtr<ScriptCallStack> callStack)
 {
     if (DOMWindow* window = domWindow())
-        window->console()->addMessage(source, type, level, message, lineNumber, sourceURL);
+        window->console()->addMessage(source, type, level, message, lineNumber, sourceURL, callStack);
 }
 
 struct PerformTaskContext : Noncopyable {
diff --git a/Source/WebCore/dom/Document.h b/Source/WebCore/dom/Document.h
index 2cd26f9..1ab98a6 100644
--- a/Source/WebCore/dom/Document.h
+++ b/Source/WebCore/dom/Document.h
@@ -931,8 +931,7 @@ public:
     bool isDNSPrefetchEnabled() const { return m_isDNSPrefetchEnabled; }
     void parseDNSPrefetchControlHeader(const String&);
 
-    virtual void reportException(const String& errorMessage, int lineNumber, const String& sourceURL);
-    virtual void addMessage(MessageSource, MessageType, MessageLevel, const String& message, unsigned lineNumber, const String& sourceURL);
+    virtual void addMessage(MessageSource, MessageType, MessageLevel, const String& message, unsigned lineNumber, const String& sourceURL, PassRefPtr<ScriptCallStack>);
     virtual void postTask(PassOwnPtr<Task>); // Executes the task on context's thread asynchronously.
 
 #if USE(JSC)
@@ -1074,6 +1073,9 @@ public:
 
     bool mayCauseFlashOfUnstyledContent() const;
 
+    virtual EventTarget* errorEventTarget();
+    virtual void logExceptionToConsole(const String& errorMessage, int lineNumber, const String& sourceURL, PassRefPtr<ScriptCallStack>);
+
     void initDNSPrefetch();
 
 protected:
diff --git a/Source/WebCore/dom/ErrorEvent.cpp b/Source/WebCore/dom/ErrorEvent.cpp
index 2627d01..c598836 100644
--- a/Source/WebCore/dom/ErrorEvent.cpp
+++ b/Source/WebCore/dom/ErrorEvent.cpp
@@ -30,8 +30,6 @@
 
 #include "config.h"
 
-#if ENABLE(WORKERS)
-
 #include "ErrorEvent.h"
 
 #include "EventNames.h"
@@ -72,5 +70,3 @@ bool ErrorEvent::isErrorEvent() const
 }
 
 } // namespace WebCore
-
-#endif // ENABLE(WORKERS)
diff --git a/Source/WebCore/dom/ErrorEvent.h b/Source/WebCore/dom/ErrorEvent.h
index f81530a..719ca2d 100644
--- a/Source/WebCore/dom/ErrorEvent.h
+++ b/Source/WebCore/dom/ErrorEvent.h
@@ -31,8 +31,6 @@
 #ifndef ErrorEvent_h
 #define ErrorEvent_h
 
-#if ENABLE(WORKERS)
-
 #include "Event.h"
 #include "PlatformString.h"
 
@@ -69,6 +67,4 @@ namespace WebCore {
 
 } // namespace WebCore
 
-#endif // ENABLE(WORKERS)
-
 #endif // ErrorEvent_h
diff --git a/Source/WebCore/dom/Event.cpp b/Source/WebCore/dom/Event.cpp
index 24efc4e..0e11c69 100644
--- a/Source/WebCore/dom/Event.cpp
+++ b/Source/WebCore/dom/Event.cpp
@@ -204,12 +204,10 @@ bool Event::isIDBSuccessEvent() const
 }
 #endif
 
-#if ENABLE(WORKERS)
 bool Event::isErrorEvent() const
 {
     return false;
 }
-#endif
 
 #if ENABLE(TOUCH_EVENTS)
 bool Event::isTouchEvent() const
diff --git a/Source/WebCore/dom/Event.h b/Source/WebCore/dom/Event.h
index 8562cad..f629241 100644
--- a/Source/WebCore/dom/Event.h
+++ b/Source/WebCore/dom/Event.h
@@ -132,9 +132,7 @@ namespace WebCore {
 #if ENABLE(WEB_AUDIO)
         virtual bool isAudioProcessingEvent() const;
 #endif
-#if ENABLE(WORKERS)
         virtual bool isErrorEvent() const;
-#endif
 #if ENABLE(TOUCH_EVENTS)
         virtual bool isTouchEvent() const;
 #endif
diff --git a/Source/WebCore/dom/ScriptExecutionContext.cpp b/Source/WebCore/dom/ScriptExecutionContext.cpp
index bfda17b..f498be0 100644
--- a/Source/WebCore/dom/ScriptExecutionContext.cpp
+++ b/Source/WebCore/dom/ScriptExecutionContext.cpp
@@ -33,14 +33,19 @@
 #include "Database.h"
 #include "DatabaseTask.h"
 #include "DatabaseThread.h"
+#include "ErrorEvent.h"
+#include "EventListener.h"
+#include "EventTarget.h"
 #include "FileThread.h"
 #include "MessagePort.h"
+#include "ScriptCallStack.h"
 #include "SecurityOrigin.h"
 #include "ThreadableBlobRegistry.h"
 #include "WorkerContext.h"
 #include "WorkerThread.h"
 #include <wtf/MainThread.h>
 #include <wtf/PassRefPtr.h>
+#include <wtf/Vector.h>
 
 #if USE(JSC)
 #include "JSDOMWindow.h"
@@ -61,9 +66,25 @@ public:
     }
 };
 
+class ScriptExecutionContext::PendingException : public Noncopyable {
+public:
+    PendingException(const String& errorMessage, int lineNumber, const String& sourceURL, PassRefPtr<ScriptCallStack> callStack)
+        : m_errorMessage(errorMessage)
+        , m_lineNumber(lineNumber)
+        , m_sourceURL(sourceURL)
+        , m_callStack(callStack)
+    {
+    }
+    String m_errorMessage;
+    int m_lineNumber;
+    String m_sourceURL;
+    RefPtr<ScriptCallStack> m_callStack;
+};
+
 ScriptExecutionContext::ScriptExecutionContext()
+    : m_inDispatchErrorEvent(false)
 #if ENABLE(DATABASE)
-    : m_hasOpenDatabases(false)
+    , m_hasOpenDatabases(false)
 #endif
 {
 }
@@ -243,6 +264,43 @@ void ScriptExecutionContext::setSecurityOrigin(PassRefPtr<SecurityOrigin> securi
     m_securityOrigin = securityOrigin;
 }
 
+void ScriptExecutionContext::reportException(const String& errorMessage, int lineNumber, const String& sourceURL, PassRefPtr<ScriptCallStack> callStack)
+{
+    if (m_inDispatchErrorEvent) {
+        if (!m_pendingExceptions)
+            m_pendingExceptions = adoptPtr(new Vector<OwnPtr<PendingException> >());
+        m_pendingExceptions->append(adoptPtr(new PendingException(errorMessage, lineNumber, sourceURL, callStack)));
+        return;
+    }
+
+    // First report the original exception and only then all the nested ones.
+    if (!dispatchErrorEvent(errorMessage, lineNumber, sourceURL))
+        logExceptionToConsole(errorMessage, lineNumber, sourceURL, callStack);
+
+    if (!m_pendingExceptions)
+        return;
+
+    for (size_t i = 0; i < m_pendingExceptions->size(); i++) {
+        PendingException* e = m_pendingExceptions->at(i).get();
+        logExceptionToConsole(e->m_errorMessage, e->m_lineNumber, e->m_sourceURL, e->m_callStack);
+    }
+    m_pendingExceptions.clear();
+}
+
+bool ScriptExecutionContext::dispatchErrorEvent(const String& errorMessage, int lineNumber, const String& sourceURL)
+{
+    EventTarget* target = errorEventTarget();
+    if (!target)
+        return false;
+
+    ASSERT(!m_inDispatchErrorEvent);
+    m_inDispatchErrorEvent = true;
+    RefPtr<ErrorEvent> errorEvent = ErrorEvent::create(errorMessage, sourceURL, lineNumber);
+    target->dispatchEvent(errorEvent);
+    m_inDispatchErrorEvent = false;
+    return errorEvent->defaultPrevented();
+}
+
 void ScriptExecutionContext::addTimeout(int timeoutId, DOMTimer* timer)
 {
     ASSERT(!m_timeouts.contains(timeoutId));
diff --git a/Source/WebCore/dom/ScriptExecutionContext.h b/Source/WebCore/dom/ScriptExecutionContext.h
index e473a4b..fbb96ec 100644
--- a/Source/WebCore/dom/ScriptExecutionContext.h
+++ b/Source/WebCore/dom/ScriptExecutionContext.h
@@ -33,6 +33,7 @@
 #include <wtf/Forward.h>
 #include <wtf/HashMap.h>
 #include <wtf/HashSet.h>
+#include <wtf/OwnPtr.h>
 #include <wtf/PassOwnPtr.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefPtr.h>
@@ -52,11 +53,14 @@ namespace WebCore {
     class DatabaseThread;
 #endif
     class DOMTimer;
+    class EventListener;
+    class EventTarget;
 #if ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
     class FileThread;
 #endif
     class MessagePort;
     class SecurityOrigin;
+    class ScriptCallStack;
 
     class ScriptExecutionContext {
     public:
@@ -85,8 +89,8 @@ namespace WebCore {
 
         SecurityOrigin* securityOrigin() const { return m_securityOrigin.get(); }
 
-        virtual void reportException(const String& errorMessage, int lineNumber, const String& sourceURL) = 0;
-        virtual void addMessage(MessageSource, MessageType, MessageLevel, const String& message, unsigned lineNumber, const String& sourceURL) = 0;
+        void reportException(const String& errorMessage, int lineNumber, const String& sourceURL, PassRefPtr<ScriptCallStack>);
+        virtual void addMessage(MessageSource, MessageType, MessageLevel, const String& message, unsigned lineNumber, const String& sourceURL, PassRefPtr<ScriptCallStack>) = 0;
 
         // Active objects are not garbage collected even if inaccessible, e.g. because their activity may result in callbacks being invoked.
         bool canSuspendActiveDOMObjects();
@@ -148,6 +152,10 @@ namespace WebCore {
         virtual const KURL& virtualURL() const = 0;
         virtual KURL virtualCompleteURL(const String&) const = 0;
 
+        virtual EventTarget* errorEventTarget() = 0;
+        virtual void logExceptionToConsole(const String& errorMessage, int lineNumber, const String& sourceURL, PassRefPtr<ScriptCallStack>) = 0;
+        bool dispatchErrorEvent(const String& errorMessage, int lineNumber, const String& sourceURL);
+
         void closeMessagePorts();
 
         RefPtr<SecurityOrigin> m_securityOrigin;
@@ -165,6 +173,10 @@ namespace WebCore {
         virtual void refScriptExecutionContext() = 0;
         virtual void derefScriptExecutionContext() = 0;
 
+        bool m_inDispatchErrorEvent;
+        class PendingException;
+        OwnPtr<Vector<OwnPtr<PendingException> > > m_pendingExceptions;
+
 #if ENABLE(DATABASE)
         RefPtr<DatabaseThread> m_databaseThread;
         bool m_hasOpenDatabases; // This never changes back to false, even after the database thread is closed.
diff --git a/Source/WebCore/websockets/WebSocket.cpp b/Source/WebCore/websockets/WebSocket.cpp
index 358a742..e15d079 100644
--- a/Source/WebCore/websockets/WebSocket.cpp
+++ b/Source/WebCore/websockets/WebSocket.cpp
@@ -41,6 +41,7 @@
 #include "EventNames.h"
 #include "Logging.h"
 #include "MessageEvent.h"
+#include "ScriptCallStack.h"
 #include "ScriptExecutionContext.h"
 #include "ThreadableWebSocketChannel.h"
 #include "WebSocketChannel.h"
@@ -116,32 +117,32 @@ void WebSocket::connect(const KURL& url, const String& protocol, ExceptionCode&
     m_protocol = protocol;
 
     if (!m_url.isValid()) {
-        scriptExecutionContext()->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Invalid url for WebSocket " + url.string(), 0, scriptExecutionContext()->securityOrigin()->toString());
+        scriptExecutionContext()->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Invalid url for WebSocket " + url.string(), 0, scriptExecutionContext()->securityOrigin()->toString(), 0);
         m_state = CLOSED;
         ec = SYNTAX_ERR;
         return;
     }
 
     if (!m_url.protocolIs("ws") && !m_url.protocolIs("wss")) {
-        scriptExecutionContext()->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Wrong url scheme for WebSocket " + url.string(), 0, scriptExecutionContext()->securityOrigin()->toString());
+        scriptExecutionContext()->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Wrong url scheme for WebSocket " + url.string(), 0, scriptExecutionContext()->securityOrigin()->toString(), 0);
         m_state = CLOSED;
         ec = SYNTAX_ERR;
         return;
     }
     if (m_url.hasFragmentIdentifier()) {
-        scriptExecutionContext()->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "URL has fragment component " + url.string(), 0, scriptExecutionContext()->securityOrigin()->toString());
+        scriptExecutionContext()->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "URL has fragment component " + url.string(), 0, scriptExecutionContext()->securityOrigin()->toString(), 0);
         m_state = CLOSED;
         ec = SYNTAX_ERR;
         return;
     }
     if (!isValidProtocolString(m_protocol)) {
-        scriptExecutionContext()->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Wrong protocol for WebSocket '" + encodeProtocolString(m_protocol) + "'", 0, scriptExecutionContext()->securityOrigin()->toString());
+        scriptExecutionContext()->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Wrong protocol for WebSocket '" + encodeProtocolString(m_protocol) + "'", 0, scriptExecutionContext()->securityOrigin()->toString(), 0);
         m_state = CLOSED;
         ec = SYNTAX_ERR;
         return;
     }
     if (!portAllowed(url)) {
-        scriptExecutionContext()->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, makeString("WebSocket port ", String::number(url.port()), " blocked"), 0, scriptExecutionContext()->securityOrigin()->toString());
+        scriptExecutionContext()->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, makeString("WebSocket port ", String::number(url.port()), " blocked"), 0, scriptExecutionContext()->securityOrigin()->toString(), 0);
         m_state = CLOSED;
         ec = SECURITY_ERR;
         return;
diff --git a/Source/WebCore/websockets/WebSocketChannel.cpp b/Source/WebCore/websockets/WebSocketChannel.cpp
index 09fcd6b..c4cb2e2 100644
--- a/Source/WebCore/websockets/WebSocketChannel.cpp
+++ b/Source/WebCore/websockets/WebSocketChannel.cpp
@@ -41,6 +41,7 @@
 #include "Page.h"
 #include "PlatformString.h"
 #include "ProgressTracker.h"
+#include "ScriptCallStack.h"
 #include "ScriptExecutionContext.h"
 #include "SocketStreamError.h"
 #include "SocketStreamHandle.h"
@@ -155,7 +156,7 @@ void WebSocketChannel::didOpen(SocketStreamHandle* handle)
         InspectorInstrumentation::willSendWebSocketHandshakeRequest(m_context, m_identifier, m_handshake.clientHandshakeRequest());
     CString handshakeMessage = m_handshake.clientHandshakeMessage();
     if (!handle->send(handshakeMessage.data(), handshakeMessage.length())) {
-        m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Error sending handshake message.", 0, m_handshake.clientOrigin());
+        m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Error sending handshake message.", 0, m_handshake.clientOrigin(), 0);
         handle->close();
     }
 }
@@ -218,7 +219,7 @@ void WebSocketChannel::didFail(SocketStreamHandle* handle, const SocketStreamErr
             message = makeString("WebSocket network error: error code ", String::number(error.errorCode()));
         else
             message = makeString("WebSocket network error: ", error.localizedDescription());
-        m_context->addMessage(OtherMessageSource, NetworkErrorMessageType, ErrorMessageLevel, message, 0, error.failingURL());
+        m_context->addMessage(OtherMessageSource, NetworkErrorMessageType, ErrorMessageLevel, message, 0, error.failingURL(), 0);
     }
     m_shouldDiscardReceivedData = true;
     handle->close();
@@ -249,7 +250,7 @@ bool WebSocketChannel::appendToBuffer(const char* data, size_t len)
         m_bufferSize = newBufferSize;
         return true;
     }
-    m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, makeString("WebSocket frame (at ", String::number(static_cast<unsigned long>(newBufferSize)), " bytes) is too long."), 0, m_handshake.clientOrigin());
+    m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, makeString("WebSocket frame (at ", String::number(static_cast<unsigned long>(newBufferSize)), " bytes) is too long."), 0, m_handshake.clientOrigin(), 0);
     return false;
 }
 
diff --git a/Source/WebCore/websockets/WebSocketHandshake.cpp b/Source/WebCore/websockets/WebSocketHandshake.cpp
index 9506ad4..f653415 100644
--- a/Source/WebCore/websockets/WebSocketHandshake.cpp
+++ b/Source/WebCore/websockets/WebSocketHandshake.cpp
@@ -42,6 +42,7 @@
 #include "HTTPHeaderMap.h"
 #include "KURL.h"
 #include "Logging.h"
+#include "ScriptCallStack.h"
 #include "ScriptExecutionContext.h"
 #include "SecurityOrigin.h"
 
@@ -320,7 +321,7 @@ int WebSocketHandshake::readServerHandshake(const char* header, size_t len)
     m_response.setStatusText(statusText);
     if (statusCode != 101) {
         m_mode = Failed;
-        m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, makeString("Unexpected response code: ", String::number(statusCode)), 0, clientOrigin());
+        m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, makeString("Unexpected response code: ", String::number(statusCode)), 0, clientOrigin(), 0);
         return len;
     }
     m_mode = Normal;
@@ -450,7 +451,7 @@ int WebSocketHandshake::readStatusLine(const char* header, size_t headerLength,
             // The caller isn't prepared to deal with null bytes in status
             // line. WebSockets specification doesn't prohibit this, but HTTP
             // does, so we'll just treat this as an error. 
-            m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Status line contains embedded null", 0, clientOrigin());
+            m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Status line contains embedded null", 0, clientOrigin(), 0);
             return p + 1 - header;
         } else if (*p == '\n')
             break;
@@ -460,19 +461,19 @@ int WebSocketHandshake::readStatusLine(const char* header, size_t headerLength,
 
     const char* end = p + 1;
     if (end - header > maximumLength) {
-        m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Status line is too long", 0, clientOrigin());
+        m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Status line is too long", 0, clientOrigin(), 0);
         return maximumLength;
     }
     int lineLength = end - header;
 
     if (!space1 || !space2) {
-        m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "No response code found: " + trimConsoleMessage(header, lineLength - 1), 0, clientOrigin());
+        m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "No response code found: " + trimConsoleMessage(header, lineLength - 1), 0, clientOrigin(), 0);
         return lineLength;
     }
 
     // The line must end with "\r\n".
     if (*(end - 2) != '\r') {
-        m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Status line does not end with CRLF", 0, clientOrigin());
+        m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Status line does not end with CRLF", 0, clientOrigin(), 0);
         return lineLength;
     }
 
@@ -481,7 +482,7 @@ int WebSocketHandshake::readStatusLine(const char* header, size_t headerLength,
         return lineLength;
     for (int i = 0; i < 3; ++i)
         if (statusCodeString[i] < '0' || statusCodeString[i] > '9') {
-            m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Invalid status code: " + statusCodeString, 0, clientOrigin());
+            m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Invalid status code: " + statusCodeString, 0, clientOrigin(), 0);
             return lineLength;
         }
 
@@ -509,13 +510,13 @@ const char* WebSocketHandshake::readHTTPHeaders(const char* start, const char* e
                 if (name.isEmpty()) {
                     if (p + 1 < end && *(p + 1) == '\n')
                         return p + 2;
-                    m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "CR doesn't follow LF at " + trimConsoleMessage(p, end - p), 0, clientOrigin());
+                    m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "CR doesn't follow LF at " + trimConsoleMessage(p, end - p), 0, clientOrigin(), 0);
                     return 0;
                 }
-                m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Unexpected CR in name at " + trimConsoleMessage(name.data(), name.size()), 0, clientOrigin());
+                m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Unexpected CR in name at " + trimConsoleMessage(name.data(), name.size()), 0, clientOrigin(), 0);
                 return 0;
             case '\n':
-                m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Unexpected LF in name at " + trimConsoleMessage(name.data(), name.size()), 0, clientOrigin());
+                m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Unexpected LF in name at " + trimConsoleMessage(name.data(), name.size()), 0, clientOrigin(), 0);
                 return 0;
             case ':':
                 break;
@@ -536,7 +537,7 @@ const char* WebSocketHandshake::readHTTPHeaders(const char* start, const char* e
             case '\r':
                 break;
             case '\n':
-                m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Unexpected LF in value at " + trimConsoleMessage(value.data(), value.size()), 0, clientOrigin());
+                m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Unexpected LF in value at " + trimConsoleMessage(value.data(), value.size()), 0, clientOrigin(), 0);
                 return 0;
             default:
                 value.append(*p);
@@ -547,17 +548,17 @@ const char* WebSocketHandshake::readHTTPHeaders(const char* start, const char* e
             }
         }
         if (p >= end || *p != '\n') {
-            m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "CR doesn't follow LF after value at " + trimConsoleMessage(p, end - p), 0, clientOrigin());
+            m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "CR doesn't follow LF after value at " + trimConsoleMessage(p, end - p), 0, clientOrigin(), 0);
             return 0;
         }
         AtomicString nameStr(String::fromUTF8(name.data(), name.size()));
         String valueStr = String::fromUTF8(value.data(), value.size());
         if (nameStr.isNull()) {
-            m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "invalid UTF-8 sequence in header name", 0, clientOrigin());
+            m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "invalid UTF-8 sequence in header name", 0, clientOrigin(), 0);
             return 0;
         }
         if (valueStr.isNull()) {
-            m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "invalid UTF-8 sequence in header value", 0, clientOrigin());
+            m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "invalid UTF-8 sequence in header value", 0, clientOrigin(), 0);
             return 0;
         }
         LOG(Network, "name=%s value=%s", nameStr.string().utf8().data(), valueStr.utf8().data());
@@ -581,24 +582,24 @@ void WebSocketHandshake::processHeaders()
 bool WebSocketHandshake::checkResponseHeaders()
 {
     if (m_wsOrigin.isNull()) {
-        m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Error during WebSocket handshake: 'sec-websocket-origin' header is missing", 0, clientOrigin());
+        m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Error during WebSocket handshake: 'sec-websocket-origin' header is missing", 0, clientOrigin(), 0);
         return false;
     }
     if (m_wsLocation.isNull()) {
-        m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Error during WebSocket handshake: 'sec-websocket-location' header is missing", 0, clientOrigin());
+        m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Error during WebSocket handshake: 'sec-websocket-location' header is missing", 0, clientOrigin(), 0);
         return false;
     }
 
     if (clientOrigin() != m_wsOrigin) {
-        m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Error during WebSocket handshake: origin mismatch: " + clientOrigin() + " != " + m_wsOrigin, 0, clientOrigin());
+        m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Error during WebSocket handshake: origin mismatch: " + clientOrigin() + " != " + m_wsOrigin, 0, clientOrigin(), 0);
         return false;
     }
     if (clientLocation() != m_wsLocation) {
-        m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Error during WebSocket handshake: location mismatch: " + clientLocation() + " != " + m_wsLocation, 0, clientOrigin());
+        m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Error during WebSocket handshake: location mismatch: " + clientLocation() + " != " + m_wsLocation, 0, clientOrigin(), 0);
         return false;
     }
     if (!m_clientProtocol.isEmpty() && m_clientProtocol != m_wsProtocol) {
-        m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Error during WebSocket handshake: protocol mismatch: " + m_clientProtocol + " != " + m_wsProtocol, 0, clientOrigin());
+        m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Error during WebSocket handshake: protocol mismatch: " + m_clientProtocol + " != " + m_wsProtocol, 0, clientOrigin(), 0);
         return false;
     }
     return true;
diff --git a/Source/WebCore/workers/DefaultSharedWorkerRepository.cpp b/Source/WebCore/workers/DefaultSharedWorkerRepository.cpp
index 3a14b62..c20cd30 100644
--- a/Source/WebCore/workers/DefaultSharedWorkerRepository.cpp
+++ b/Source/WebCore/workers/DefaultSharedWorkerRepository.cpp
@@ -42,6 +42,7 @@
 #include "MessagePort.h"
 #include "NotImplemented.h"
 #include "PlatformString.h"
+#include "ScriptCallStack.h"
 #include "SecurityOrigin.h"
 #include "SecurityOriginHash.h"
 #include "SharedWorker.h"
@@ -155,7 +156,7 @@ void SharedWorkerProxy::postTaskForModeToWorkerContext(PassOwnPtr<ScriptExecutio
 
 static void postExceptionTask(ScriptExecutionContext* context, const String& errorMessage, int lineNumber, const String& sourceURL)
 {
-    context->reportException(errorMessage, lineNumber, sourceURL);
+    context->reportException(errorMessage, lineNumber, sourceURL, 0);
 }
 
 void SharedWorkerProxy::postExceptionToWorkerObject(const String& errorMessage, int lineNumber, const String& sourceURL)
@@ -167,7 +168,7 @@ void SharedWorkerProxy::postExceptionToWorkerObject(const String& errorMessage,
 
 static void postConsoleMessageTask(ScriptExecutionContext* document, MessageSource source, MessageType type, MessageLevel level, const String& message, unsigned lineNumber, const String& sourceURL)
 {
-    document->addMessage(source, type, level, message, lineNumber, sourceURL);
+    document->addMessage(source, type, level, message, lineNumber, sourceURL, 0);
 }
 
 void SharedWorkerProxy::postConsoleMessageToWorkerObject(MessageSource source, MessageType type, MessageLevel level, const String& message, int lineNumber, const String& sourceURL)
diff --git a/Source/WebCore/workers/WorkerContext.cpp b/Source/WebCore/workers/WorkerContext.cpp
index d5d1ccc..36c4215 100644
--- a/Source/WebCore/workers/WorkerContext.cpp
+++ b/Source/WebCore/workers/WorkerContext.cpp
@@ -47,6 +47,7 @@
 #include "KURL.h"
 #include "MessagePort.h"
 #include "NotImplemented.h"
+#include "ScriptCallStack.h"
 #include "ScriptSourceCode.h"
 #include "ScriptValue.h"
 #include "SecurityOrigin.h"
@@ -103,7 +104,6 @@ WorkerContext::WorkerContext(const KURL& url, const String& userAgent, WorkerThr
     , m_script(new WorkerScriptController(this))
     , m_thread(thread)
     , m_closing(false)
-    , m_reportingException(false)
 {
     setSecurityOrigin(SecurityOrigin::create(url));
 }
@@ -257,23 +257,17 @@ void WorkerContext::importScripts(const Vector<String>& urls, ExceptionCode& ec)
     }
 }
 
-void WorkerContext::reportException(const String& errorMessage, int lineNumber, const String& sourceURL)
+EventTarget* WorkerContext::errorEventTarget()
 {
-    bool errorHandled = false;
-    if (!m_reportingException) {
-        if (onerror()) {
-            m_reportingException = true;
-            RefPtr<ErrorEvent> errorEvent(ErrorEvent::create(errorMessage, sourceURL, lineNumber));
-            onerror()->handleEvent(this, errorEvent.get());
-            errorHandled = errorEvent->defaultPrevented();
-            m_reportingException = false;
-        }
-    }
-    if (!errorHandled)
-        thread()->workerReportingProxy().postExceptionToWorkerObject(errorMessage, lineNumber, sourceURL);
+    return this;
+}
+
+void WorkerContext::logExceptionToConsole(const String& errorMessage, int lineNumber, const String& sourceURL, PassRefPtr<ScriptCallStack>)
+{
+    thread()->workerReportingProxy().postExceptionToWorkerObject(errorMessage, lineNumber, sourceURL);
 }
 
-void WorkerContext::addMessage(MessageSource source, MessageType type, MessageLevel level, const String& message, unsigned lineNumber, const String& sourceURL)
+void WorkerContext::addMessage(MessageSource source, MessageType type, MessageLevel level, const String& message, unsigned lineNumber, const String& sourceURL, PassRefPtr<ScriptCallStack>)
 {
     thread()->workerReportingProxy().postConsoleMessageToWorkerObject(source, type, level, message, lineNumber, sourceURL);
 }
diff --git a/Source/WebCore/workers/WorkerContext.h b/Source/WebCore/workers/WorkerContext.h
index a0dbaae..ae370e0 100644
--- a/Source/WebCore/workers/WorkerContext.h
+++ b/Source/WebCore/workers/WorkerContext.h
@@ -101,8 +101,7 @@ namespace WebCore {
         void clearInterval(int timeoutId);
 
         // ScriptExecutionContext
-        virtual void reportException(const String& errorMessage, int lineNumber, const String& sourceURL);
-        virtual void addMessage(MessageSource, MessageType, MessageLevel, const String& message, unsigned lineNumber, const String& sourceURL);
+        virtual void addMessage(MessageSource, MessageType, MessageLevel, const String& message, unsigned lineNumber, const String& sourceURL, PassRefPtr<ScriptCallStack>);
 
 #if ENABLE(NOTIFICATIONS)
         NotificationCenter* webkitNotifications() const;
@@ -174,6 +173,9 @@ namespace WebCore {
         virtual const KURL& virtualURL() const;
         virtual KURL virtualCompleteURL(const String&) const;
 
+        virtual EventTarget* errorEventTarget();
+        virtual void logExceptionToConsole(const String& errorMessage, int lineNumber, const String& sourceURL, PassRefPtr<ScriptCallStack>);
+
         KURL m_url;
         String m_userAgent;
 
@@ -190,7 +192,6 @@ namespace WebCore {
         mutable RefPtr<DOMURL> m_domURL;
 #endif
         bool m_closing;
-        bool m_reportingException;
         EventTargetData m_eventTargetData;
 
         HashSet<Observer*> m_workerObservers;
diff --git a/Source/WebCore/workers/WorkerMessagingProxy.cpp b/Source/WebCore/workers/WorkerMessagingProxy.cpp
index e89ccb4..eca8e2e 100644
--- a/Source/WebCore/workers/WorkerMessagingProxy.cpp
+++ b/Source/WebCore/workers/WorkerMessagingProxy.cpp
@@ -39,6 +39,7 @@
 #include "ErrorEvent.h"
 #include "ExceptionCode.h"
 #include "MessageEvent.h"
+#include "ScriptCallStack.h"
 #include "ScriptExecutionContext.h"
 #include "Worker.h"
 
@@ -130,7 +131,7 @@ private:
 
         bool errorHandled = !workerObject->dispatchEvent(ErrorEvent::create(m_errorMessage, m_sourceURL, m_lineNumber));
         if (!errorHandled)
-            context->reportException(m_errorMessage, m_lineNumber, m_sourceURL);
+            context->reportException(m_errorMessage, m_lineNumber, m_sourceURL, 0);
     }
 
     String m_errorMessage;
@@ -282,7 +283,7 @@ static void postConsoleMessageTask(ScriptExecutionContext* context, WorkerMessag
 {
     if (messagingProxy->askedToTerminate())
         return;
-    context->addMessage(source, type, level, message, lineNumber, sourceURL);
+    context->addMessage(source, type, level, message, lineNumber, sourceURL, 0);
 }
 
 void WorkerMessagingProxy::postConsoleMessageToWorkerObject(MessageSource source, MessageType type, MessageLevel level, const String& message, int lineNumber, const String& sourceURL)
diff --git a/Source/WebCore/xml/XMLHttpRequest.cpp b/Source/WebCore/xml/XMLHttpRequest.cpp
index ee9e20f..48a4f7f 100644
--- a/Source/WebCore/xml/XMLHttpRequest.cpp
+++ b/Source/WebCore/xml/XMLHttpRequest.cpp
@@ -38,6 +38,7 @@
 #include "InspectorInstrumentation.h"
 #include "ResourceError.h"
 #include "ResourceRequest.h"
+#include "ScriptCallStack.h"
 #include "SecurityOrigin.h"
 #include "Settings.h"
 #include "SharedBuffer.h"
@@ -806,7 +807,7 @@ static void reportUnsafeUsage(ScriptExecutionContext* context, const String& mes
         return;
     // FIXME: It's not good to report the bad usage without indicating what source line it came from.
     // We should pass additional parameters so we can tell the console where the mistake occurred.
-    context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, message, 1, String());
+    context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, message, 1, String(), 0);
 }
 
 void XMLHttpRequest::setRequestHeader(const AtomicString& name, const String& value, ExceptionCode& ec)
diff --git a/Source/WebKit/chromium/ChangeLog b/Source/WebKit/chromium/ChangeLog
index e81736f..27afde9 100644
--- a/Source/WebKit/chromium/ChangeLog
+++ b/Source/WebKit/chromium/ChangeLog
@@ -1,3 +1,39 @@
+2010-12-27  Yury Semikhatsky  <yurys at chromium.org>
+
+        Reviewed by Pavel Feldman.
+
+        WebCore doesn't fire window.onerror event when uncaught JavaScript exceptions are thrown
+        https://bugs.webkit.org/show_bug.cgi?id=8519
+
+        Uncaught exceptions are propagated to window.onerror hander if one is present.
+        The handler is expected to be a function accepting three arguments: error message,
+        resource url and line number where the exception occured.
+
+        It was decided to dispatch ErrorEvent to all listeners/handlers no matter if they
+        were created in the same isolated world where the exception occured or not.
+
+        Tests: fast/events/window-onerror1.html
+               fast/events/window-onerror10.html
+               fast/events/window-onerror11.html
+               fast/events/window-onerror12.html
+               fast/events/window-onerror2.html
+               fast/events/window-onerror3.html
+               fast/events/window-onerror4.html
+               fast/events/window-onerror5.html
+               fast/events/window-onerror6.html
+               fast/events/window-onerror7.html
+               fast/events/window-onerror8.html
+               fast/events/window-onerror9.html
+               http/tests/security/window-onerror-exception-in-iframe.html
+               userscripts/window-onerror-for-isolated-world-1.html
+               userscripts/window-onerror-for-isolated-world-2.html
+
+        * src/WebWorkerClientImpl.cpp:
+        (WebKit::WebWorkerClientImpl::postExceptionToWorkerObject):
+        (WebKit::WebWorkerClientImpl::postConsoleMessageToWorkerObject):
+        (WebKit::WebWorkerClientImpl::postExceptionToWorkerObjectTask):
+        (WebKit::WebWorkerClientImpl::postConsoleMessageToWorkerObjectTask):
+
 2011-01-19  Dmitry Titov  <dimich at chromium.org>
 
         [Chromium] Unreviewed, build fix.
diff --git a/Source/WebKit/chromium/src/WebWorkerClientImpl.cpp b/Source/WebKit/chromium/src/WebWorkerClientImpl.cpp
index 18282e3..f90e7e8 100644
--- a/Source/WebKit/chromium/src/WebWorkerClientImpl.cpp
+++ b/Source/WebKit/chromium/src/WebWorkerClientImpl.cpp
@@ -41,6 +41,7 @@
 #include "MessageEvent.h"
 #include "MessagePort.h"
 #include "MessagePortChannel.h"
+#include "ScriptCallStack.h"
 #include "ScriptExecutionContext.h"
 #include "Worker.h"
 #include "WorkerContext.h"
@@ -247,7 +248,7 @@ void WebWorkerClientImpl::postExceptionToWorkerObject(const WebString& errorMess
                                                                 sourceURL,
                                                                 lineNumber));
     if (unhandled)
-        m_scriptExecutionContext->reportException(errorMessage, lineNumber, sourceURL);
+        m_scriptExecutionContext->reportException(errorMessage, lineNumber, sourceURL, 0);
 }
 
 void WebWorkerClientImpl::postConsoleMessageToWorkerObject(int destination,
@@ -274,7 +275,7 @@ void WebWorkerClientImpl::postConsoleMessageToWorkerObject(int destination,
                                          static_cast<MessageType>(messageType),
                                          static_cast<MessageLevel>(messageLevel),
                                          String(message), lineNumber,
-                                         String(sourceURL));
+                                         String(sourceURL), 0);
 }
 
 void WebWorkerClientImpl::postConsoleMessageToWorkerObject(int sourceId,
@@ -381,9 +382,7 @@ void WebWorkerClientImpl::postExceptionToWorkerObjectTask(
                                                                       sourceURL,
                                                                       lineNumber));
     if (!handled)
-        thisPtr->m_scriptExecutionContext->reportException(errorMessage,
-                                                           lineNumber,
-                                                           sourceURL);
+        thisPtr->m_scriptExecutionContext->reportException(errorMessage, lineNumber, sourceURL, 0);
 }
 
 void WebWorkerClientImpl::postConsoleMessageToWorkerObjectTask(ScriptExecutionContext* context,
@@ -398,8 +397,7 @@ void WebWorkerClientImpl::postConsoleMessageToWorkerObjectTask(ScriptExecutionCo
     thisPtr->m_scriptExecutionContext->addMessage(static_cast<MessageSource>(sourceId),
                                                   static_cast<MessageType>(messageType),
                                                   static_cast<MessageLevel>(messageLevel),
-                                                  message, lineNumber,
-                                                  sourceURL);
+                                                  message, lineNumber, sourceURL, 0);
 }
 
 void WebWorkerClientImpl::confirmMessageFromWorkerObjectTask(ScriptExecutionContext* context,

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list