Return value of window.onerror has inverted semantics
authoryurys@chromium.org <yurys@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 Aug 2011 09:28:09 +0000 (09:28 +0000)
committeryurys@chromium.org <yurys@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 Aug 2011 09:28:09 +0000 (09:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=67119

Source/WebCore:

Error is now treated as handled only when window.onerror function returns true.

Reviewed by Darin Adler.

Test: fast/events/window-onerror13.html

* bindings/js/JSErrorHandler.cpp:
(WebCore::JSErrorHandler::handleEvent):
* bindings/v8/V8WindowErrorHandler.cpp:
(WebCore::V8WindowErrorHandler::callListenerFunction):
* bindings/v8/V8WorkerContextErrorHandler.cpp:
(WebCore::V8WorkerContextErrorHandler::callListenerFunction):

LayoutTests:

Reviewed by Darin Adler.

* fast/events/window-onerror1.html:
* fast/events/window-onerror11.html:
* fast/events/window-onerror12.html:
* fast/events/window-onerror13-expected.txt: Added.
* fast/events/window-onerror13.html: Copied from LayoutTests/fast/events/window-onerror11.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-onerror8.html:
* fast/events/window-onerror9.html:
* fast/workers/resources/worker-script-error-bubbled.js:
(onerror):
* fast/workers/resources/worker-script-error-handled.js:
(onerror):
* http/tests/security/window-onerror-exception-in-iframe.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@94061 268f45cc-cd09-0410-ab3c-d52691b4dbfc

20 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/events/window-onerror1.html
LayoutTests/fast/events/window-onerror11.html
LayoutTests/fast/events/window-onerror12.html
LayoutTests/fast/events/window-onerror13-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/window-onerror13.html [new file with mode: 0644]
LayoutTests/fast/events/window-onerror2.html
LayoutTests/fast/events/window-onerror3.html
LayoutTests/fast/events/window-onerror4.html
LayoutTests/fast/events/window-onerror5.html
LayoutTests/fast/events/window-onerror6.html
LayoutTests/fast/events/window-onerror8.html
LayoutTests/fast/events/window-onerror9.html
LayoutTests/fast/workers/resources/worker-script-error-bubbled.js
LayoutTests/fast/workers/resources/worker-script-error-handled.js
LayoutTests/http/tests/security/window-onerror-exception-in-iframe.html
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSErrorHandler.cpp
Source/WebCore/bindings/v8/V8WindowErrorHandler.cpp
Source/WebCore/bindings/v8/V8WorkerContextErrorHandler.cpp

index fa708e3..918fa1c 100644 (file)
@@ -1,3 +1,28 @@
+2011-08-29  Yury Semikhatsky  <yurys@chromium.org>
+
+        Return value of window.onerror has inverted semantics
+        https://bugs.webkit.org/show_bug.cgi?id=67119
+
+        Reviewed by Darin Adler.
+
+        * fast/events/window-onerror1.html:
+        * fast/events/window-onerror11.html:
+        * fast/events/window-onerror12.html:
+        * fast/events/window-onerror13-expected.txt: Added.
+        * fast/events/window-onerror13.html: Copied from LayoutTests/fast/events/window-onerror11.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-onerror8.html:
+        * fast/events/window-onerror9.html:
+        * fast/workers/resources/worker-script-error-bubbled.js:
+        (onerror):
+        * fast/workers/resources/worker-script-error-handled.js:
+        (onerror):
+        * http/tests/security/window-onerror-exception-in-iframe.html:
+
 2011-08-30  Takashi Toyoshima  <toyoshim@chromium.org>
 
         [WebSocket] Prevent unnecessary pywebsocket warnings on layout tests.
index 59d2495..0bdaa9b 100644 (file)
@@ -20,7 +20,7 @@ function test()
     window.onerror = function (error, url, line) {
         url = url ? url.match( /[^\/]+\/?$/ )[0] : url;
         print("PASS: caught global error: " + error + " at " + url + ":" + line, "green");
-        return false;
+        return true;
     };
     hahaha_good_luck_finding_me(); // caught by window.onerror
 }
index 7655fa7..dddec7e 100644 (file)
@@ -18,7 +18,7 @@ window.onerror = function(msg, url, line)
 {
     url = url ? url.match( /[^\/]+\/?$/ )[0] : url;
     log("Main frame window.onerror: " + msg + " at " + url + ":" + line);
-    return false;
+    return true;
 }
 
 throwException();
index dede975..b115710 100644 (file)
@@ -20,7 +20,7 @@ window.onerror = function(msg, url, line)
     log("msg: " + msg);
     log("url: " + url);
     log("line: " + line);
-    return false;
+    return true;
 }
 
 var evt = document.createEvent("Event");
diff --git a/LayoutTests/fast/events/window-onerror13-expected.txt b/LayoutTests/fast/events/window-onerror13-expected.txt
new file mode 100644 (file)
index 0000000..6f0d6d9
--- /dev/null
@@ -0,0 +1,6 @@
+CONSOLE MESSAGE: line 0: An Error
+Test that error is treated as not handled when window.onerror return value is not 'true'. Bug 67119.
+
+Uncaught error should be printed in console when window.onerror returns not true.
+DONE.
+
diff --git a/LayoutTests/fast/events/window-onerror13.html b/LayoutTests/fast/events/window-onerror13.html
new file mode 100644 (file)
index 0000000..833631b
--- /dev/null
@@ -0,0 +1,27 @@
+<html>
+<head>
+<script src="resources/window-onerror.js">
+</script>
+</head>
+<body>
+<p>Test that error is treated as not handled when window.onerror return
+value is not 'true'. <a href="https://bugs.webkit.org/show_bug.cgi?id=67119">Bug 67119</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("Uncaught error should be printed in console when window.onerror returns not true.");
+  log("DONE.");
+}
+
+throw "An Error";
+</script>
+</body>
+</html>
index 8f458bc..d2c7868 100644 (file)
@@ -21,7 +21,7 @@ window.onerror = function(msg, url, line)
     if (++unhandledErrorCount === 3 && window.layoutTestController)
         layoutTestController.notifyDone();
 
