fast/workers/worker-script-error.html fails on Chromium after r94061
authoryurys@chromium.org <yurys@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Sep 2011 06:53:14 +0000 (06:53 +0000)
committeryurys@chromium.org <yurys@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Sep 2011 06:53:14 +0000 (06:53 +0000)
https://bugs.webkit.org/show_bug.cgi?id=67206

Source/WebCore:

Default action should be prevented if window.onerror returned true and stay
not prevented otherwise.

Reviewed by Dmitry Titov.

Tests: fast/events/window-onerror14.html
       fast/events/window-onerror15.html
       fast/events/window-onerror16.html

* bindings/v8/V8AbstractEventListener.cpp:
(WebCore::V8AbstractEventListener::invokeEventHandler):
(WebCore::V8AbstractEventListener::shouldPreventDefault): allow specific
event listeners to decide when to prevent default action based on the handler
return value.
* bindings/v8/V8AbstractEventListener.h:
* bindings/v8/V8WindowErrorHandler.cpp:
(WebCore::V8WindowErrorHandler::callListenerFunction):
(WebCore::V8WindowErrorHandler::shouldPreventDefault):
* bindings/v8/V8WindowErrorHandler.h:
* bindings/v8/V8WorkerContextErrorHandler.cpp:
(WebCore::V8WorkerContextErrorHandler::callListenerFunction):
(WebCore::V8WorkerContextErrorHandler::shouldPreventDefault):
* bindings/v8/V8WorkerContextErrorHandler.h:

LayoutTests:

Add a couple more tests for window.onerror handler that check whether
error message is printed to the console pending on the handler return
value.

Reviewed by Dmitry Titov.

* fast/events/window-onerror14-expected.txt: Added.
* fast/events/window-onerror14.html: Added.
* fast/events/window-onerror15-expected.txt: Added.
* fast/events/window-onerror15.html: Added.
* fast/events/window-onerror16-expected.txt: Added.
* fast/events/window-onerror16.html: Added.
* platform/chromium/fast/events/window-onerror16-expected.txt: Added.

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

