Title: [253123] trunk
Revision
253123
Author
[email protected]
Date
2019-12-04 14:24:24 -0800 (Wed, 04 Dec 2019)

Log Message

Non-callable "handleEvent" property is silently ignored
https://bugs.webkit.org/show_bug.cgi?id=200066

Patch by Alexey Shvayka <[email protected]> on 2019-12-04
Reviewed by Ryosuke Niwa.

LayoutTests/imported/w3c:

* web-platform-tests/IndexedDB/fire-error-event-exception-expected.txt:
* web-platform-tests/IndexedDB/fire-success-event-exception-expected.txt:
* web-platform-tests/IndexedDB/fire-upgradeneeded-event-exception-expected.txt:
* web-platform-tests/dom/events/EventListener-handleEvent-expected.txt:
* web-platform-tests/html/webappapis/scripting/events/event-handler-handleEvent-ignored-expected.txt:
* web-platform-tests/websockets/interfaces/WebSocket/events/013-expected.txt:
* web-platform-tests/workers/interfaces/DedicatedWorkerGlobalScope/onmessage.worker-expected.txt:

Source/WebCore:

This patch prevents "handleEvent" property from being looked up on event handlers
and also reports TypeError exception if "handleEvent" value is not callable.
Web IDL spec: https://heycam.github.io/webidl/#call-a-user-objects-operation (step 10.4)

Tests: fast/dom/exception-getting-event-handler.html
       imported/w3c/web-platform-tests/IndexedDB/fire-error-event-exception.html
       imported/w3c/web-platform-tests/IndexedDB/fire-success-event-exception.html
       imported/w3c/web-platform-tests/IndexedDB/fire-upgradeneeded-event-exception.html
       imported/w3c/web-platform-tests/dom/events/EventListener-handleEvent.html
       imported/w3c/web-platform-tests/html/webappapis/scripting/events/event-handler-handleEvent-ignored.html
       imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/events/013.html
       imported/w3c/web-platform-tests/workers/interfaces/DedicatedWorkerGlobalScope/onmessage.worker.html

* bindings/js/JSEventListener.cpp:
(WebCore::JSEventListener::handleEvent):

LayoutTests:

* fast/dom/exception-getting-event-handler-expected.txt:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (253122 => 253123)


--- trunk/LayoutTests/ChangeLog	2019-12-04 22:19:27 UTC (rev 253122)
+++ trunk/LayoutTests/ChangeLog	2019-12-04 22:24:24 UTC (rev 253123)
@@ -1,3 +1,12 @@
+2019-12-04  Alexey Shvayka  <[email protected]>
+
+        Non-callable "handleEvent" property is silently ignored
+        https://bugs.webkit.org/show_bug.cgi?id=200066
+
+        Reviewed by Ryosuke Niwa.
+
+        * fast/dom/exception-getting-event-handler-expected.txt:
+
 2019-12-04  Wenson Hsieh  <[email protected]>
 
         Adopt UIHelper in a few more layout tests in fast/events

Modified: trunk/LayoutTests/fast/dom/exception-getting-event-handler-expected.txt (253122 => 253123)


--- trunk/LayoutTests/fast/dom/exception-getting-event-handler-expected.txt	2019-12-04 22:19:27 UTC (rev 253122)
+++ trunk/LayoutTests/fast/dom/exception-getting-event-handler-expected.txt	2019-12-04 22:24:24 UTC (rev 253123)
@@ -1,4 +1,3 @@
-CONSOLE MESSAGE: line 12: 42
 This test checks that an exception thrown when getting the handleEvent property of an event listener does not crash.
 
 PASS: You didn't crash.

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (253122 => 253123)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2019-12-04 22:19:27 UTC (rev 253122)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2019-12-04 22:24:24 UTC (rev 253123)
@@ -1,3 +1,18 @@
+2019-12-04  Alexey Shvayka  <[email protected]>
+
+        Non-callable "handleEvent" property is silently ignored
+        https://bugs.webkit.org/show_bug.cgi?id=200066
+
+        Reviewed by Ryosuke Niwa.
+
+        * web-platform-tests/IndexedDB/fire-error-event-exception-expected.txt:
+        * web-platform-tests/IndexedDB/fire-success-event-exception-expected.txt:
+        * web-platform-tests/IndexedDB/fire-upgradeneeded-event-exception-expected.txt:
+        * web-platform-tests/dom/events/EventListener-handleEvent-expected.txt:
+        * web-platform-tests/html/webappapis/scripting/events/event-handler-handleEvent-ignored-expected.txt:
+        * web-platform-tests/websockets/interfaces/WebSocket/events/013-expected.txt:
+        * web-platform-tests/workers/interfaces/DedicatedWorkerGlobalScope/onmessage.worker-expected.txt:
+
 2019-12-04  Simon Fraser  <[email protected]>
 
         Implement the CSS clamp() function

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/IndexedDB/fire-error-event-exception-expected.txt (253122 => 253123)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/IndexedDB/fire-error-event-exception-expected.txt	2019-12-04 22:19:27 UTC (rev 253122)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/IndexedDB/fire-error-event-exception-expected.txt	2019-12-04 22:24:24 UTC (rev 253123)
@@ -3,7 +3,7 @@
 PASS Exception in error event handler on request, with preventDefault 
 PASS Exception in error event listener on request 
 PASS Exception in error event listener ("handleEvent" lookup) on request 