-    return false;
+    return true;
 }
 
 function delayedThrowException()
index ee2893f..935cbe3 100644 (file)
@@ -11,7 +11,7 @@ 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;
+        return true;
     };
     unknownObject.unknownProperty++;
 }
index c51887d..f16baba 100644 (file)
@@ -11,7 +11,7 @@ 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;
+        return true;
     };
     eval("1=2");
 }
index 932d438..6e05820 100644 (file)
@@ -11,7 +11,7 @@ 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;
+        return true;
     };
     eval("a(");
 }
index 1978436..7e9f5d9 100644 (file)
@@ -14,7 +14,7 @@ window.onerror = function(msg, url, line)
 {
     url = url ? url.match( /[^\/]+\/?$/ )[0] : url;
     log("Main frame window.onerror: " + msg + " at " + url + ":" + line);
-    return false;
+    return true;
 }
 </script>
 <script>
index bade538..843fdb9 100644 (file)
@@ -18,7 +18,7 @@ window.onerror = function(msg, url, line)
         log("PASSED: this === window");
     else
         log("FAILED: this === window");
-    return false;
+    return true;
 }
 
 throw 2010;
index 1086ace..e286322 100644 (file)
@@ -25,7 +25,7 @@ window.onerror = function(msg, url, line)
     log("window.event.lineno = " + window.event.lineno);
     if (window.layoutTestController)
         layoutTestController.notifyDone();
-    return false;
+    return true;
 }
 
 throw new Error(2010);
index 081decb..20dff37 100644 (file)
@@ -4,7 +4,7 @@ onerror = function(message, url, lineno)
         postMessage("FAIL: Bad location. Actual: " + url + " Expected: " + location.href);
     splitUrl = url.split('/');
     postMessage("PASS: onerror in worker context invoked for a script that has script error '" + message + "' at line " + lineno + " in " + splitUrl[splitUrl.length - 1]);
-    return true;
+    return false;
 }
 
 foo.bar = 0;
index 50d9077..a20d410 100644 (file)
@@ -1,7 +1,7 @@
 onerror = function(message, url, lineno)
 {
     postMessage("onerror invoked for a script that has script error '" + message + "' at line " + lineno);
-    return false;
+    return true;
 }
 
 foo.bar = 0;
index 0904e39..88af766 100644 (file)
@@ -17,7 +17,7 @@ window.onerror = function(msg, url, line)
 {
     url = url ? url.match( /[^\/]+\/?$/ )[0] : url;
     log("Main frame window.onerror: " + msg + " at " + url + ":" + line);
-    return false;
+    return true;
 }
 
 function receiveMessage(event) {
index 8951a73..7e39feb 100644 (file)
@@ -1,3 +1,21 @@
+2011-08-29  Yury Semikhatsky  <yurys@chromium.org>
+
+        Return value of window.onerror has inverted semantics
+        https://bugs.webkit.org/show_bug.cgi?id=67119
+
+        Error is now treated as handled only when window.onerror function returns true.
+
+        Reviewed by Darin Adler.
+
+        Test: fast/events/window-onerror13.html
+
+        * bindings/js/JSErrorHandler.cpp:
+        (WebCore::JSErrorHandler::handleEvent):
+        * bindings/v8/V8WindowErrorHandler.cpp:
+        (WebCore::V8WindowErrorHandler::callListenerFunction):
+        * bindings/v8/V8WorkerContextErrorHandler.cpp:
+        (WebCore::V8WorkerContextErrorHandler::callListenerFunction):
+
 2011-08-29  Ryosuke Niwa  <rniwa@webkit.org>
 
         Touch Internals.cpp in an attempt to fix GTK+ build.
index 3d916e6..4f2ce39 100644 (file)
@@ -102,7 +102,7 @@ void JSErrorHandler::handleEvent(ScriptExecutionContext* scriptExecutionContext,
             reportCurrentException(exec);
         else {
             bool retvalbool;
-            if (returnValue.getBoolean(retvalbool) && !retvalbool)
+            if (returnValue.getBoolean(retvalbool) && retvalbool)
                 event->preventDefault();
         }
     }
index e33a183..be6a5f1 100644 (file)
@@ -57,7 +57,7 @@ v8::Local<v8::Value> V8WindowErrorHandler::callListenerFunction(ScriptExecutionC
         v8::TryCatch tryCatch;
         tryCatch.SetVerbose(true);
         returnValue = callFunction->Call(thisValue, 3, parameters);
-        if (!tryCatch.HasCaught() && !returnValue.IsEmpty() && returnValue->IsBoolean() && !returnValue->BooleanValue())
+        if (!tryCatch.HasCaught() && !returnValue.IsEmpty() && returnValue->IsBoolean() && returnValue->BooleanValue())
             event->preventDefault();
     }
     return returnValue;
index 5a75a40..3b9a886 100644 (file)
@@ -55,7 +55,7 @@ v8::Local<v8::Value> V8WorkerContextErrorHandler::callListenerFunction(ScriptExe
         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())
+        if (!returnValue.IsEmpty() && returnValue->IsBoolean() && returnValue->BooleanValue())
             event->preventDefault();
     }
     return returnValue;