15 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/events/window-onerror14-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/window-onerror14.html [new file with mode: 0644]
LayoutTests/fast/events/window-onerror15-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/window-onerror15.html [new file with mode: 0644]
LayoutTests/fast/events/window-onerror16-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/window-onerror16.html [new file with mode: 0644]
LayoutTests/platform/chromium/fast/events/window-onerror16-expected.txt [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/bindings/v8/V8AbstractEventListener.cpp
Source/WebCore/bindings/v8/V8AbstractEventListener.h
Source/WebCore/bindings/v8/V8WindowErrorHandler.cpp
Source/WebCore/bindings/v8/V8WindowErrorHandler.h
Source/WebCore/bindings/v8/V8WorkerContextErrorHandler.cpp
Source/WebCore/bindings/v8/V8WorkerContextErrorHandler.h

index d1846d0..2d6ed1e 100644 (file)
@@ -1,3 +1,22 @@
+2011-08-31  Yury Semikhatsky  <yurys@chromium.org>
+
+        fast/workers/worker-script-error.html fails on Chromium after r94061
+        https://bugs.webkit.org/show_bug.cgi?id=67206
+
+        Add a couple more tests for window.onerror handler that check whether
+        error message is printed to the console pending on the handler return
+        value.
+
+        Reviewed by Dmitry Titov.
+
+        * fast/events/window-onerror14-expected.txt: Added.
+        * fast/events/window-onerror14.html: Added.
+        * fast/events/window-onerror15-expected.txt: Added.
+        * fast/events/window-onerror15.html: Added.
+        * fast/events/window-onerror16-expected.txt: Added.
+        * fast/events/window-onerror16.html: Added.
+        * platform/chromium/fast/events/window-onerror16-expected.txt: Added.
+
 2011-09-05  Kent Tamura  <tkent@chromium.org>
 
         REGRESSION (Safari 5.1 - ToT): File input retains its file icon when the value is reset
diff --git a/LayoutTests/fast/events/window-onerror14-expected.txt b/LayoutTests/fast/events/window-onerror14-expected.txt
new file mode 100644 (file)
index 0000000..36271f9
--- /dev/null
@@ -0,0 +1,5 @@
+Test that error is treated as handled when window.onerror return value is 'true'. Bug 67119.
+
+Uncaught error should *not* be printed in console when window.onerror returns true.
+window.onerror invoked.
+
diff --git a/LayoutTests/fast/events/window-onerror14.html b/LayoutTests/fast/events/window-onerror14.html
new file mode 100644 (file)
index 0000000..c322099
--- /dev/null
@@ -0,0 +1,28 @@
+<html>
+<head>
+<script src="resources/window-onerror.js">
+</script>
+</head>
+<body>
+<p>Test that error is treated as handled when window.onerror return
+value is '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 *not* be printed in console when window.onerror returns true.");
+  log("window.onerror invoked.");
+  return true;
+}
+
+throw "An Error";
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/events/window-onerror15-expected.txt b/LayoutTests/fast/events/window-onerror15-expected.txt
new file mode 100644 (file)
index 0000000..947de6b
--- /dev/null
@@ -0,0 +1,5 @@
+Test that error is treated as handled when preventDefault is called on the error event.Bug 67119.
+
+Error event listener invoked. Error should *not* be printed in console.
+DONE.
+
diff --git a/LayoutTests/fast/events/window-onerror15.html b/LayoutTests/fast/events/window-onerror15.html
new file mode 100644 (file)
index 0000000..a40a53c
--- /dev/null
@@ -0,0 +1,27 @@
+<html>
+<head>
+<script src="resources/window-onerror.js">
+</script>
+</head>
+<body>
+<p>Test that error is treated as handled when preventDefault is called on the
+error event.<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.addEventListener("error", function(e) {
+  log("Error event listener invoked. Error should *not* be printed in console.");
+  log("DONE.");
+  e.preventDefault();
+}, true);
+
+throw "An Error";
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/events/window-onerror16-expected.txt b/LayoutTests/fast/events/window-onerror16-expected.txt
new file mode 100644 (file)
index 0000000..19327e4
--- /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 'false'. Bug 67119.
+
+window.onerror invoked. Uncaught error should be printed in console
+DONE.
+
diff --git a/LayoutTests/fast/events/window-onerror16.html b/LayoutTests/fast/events/window-onerror16.html
new file mode 100644 (file)
index 0000000..8e36844
--- /dev/null
@@ -0,0 +1,28 @@
+<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 'false'. <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("window.onerror invoked. Uncaught error should be printed in console");
+  log("DONE.");
+  return false;
+}
+
+throw "An Error";
+</script>
+</body>
+</html>
diff --git a/LayoutTests/platform/chromium/fast/events/window-onerror16-expected.txt b/LayoutTests/platform/chromium/fast/events/window-onerror16-expected.txt
new file mode 100644 (file)
index 0000000..c59bfb0
--- /dev/null
@@ -0,0 +1,6 @@
+CONSOLE MESSAGE: line 25: Uncaught An Error
+Test that error is treated as not handled when window.onerror return value is 'false'. Bug 67119.
+
+window.onerror invoked. Uncaught error should be printed in console
+DONE.
+
index eaaff76..e2006f8 100644 (file)
@@ -1,3 +1,32 @@
+2011-08-31  Yury Semikhatsky  <yurys@chromium.org>
+
+        fast/workers/worker-script-error.html fails on Chromium after r94061
+        https://bugs.webkit.org/show_bug.cgi?id=67206
+
+        Default action should be prevented if window.onerror returned true and stay
+        not prevented otherwise.
+
+        Reviewed by Dmitry Titov.
+
+        Tests: fast/events/window-onerror14.html
+               fast/events/window-onerror15.html
+               fast/events/window-onerror16.html
+
+        * bindings/v8/V8AbstractEventListener.cpp:
+        (WebCore::V8AbstractEventListener::invokeEventHandler):
+        (WebCore::V8AbstractEventListener::shouldPreventDefault): allow specific
+        event listeners to decide when to prevent default action based on the handler
+        return value.
+        * bindings/v8/V8AbstractEventListener.h:
+        * bindings/v8/V8WindowErrorHandler.cpp:
+        (WebCore::V8WindowErrorHandler::callListenerFunction):
+        (WebCore::V8WindowErrorHandler::shouldPreventDefault):
+        * bindings/v8/V8WindowErrorHandler.h:
+        * bindings/v8/V8WorkerContextErrorHandler.cpp:
+        (WebCore::V8WorkerContextErrorHandler::callListenerFunction):
+        (WebCore::V8WorkerContextErrorHandler::shouldPreventDefault):
+        * bindings/v8/V8WorkerContextErrorHandler.h:
+
 2011-09-06  Xianzhu Wang  <wangxianzhu@chromium.org>
 
         Replace usages of Vector<UChar> with existing StringBuilder