-FAIL Exception in error event listener (non-callable "handleEvent") on request assert_equals: expected "AbortError" but got "ConstraintError"
+PASS Exception in error event listener (non-callable "handleEvent") on request 
 PASS Exception in second error event listener on request 
 PASS Exception in first error event listener on request, transaction active in second 
 PASS Exception in error event handler on transaction 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/IndexedDB/fire-success-event-exception-expected.txt (253122 => 253123)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/IndexedDB/fire-success-event-exception-expected.txt	2019-12-04 22:19:27 UTC (rev 253122)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/IndexedDB/fire-success-event-exception-expected.txt	2019-12-04 22:24:24 UTC (rev 253123)
@@ -2,7 +2,7 @@
 PASS Exception in success event handler on request 
 PASS Exception in success event listener on request 
 PASS Exception in success event listener ("handleEvent" lookup) on request 
-FAIL Exception in success event listener (non-callable "handleEvent") on request assert_unreached: transaction should abort Reached unreachable code
+PASS Exception in success event listener (non-callable "handleEvent") on request 
 PASS Exception in second success event listener on request 
 PASS Exception in first success event listener, tx active in second 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/IndexedDB/fire-upgradeneeded-event-exception-expected.txt (253122 => 253123)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/IndexedDB/fire-upgradeneeded-event-exception-expected.txt	2019-12-04 22:19:27 UTC (rev 253122)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/IndexedDB/fire-upgradeneeded-event-exception-expected.txt	2019-12-04 22:24:24 UTC (rev 253123)
@@ -1,6 +1,7 @@
 CONSOLE MESSAGE: line 31: Error
 CONSOLE MESSAGE: line 37: Error
 CONSOLE MESSAGE: line 44: Error
+CONSOLE MESSAGE: TypeError: 'handleEvent' property of event listener should be callable
 CONSOLE MESSAGE: line 62: Error
 CONSOLE MESSAGE: line 70: Error
 
@@ -7,7 +8,7 @@
 PASS Exception in upgradeneeded handler 
 PASS Exception in upgradeneeded listener 
 PASS Exception in upgradeneeded "handleEvent" lookup 
-FAIL Exception in upgradeneeded due to non-callable "handleEvent" assert_unreached: open should fail Reached unreachable code
+PASS Exception in upgradeneeded due to non-callable "handleEvent" 
 PASS Exception in second upgradeneeded listener 
 PASS Exception in first upgradeneeded listener, tx active in second 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/EventListener-handleEvent-expected.txt (253122 => 253123)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/EventListener-handleEvent-expected.txt	2019-12-04 22:19:27 UTC (rev 253122)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/EventListener-handleEvent-expected.txt	2019-12-04 22:24:24 UTC (rev 253123)
@@ -1,9 +1,11 @@
 CONSOLE MESSAGE: line 46: [object Object]
+CONSOLE MESSAGE: line 101: TypeError: 'handleEvent' property of event listener should be callable
+CONSOLE MESSAGE: line 122: TypeError: 'handleEvent' property of event listener should be callable
 
 PASS calls `handleEvent` method of `EventListener` 
 PASS rethrows errors when getting `handleEvent` 
 PASS performs `Get` every time event is dispatched 
 PASS doesn't call `handleEvent` method on callable `EventListener` 
-FAIL throws if `handleEvent` is falsy and not callable assert_true: expected true got false
-FAIL throws if `handleEvent` is thruthy and not callable assert_true: expected true got false
+PASS throws if `handleEvent` is falsy and not callable 
+PASS throws if `handleEvent` is thruthy and not callable 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/webappapis/scripting/events/event-handler-handleEvent-ignored-expected.txt (253122 => 253123)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/webappapis/scripting/events/event-handler-handleEvent-ignored-expected.txt	2019-12-04 22:19:27 UTC (rev 253122)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/webappapis/scripting/events/event-handler-handleEvent-ignored-expected.txt	2019-12-04 22:24:24 UTC (rev 253123)
@@ -1,4 +1,4 @@
 