index 85dbd2e..6e27eeb 100644 (file)
@@ -181,12 +181,17 @@ void V8AbstractEventListener::invokeEventHandler(ScriptExecutionContext* context
     if (!returnValue->IsNull() && !returnValue->IsUndefined() && event->storesResultAsString())
         event->storeResult(toWebCoreString(returnValue));
 
-    // Prevent default action if the return value is false;
-    // FIXME: Add example, and reference to bug entry.
-    if (m_isAttribute && returnValue->IsBoolean() && !returnValue->BooleanValue())
+    if (m_isAttribute && shouldPreventDefault(returnValue))
         event->preventDefault();
 }
 
+bool V8AbstractEventListener::shouldPreventDefault(v8::Local<v8::Value> returnValue)
+{
+    // Prevent default action if the return value is false in accord with the spec
+    // http://www.w3.org/TR/html5/webappapis.html#event-handler-attributes
+    return returnValue->IsBoolean() && !returnValue->BooleanValue();
+}
+
 v8::Local<v8::Object> V8AbstractEventListener::getReceiverObject(Event* event)
 {
     if (!m_listener.IsEmpty() && !m_listener->IsFunction())
index 31cca6d..672ba6d 100644 (file)
@@ -123,6 +123,8 @@ namespace WebCore {
 
         virtual v8::Local<v8::Value> callListenerFunction(ScriptExecutionContext*, v8::Handle<v8::Value> jsevent, Event*) = 0;
 
+        virtual bool shouldPreventDefault(v8::Local<v8::Value> returnValue);
+
         v8::Persistent<v8::Object> m_listener;
 
         // Indicates if this is an HTML type listener.
index be6a5f1..94e8680 100644 (file)
@@ -57,10 +57,13 @@ 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())
-            event->preventDefault();
     }
     return returnValue;
 }
 
+bool V8WindowErrorHandler::shouldPreventDefault(v8::Local<v8::Value> returnValue)
+{
+    return returnValue->IsBoolean() && returnValue->BooleanValue();
+}
+
 } // namespace WebCore
index 493a9bf..9ba4e9e 100644 (file)
@@ -48,6 +48,7 @@ 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*);
+    virtual bool shouldPreventDefault(v8::Local<v8::Value> returnValue);
 };
 
 } // namespace WebCore
index 3b9a886..0a5c99d 100644 (file)
@@ -55,12 +55,15 @@ 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())
-            event->preventDefault();
     }
     return returnValue;
 }
 
+bool V8WorkerContextErrorHandler::shouldPreventDefault(v8::Local<v8::Value> returnValue)
+{
+    return returnValue->IsBoolean() && returnValue->BooleanValue();
+}
+
 } // namespace WebCore
 
 #endif // WORKERS
index cd1e0e6..8896bb5 100644 (file)
@@ -50,6 +50,7 @@ private:
     V8WorkerContextErrorHandler(v8::Local<v8::Object> listener, bool isInline, const WorldContextHandle& worldContext);
 
     virtual v8::Local<v8::Value> callListenerFunction(ScriptExecutionContext*, v8::Handle<v8::Value> jsEvent, Event*);
+    virtual bool shouldPreventDefault(v8::Local<v8::Value> returnValue);
 };
 
 } // namespace WebCore