-FAIL plain object "mouseenter" handler assert_unreached: "handleEvent" property should not be looked up Reached unreachable code
-FAIL non-callable "message" handler that is instance of Function assert_unreached: "handleEvent" property should not be looked up Reached unreachable code
+PASS plain object "mouseenter" handler 
+PASS non-callable "message" handler that is instance of Function 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/events/013-expected.txt (253122 => 253123)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/events/013-expected.txt	2019-12-04 22:19:27 UTC (rev 253122)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/events/013-expected.txt	2019-12-04 22:24:24 UTC (rev 253123)
@@ -1,6 +1,6 @@
 
-FAIL onclose assert_unreached: handleEvent was called Reached unreachable code
-FAIL onopen assert_unreached: handleEvent was called Reached unreachable code
-FAIL onerror assert_unreached: handleEvent was called Reached unreachable code
-FAIL onmessage assert_unreached: handleEvent was called Reached unreachable code
+PASS onclose 
+PASS onopen 
+PASS onerror 
+PASS onmessage 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/workers/interfaces/DedicatedWorkerGlobalScope/onmessage.worker-expected.txt (253122 => 253123)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/workers/interfaces/DedicatedWorkerGlobalScope/onmessage.worker-expected.txt	2019-12-04 22:19:27 UTC (rev 253122)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/workers/interfaces/DedicatedWorkerGlobalScope/onmessage.worker-expected.txt	2019-12-04 22:24:24 UTC (rev 253123)
@@ -1,6 +1,6 @@
 
 PASS Setting onmessage to 1 
-FAIL Setting onmessage to an object assert_unreached: Reached unreachable code
+PASS Setting onmessage to an object 
 PASS Setting onmessage to a function 
 PASS Setting onmessage to 1 (again) 
 

Modified: trunk/Source/WebCore/ChangeLog (253122 => 253123)


--- trunk/Source/WebCore/ChangeLog	2019-12-04 22:19:27 UTC (rev 253122)
+++ trunk/Source/WebCore/ChangeLog	2019-12-04 22:24:24 UTC (rev 253123)
@@ -1,3 +1,26 @@
+2019-12-04  Alexey Shvayka  <[email protected]>
+
+        Non-callable "handleEvent" property is silently ignored
+        https://bugs.webkit.org/show_bug.cgi?id=200066
+
+        Reviewed by Ryosuke Niwa.
+
+        This patch prevents "handleEvent" property from being looked up on event handlers
+        and also reports TypeError exception if "handleEvent" value is not callable.
+        Web IDL spec: https://heycam.github.io/webidl/#call-a-user-objects-operation (step 10.4)
+
+        Tests: fast/dom/exception-getting-event-handler.html
+               imported/w3c/web-platform-tests/IndexedDB/fire-error-event-exception.html
+               imported/w3c/web-platform-tests/IndexedDB/fire-success-event-exception.html
+               imported/w3c/web-platform-tests/IndexedDB/fire-upgradeneeded-event-exception.html
+               imported/w3c/web-platform-tests/dom/events/EventListener-handleEvent.html
+               imported/w3c/web-platform-tests/html/webappapis/scripting/events/event-handler-handleEvent-ignored.html
+               imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/events/013.html
+               imported/w3c/web-platform-tests/workers/interfaces/DedicatedWorkerGlobalScope/onmessage.worker.html
+
+        * bindings/js/JSEventListener.cpp:
+        (WebCore::JSEventListener::handleEvent):
+
 2019-12-04  Kate Cheney  <[email protected]>
 
         Expose basic ITP data from the database for future API/SPI use

Modified: trunk/Source/WebCore/bindings/js/JSEventListener.cpp (253122 => 253123)


--- trunk/Source/WebCore/bindings/js/JSEventListener.cpp	2019-12-04 22:19:27 UTC (rev 253122)
+++ trunk/Source/WebCore/bindings/js/JSEventListener.cpp	2019-12-04 22:24:24 UTC (rev 253123)
@@ -137,8 +137,11 @@
     CallData callData;
     CallType callType = getCallData(vm, handleEventFunction, callData);
 
-    // If jsFunction is not actually a function, see if it implements the EventListener interface and use that
+    // If jsFunction is not actually a function and this is an EventListener, see if it implements callback interface.
     if (callType == CallType::None) {
+        if (m_isAttribute)
+            return;
+
         handleEventFunction = jsFunction->get(lexicalGlobalObject, Identifier::fromString(vm, "handleEvent"));
         if (UNLIKELY(scope.exception())) {
             auto* exception = scope.exception();
@@ -148,11 +151,13 @@
             return;
         }
         callType = getCallData(vm, handleEventFunction, callData);
+        if (callType == CallType::None) {
+            event.target()->uncaughtExceptionInEventHandler();
+            reportException(lexicalGlobalObject, createTypeError(lexicalGlobalObject, "'handleEvent' property of event listener should be callable"_s));
+            return;
+        }
     }
 
-    if (callType == CallType::None)
-        return;
-
     Ref<JSEventListener> protectedThis(*this);
 
     MarkedArgumentBuffer args;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to