Implement PostMessageOptions for postMessage
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Dec 2019 21:36:25 +0000 (21:36 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Dec 2019 21:36:25 +0000 (21:36 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191028

Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

Rebaseline WPT tests now that we have more passes.

* web-platform-tests/html/browsers/origin/cross-origin-objects/cross-origin-objects-expected.txt:
* web-platform-tests/html/browsers/windows/document-access/document_access_parent_access.tentative-expected.txt:
* web-platform-tests/service-workers/service-worker/clients-matchall-frozen.https-expected.txt:
* web-platform-tests/service-workers/service-worker/postmessage.https-expected.txt:
* web-platform-tests/webmessaging/message-channels/dictionary-transferrable-expected.txt:
* web-platform-tests/webmessaging/message-channels/user-activation.tentative-expected.txt:
* web-platform-tests/webmessaging/postMessage_MessagePorts_xsite.sub.window-expected.txt:
* web-platform-tests/webmessaging/with-options/host-specific-origin-expected.txt:
* web-platform-tests/webmessaging/with-options/message-channel-transferable-expected.txt:
* web-platform-tests/webmessaging/with-options/no-target-origin-expected.txt:
* web-platform-tests/webmessaging/with-options/null-transfer-expected.txt:
* web-platform-tests/webmessaging/with-options/one-arg-expected.txt:
* web-platform-tests/webmessaging/with-options/slash-origin-expected.txt:
* web-platform-tests/webmessaging/with-options/undefined-transferable-expected.txt:
* web-platform-tests/webmessaging/with-options/unknown-parameter-expected.txt:
* web-platform-tests/webmessaging/without-ports/008-expected.txt:
* web-platform-tests/webmessaging/worker_postMessage_user_activation.tentative-expected.txt:
* web-platform-tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-dictionary-expected.txt:
* web-platform-tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-null-expected.txt:

Source/WebCore:

Implement PostMessageOptions dictionary parameter for postMessage:
- https://github.com/whatwg/html/issues/3799
- https://github.com/w3c/ServiceWorker/pull/1344

Blink and Gecko already support this.

No new tests, rebaselined existing tests.

* CMakeLists.txt:
* DerivedSources-input.xcfilelist:
* DerivedSources-output.xcfilelist:
* DerivedSources.make:
* Headers.cmake:
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* dom/MessagePort.cpp:
(WebCore::MessagePort::postMessage):
* dom/MessagePort.h:
* dom/MessagePort.idl:
* page/DOMWindow.cpp:
(WebCore::DOMWindow::postMessage):
* page/DOMWindow.h:
(WebCore::WindowPostMessageOptions::WindowPostMessageOptions):
* page/DOMWindow.idl:
* page/PostMessageOptions.h: Copied from Source/WebCore/workers/service/ServiceWorkerClient.idl.
(WebCore::PostMessageOptions::PostMessageOptions):
* page/PostMessageOptions.idl: Copied from Source/WebCore/workers/service/ServiceWorkerClient.idl.
* workers/DedicatedWorkerGlobalScope.cpp:
(WebCore::DedicatedWorkerGlobalScope::postMessage):
* workers/DedicatedWorkerGlobalScope.h:
* workers/DedicatedWorkerGlobalScope.idl:
* workers/Worker.cpp:
(WebCore::Worker::postMessage):
* workers/Worker.h:
* workers/Worker.idl:
* workers/service/ServiceWorker.cpp:
(WebCore::ServiceWorker::postMessage):
* workers/service/ServiceWorker.h:
* workers/service/ServiceWorker.idl:
* workers/service/ServiceWorkerClient.cpp:
(WebCore::ServiceWorkerClient::postMessage):
* workers/service/ServiceWorkerClient.h:
* workers/service/ServiceWorkerClient.idl:

LayoutTests:

Update a few existing tests due to the behavior change.

* TestExpectations:
* fast/dom/Window/post-message-crash.html:
* fast/events/message-port-multi-expected.txt:
* fast/events/resources/message-port-multi.js:
* fast/workers/resources/worker-context-thread-multi-port.js:
* fast/workers/resources/worker-multi-port.js:
* fast/workers/worker-multi-port-expected.txt:
* http/tests/security/postMessage/target-origin-expected.txt:
* platform/mac-wk1/imported/w3c/web-platform-tests/html/dom/idlharness.https-expected.txt:
* platform/mac-wk2/imported/w3c/web-platform-tests/html/dom/idlharness.https-expected.txt:

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

61 files changed:
LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/fast/dom/Window/post-message-crash.html
LayoutTests/fast/events/message-port-multi-expected.txt
LayoutTests/fast/events/resources/message-port-multi.js
LayoutTests/fast/workers/resources/worker-context-thread-multi-port.js
LayoutTests/fast/workers/resources/worker-multi-port.js
LayoutTests/fast/workers/worker-multi-port-expected.txt
LayoutTests/http/tests/security/postMessage/target-origin-expected.txt
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/html/browsers/origin/cross-origin-objects/cross-origin-objects-expected.txt
LayoutTests/imported/w3c/web-platform-tests/html/browsers/windows/document-access/document_access_parent_access.tentative-expected.txt
LayoutTests/imported/w3c/web-platform-tests/html/dom/idlharness.https-expected.txt
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/clients-matchall-frozen.https-expected.txt
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/postmessage.https-expected.txt
LayoutTests/imported/w3c/web-platform-tests/webmessaging/message-channels/dictionary-transferrable-expected.txt
LayoutTests/imported/w3c/web-platform-tests/webmessaging/message-channels/user-activation.tentative-expected.txt
LayoutTests/imported/w3c/web-platform-tests/webmessaging/postMessage_MessagePorts_xsite.sub.window-expected.txt
LayoutTests/imported/w3c/web-platform-tests/webmessaging/with-options/host-specific-origin-expected.txt
LayoutTests/imported/w3c/web-platform-tests/webmessaging/with-options/message-channel-transferable-expected.txt
LayoutTests/imported/w3c/web-platform-tests/webmessaging/with-options/no-target-origin-expected.txt
LayoutTests/imported/w3c/web-platform-tests/webmessaging/with-options/null-transfer-expected.txt
LayoutTests/imported/w3c/web-platform-tests/webmessaging/with-options/one-arg-expected.txt
LayoutTests/imported/w3c/web-platform-tests/webmessaging/with-options/slash-origin-expected.txt
LayoutTests/imported/w3c/web-platform-tests/webmessaging/with-options/undefined-transferable-expected.txt
LayoutTests/imported/w3c/web-platform-tests/webmessaging/with-options/unknown-parameter-expected.txt
LayoutTests/imported/w3c/web-platform-tests/webmessaging/without-ports/008-expected.txt
LayoutTests/imported/w3c/web-platform-tests/webmessaging/worker_postMessage_user_activation.tentative-expected.txt
LayoutTests/imported/w3c/web-platform-tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-dictionary-expected.txt
LayoutTests/imported/w3c/web-platform-tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-null-expected.txt
LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/html/dom/idlharness.https-expected.txt
LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/html/dom/idlharness.https-expected.txt
LayoutTests/platform/mac-wk2/imported/w3c/web-platform-tests/html/dom/idlharness.https-expected.txt
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/DerivedSources-input.xcfilelist
Source/WebCore/DerivedSources-output.xcfilelist
Source/WebCore/DerivedSources.make
Source/WebCore/Headers.cmake
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/dom/MessagePort.cpp
Source/WebCore/dom/MessagePort.h
Source/WebCore/dom/MessagePort.idl
Source/WebCore/page/DOMWindow.cpp
Source/WebCore/page/DOMWindow.h
Source/WebCore/page/DOMWindow.idl
Source/WebCore/page/PostMessageOptions.h [new file with mode: 0644]
Source/WebCore/page/PostMessageOptions.idl [new file with mode: 0644]
Source/WebCore/workers/DedicatedWorkerGlobalScope.cpp
Source/WebCore/workers/DedicatedWorkerGlobalScope.h
Source/WebCore/workers/DedicatedWorkerGlobalScope.idl
Source/WebCore/workers/Worker.cpp
Source/WebCore/workers/Worker.h
Source/WebCore/workers/Worker.idl
Source/WebCore/workers/service/ServiceWorker.cpp
Source/WebCore/workers/service/ServiceWorker.h
Source/WebCore/workers/service/ServiceWorker.idl
Source/WebCore/workers/service/ServiceWorkerClient.cpp
Source/WebCore/workers/service/ServiceWorkerClient.h
Source/WebCore/workers/service/ServiceWorkerClient.idl

index ec84d76..7c0c7ce 100644 (file)
@@ -1,3 +1,23 @@
+2019-12-13  Chris Dumez  <cdumez@apple.com>
+
+        Implement PostMessageOptions for postMessage
+        https://bugs.webkit.org/show_bug.cgi?id=191028
+
+        Reviewed by Alex Christensen.
+
+        Update a few existing tests due to the behavior change.
+
+        * TestExpectations:
+        * fast/dom/Window/post-message-crash.html:
+        * fast/events/message-port-multi-expected.txt:
+        * fast/events/resources/message-port-multi.js:
+        * fast/workers/resources/worker-context-thread-multi-port.js:
+        * fast/workers/resources/worker-multi-port.js:
+        * fast/workers/worker-multi-port-expected.txt:
+        * http/tests/security/postMessage/target-origin-expected.txt:
+        * platform/mac-wk1/imported/w3c/web-platform-tests/html/dom/idlharness.https-expected.txt:
+        * platform/mac-wk2/imported/w3c/web-platform-tests/html/dom/idlharness.https-expected.txt:
+
 2019-12-13  Charlie Turner  <cturner@igalia.com>
 
         [GStreamer][EME] Update expectation for media/encrypted-media/clearKey/clearKey-cenc-video-playback-mse.html
index 7e1da39..62ba4b5 100644 (file)
@@ -210,6 +210,9 @@ imported/w3c/web-platform-tests/secure-contexts/shared-worker-secure-first.https
 # Per specification, if the scripts are identical, we do not install the new script and return the existing registration.
 imported/w3c/web-platform-tests/service-workers/service-worker/import-scripts-redirect.https.html [ Skip ]
 
+# This test is timing out in all browsers.
+imported/w3c/web-platform-tests/service-workers/service-worker/clients-matchall-frozen.https.html [ Skip ]
+
 imported/w3c/web-platform-tests/referrer-policy [ Skip ]
 
 # Newly imported service worker tests that are timing out.
index ec2247b..85300a3 100644 (file)
@@ -14,15 +14,24 @@ if (window.testRunner) {
 
 var n = 0;
 
-window.onerror = function() {
+function finishIfNeeded()
+{
     if (++n === 2) {
         document.querySelector('pre').textContent = 'PASS';
         if (window.testRunner)
             testRunner.notifyDone();
     }
+}
+
+window.onerror = function() {
+    finishIfNeeded();
     return true;
 };
 
+onmessage = () => {
+    finishIfNeeded();
+}
+
 requestAnimationFrame(postMessage);
 setTimeout(postMessage);
 
index 872c5a9..3521aac 100644 (file)
@@ -8,7 +8,7 @@ PASS channel.port1.postMessage("entangled port", [channel.port2]) threw exceptio
 PASS channel.port1.postMessage("null port", [channel3.port1, null, channel3.port2]) threw exception TypeError: Type error.
 PASS channel.port1.postMessage("notAPort", [channel3.port1, {}, channel3.port2]) threw exception DataCloneError: The object can not be cloned..
 PASS channel.port1.postMessage("duplicate port", [channel3.port1, channel3.port1]) threw exception DataCloneError: The object can not be cloned..
-PASS channel.port1.postMessage("notAnArray", channel3.port1) threw exception TypeError: Type error.
+PASS channel.port1.postMessage("notAnArray", "foo") threw exception TypeError: Type error.
 PASS channel.port1.postMessage("notASequence", [{length: 3}]) threw exception DataCloneError: The object can not be cloned..
 PASS channel.port1.postMessage("largeSequence", largePortArray) threw exception TypeError: Type error.
 PASS event.ports is non-null and zero length when no port sent
index 0b0a69c..6b5a926 100644 (file)
@@ -23,7 +23,7 @@ shouldThrow('channel.port1.postMessage("duplicate port", [channel3.port1, channe
 // Should be OK to send channel3.port1 (should not have been disentangled by the previous failed calls).
 channel.port1.postMessage("entangled ports", [channel3.port1, channel3.port2]);
 
-shouldThrow('channel.port1.postMessage("notAnArray", channel3.port1)')
+shouldThrow('channel.port1.postMessage("notAnArray", "foo")')
 shouldThrow('channel.port1.postMessage("notASequence", [{length: 3}])');
 
 // Should not crash (we should figure out that the array contains undefined
index 28eef67..89f325d 100644 (file)
@@ -28,7 +28,7 @@ try {
 }
 
 try {
-    postMessage("notAnArray", channel3.port1);
+    postMessage("notAnArray", "foo");
     testFailed("posting a non-array should throw");
 } catch (e) {
     testPassed("posting a non-array did throw: " + e);
index 2018f97..eb25562 100644 (file)
@@ -21,7 +21,7 @@ shouldThrow('worker.postMessage("notAPort", [channel3.port1, {}, channel3.port2]
 // Should be OK to send channel3.port1/2 (should not have been disentangled by the previous failed calls).
 worker.postMessage("failed ports", [channel3.port1, channel3.port2]);
 
-shouldThrow('worker.postMessage("notAnArray", channel3.port1)')
+shouldThrow('worker.postMessage("notAnArray", "foo")')
 shouldThrow('worker.postMessage("notASequence", [{length: 3}])');
 
 worker.postMessage("done", [channel.port2]);
index d2b2f45..9209a22 100644 (file)
@@ -5,7 +5,7 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
 
 PASS worker.postMessage("null port", [channel3.port1, null, channel3.port2]) threw exception TypeError: Type error.
 PASS worker.postMessage("notAPort", [channel3.port1, {}, channel3.port2]) threw exception DataCloneError: The object can not be cloned..
-PASS worker.postMessage("notAnArray", channel3.port1) threw exception TypeError: Type error.
+PASS worker.postMessage("notAnArray", "foo") threw exception TypeError: Type error.
 PASS worker.postMessage("notASequence", [{length: 3}]) threw exception DataCloneError: The object can not be cloned..
 PASS event.ports is non-null and zero length when no port sent
 PASS event.ports is non-null and zero length when empty array sent
index 17c14cd..23b819d 100644 (file)
@@ -10,11 +10,13 @@ CONSOLE MESSAGE: Unable to post message to https://localhost:8000. Recipient has
 
 CONSOLE MESSAGE: Unable to post message to http://www.example.com. Recipient has origin http://localhost:8000.
 
+CONSOLE MESSAGE: Unable to post message to http://127.0.0.1:8000. Recipient has origin http://localhost:8000.
+
+CONSOLE MESSAGE: Unable to post message to http://127.0.0.1:8000. Recipient has origin http://localhost:8000.
+
 window.location.href = http://127.0.0.1:8000/security/postMessage/target-origin.html
 
 waiting...
-Error sending message to null. SyntaxError: The string did not match the expected pattern.
-Error sending message to undefined. SyntaxError: The string did not match the expected pattern.
 Error sending message to //. SyntaxError: The string did not match the expected pattern.
 Received message: data="Received message: data="Trying origin=http://localhost:8000" origin="http://127.0.0.1:8000"" origin="http://localhost:8000"
 Received message: data="Received message: data="Trying origin=http://localhost:8000/" origin="http://127.0.0.1:8000"" origin="http://localhost:8000"
index 5ca6b09..ff86a69 100644 (file)
@@ -1,5 +1,34 @@
 2019-12-13  Chris Dumez  <cdumez@apple.com>
 
+        Implement PostMessageOptions for postMessage
+        https://bugs.webkit.org/show_bug.cgi?id=191028
+
+        Reviewed by Alex Christensen.
+
+        Rebaseline WPT tests now that we have more passes.
+
+        * web-platform-tests/html/browsers/origin/cross-origin-objects/cross-origin-objects-expected.txt:
+        * web-platform-tests/html/browsers/windows/document-access/document_access_parent_access.tentative-expected.txt:
+        * web-platform-tests/service-workers/service-worker/clients-matchall-frozen.https-expected.txt:
+        * web-platform-tests/service-workers/service-worker/postmessage.https-expected.txt:
+        * web-platform-tests/webmessaging/message-channels/dictionary-transferrable-expected.txt:
+        * web-platform-tests/webmessaging/message-channels/user-activation.tentative-expected.txt:
+        * web-platform-tests/webmessaging/postMessage_MessagePorts_xsite.sub.window-expected.txt:
+        * web-platform-tests/webmessaging/with-options/host-specific-origin-expected.txt:
+        * web-platform-tests/webmessaging/with-options/message-channel-transferable-expected.txt:
+        * web-platform-tests/webmessaging/with-options/no-target-origin-expected.txt:
+        * web-platform-tests/webmessaging/with-options/null-transfer-expected.txt:
+        * web-platform-tests/webmessaging/with-options/one-arg-expected.txt:
+        * web-platform-tests/webmessaging/with-options/slash-origin-expected.txt:
+        * web-platform-tests/webmessaging/with-options/undefined-transferable-expected.txt:
+        * web-platform-tests/webmessaging/with-options/unknown-parameter-expected.txt:
+        * web-platform-tests/webmessaging/without-ports/008-expected.txt:
+        * web-platform-tests/webmessaging/worker_postMessage_user_activation.tentative-expected.txt:
+        * web-platform-tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-dictionary-expected.txt:
+        * web-platform-tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-null-expected.txt:
+
+2019-12-13  Chris Dumez  <cdumez@apple.com>
+
         REGRESSION: (r251677) imported/w3c/web-platform-tests/html/semantics/forms/form-submission-0/form-double-submit-3.html is a flaky failure
         https://bugs.webkit.org/show_bug.cgi?id=205164
         <rdar://problem/57879042>
index edc1ae7..da113c8 100644 (file)
@@ -3,14 +3,20 @@ CONSOLE MESSAGE: line 287: Blocked a frame with origin "http://localhost:8800" f
 CONSOLE MESSAGE: line 302: Blocked a frame with origin "http://localhost:8800" from accessing a frame with origin "http://127.0.0.1:8800". Protocols, domains, and ports must match.
 CONSOLE MESSAGE: line 287: Blocked a frame with origin "http://localhost:8800" from accessing a frame with origin "http://localhost:8800". The frame being accessed set "document.domain" to "localhost", but the frame requesting access did not. Both must set "document.domain" to the same value to allow access.
 CONSOLE MESSAGE: line 302: Blocked a frame with origin "http://localhost:8800" from accessing a frame with origin "http://localhost:8800". The frame being accessed set "document.domain" to "localhost", but the frame requesting access did not. Both must set "document.domain" to the same value to allow access.
+CONSOLE MESSAGE: line 302: Blocked a frame with origin "http://localhost:8800" from accessing a frame with origin "http://localhost:8800". The frame being accessed set "document.domain" to "localhost", but the frame requesting access did not. Both must set "document.domain" to the same value to allow access.
 CONSOLE MESSAGE: line 287: Blocked a frame with origin "http://localhost:8800" from accessing a frame with origin "http://127.0.0.1:8800". Protocols, domains, and ports must match.
 CONSOLE MESSAGE: line 302: Blocked a frame with origin "http://localhost:8800" from accessing a frame with origin "http://127.0.0.1:8800". Protocols, domains, and ports must match.
+CONSOLE MESSAGE: line 302: Blocked a frame with origin "http://localhost:8800" from accessing a frame with origin "http://127.0.0.1:8800". Protocols, domains, and ports must match.
 CONSOLE MESSAGE: Unable to post message to http://does-not.exist. Recipient has origin http://127.0.0.1:8800.
 
+CONSOLE MESSAGE: Unable to post message to http://localhost:8800. Recipient has origin http://127.0.0.1:8800.
+
 CONSOLE MESSAGE: Unable to post message to http://does-not.exist. Recipient has origin http://localhost:8800.
 
 CONSOLE MESSAGE: Unable to post message to http://does-not.exist. Recipient has origin http://127.0.0.1:8800.
 
+CONSOLE MESSAGE: Unable to post message to http://localhost:8800. Recipient has origin http://127.0.0.1:8800.
+
 
 PASS Basic sanity-checking (cross-origin) 
 PASS Basic sanity-checking (same-origin + document.domain) 
@@ -18,9 +24,9 @@ PASS Basic sanity-checking (cross-site)
 PASS Only whitelisted properties are accessible cross-origin (cross-origin) 
 PASS Only whitelisted properties are accessible cross-origin (same-origin + document.domain) 
 PASS Only whitelisted properties are accessible cross-origin (cross-site) 
-FAIL Only whitelisted properties are usable as cross-origin this objects (cross-origin) promise_test: Unhandled rejection with value: object "SyntaxError: The string did not match the expected pattern."
-FAIL Only whitelisted properties are usable as cross-origin this objects (same-origin + document.domain) promise_test: Unhandled rejection with value: object "SyntaxError: The string did not match the expected pattern."
-FAIL Only whitelisted properties are usable as cross-origin this objects (cross-site) promise_test: Unhandled rejection with value: object "SyntaxError: The string did not match the expected pattern."
+PASS Only whitelisted properties are usable as cross-origin this objects (cross-origin) 
+PASS Only whitelisted properties are usable as cross-origin this objects (same-origin + document.domain) 
+PASS Only whitelisted properties are usable as cross-origin this objects (cross-site) 
 PASS [[GetPrototypeOf]] should return null (cross-origin) 
 PASS [[GetPrototypeOf]] should return null (same-origin + document.domain) 
 PASS [[GetPrototypeOf]] should return null (cross-site) 
index 8fe6247..491f112 100644 (file)
@@ -4180,8 +4180,8 @@ PASS Window interface: operation alert(DOMString)
 PASS Window interface: operation confirm(DOMString) 
 PASS Window interface: operation prompt(DOMString, DOMString) 
 PASS Window interface: operation print() 
-FAIL Window interface: operation postMessage(any, USVString, [object Object]) assert_equals: property has wrong .length expected 1 but got 2
-FAIL Window interface: operation postMessage(any, WindowPostMessageOptions) assert_equals: property has wrong .length expected 1 but got 2
+PASS Window interface: operation postMessage(any, USVString, [object Object]) 
+PASS Window interface: operation postMessage(any, WindowPostMessageOptions) 
 PASS Window interface: operation captureEvents() 
 PASS Window interface: operation releaseEvents() 
 FAIL Window interface: attribute external assert_own_property: The global object must have a property "external" expected property "external" missing
index 5bd359b..0bd2d56 100644 (file)
@@ -2,6 +2,6 @@
 PASS postMessage to a ServiceWorker (and back via MessagePort) 
 PASS postMessage a transferable ArrayBuffer between ServiceWorker and Client 
 PASS postMessage a transferable ArrayBuffer between ServiceWorker and Client over MessagePort 
-FAIL postMessage with dictionary a transferable ArrayBuffer between ServiceWorker and Client promise_test: Unhandled rejection with value: object "TypeError: Type error"
+PASS postMessage with dictionary a transferable ArrayBuffer between ServiceWorker and Client 
 PASS postMessage to a redundant worker 
 
index f7f84ff..0e77c55 100644 (file)
@@ -1,3 +1,3 @@
 
-FAIL Test Description: postMessage to cross-site iframe with MessagePort array containing 100 ports. The string did not match the expected pattern.
+PASS Test Description: postMessage to cross-site iframe with MessagePort array containing 100 ports. 
 
index caf766c..6c29b28 100644 (file)
@@ -1,3 +1,3 @@
 
-FAIL null transfer assert_throws: function "() => postMessage('', {transfer: null})" threw object "SyntaxError: The string did not match the expected pattern." ("SyntaxError") expected object "TypeError" ("TypeError")
+PASS null transfer 
 
index cb04aeb..7661d75 100644 (file)
@@ -4170,8 +4170,8 @@ PASS Window interface: operation alert(DOMString)
 PASS Window interface: operation confirm(DOMString) 
 PASS Window interface: operation prompt(DOMString, DOMString) 
 PASS Window interface: operation print() 
-FAIL Window interface: operation postMessage(any, USVString, [object Object]) assert_equals: property has wrong .length expected 1 but got 2
-FAIL Window interface: operation postMessage(any, WindowPostMessageOptions) assert_equals: property has wrong .length expected 1 but got 2
+PASS Window interface: operation postMessage(any, USVString, [object Object]) 
+PASS Window interface: operation postMessage(any, WindowPostMessageOptions) 
 PASS Window interface: operation captureEvents() 
 PASS Window interface: operation releaseEvents() 
 FAIL Window interface: attribute external assert_own_property: The global object must have a property "external" expected property "external" missing
index 47691b0..a0286b1 100644 (file)
@@ -4180,8 +4180,8 @@ PASS Window interface: operation alert(DOMString)
 PASS Window interface: operation confirm(DOMString) 
 PASS Window interface: operation prompt(DOMString, DOMString) 
 PASS Window interface: operation print() 
-FAIL Window interface: operation postMessage(any, USVString, [object Object]) assert_equals: property has wrong .length expected 1 but got 2
-FAIL Window interface: operation postMessage(any, WindowPostMessageOptions) assert_equals: property has wrong .length expected 1 but got 2
+PASS Window interface: operation postMessage(any, USVString, [object Object]) 
+PASS Window interface: operation postMessage(any, WindowPostMessageOptions) 
 PASS Window interface: operation captureEvents() 
 PASS Window interface: operation releaseEvents() 
 FAIL Window interface: attribute external assert_own_property: The global object must have a property "external" expected property "external" missing
index 2e8ff28..36508ce 100644 (file)
@@ -4180,8 +4180,8 @@ PASS Window interface: operation alert(DOMString)
 PASS Window interface: operation confirm(DOMString) 
 PASS Window interface: operation prompt(DOMString, DOMString) 
 PASS Window interface: operation print() 
-FAIL Window interface: operation postMessage(any, USVString, [object Object]) assert_equals: property has wrong .length expected 1 but got 2
-FAIL Window interface: operation postMessage(any, WindowPostMessageOptions) assert_equals: property has wrong .length expected 1 but got 2
+PASS Window interface: operation postMessage(any, USVString, [object Object]) 
+PASS Window interface: operation postMessage(any, WindowPostMessageOptions) 
 PASS Window interface: operation captureEvents() 
 PASS Window interface: operation releaseEvents() 
 FAIL Window interface: attribute external assert_own_property: The global object must have a property "external" expected property "external" missing
index c743e4d..38e6edf 100644 (file)
@@ -960,6 +960,7 @@ set(WebCore_NON_SVG_IDL_FILES
     page/PerformanceResourceTiming.idl
     page/PerformanceServerTiming.idl
     page/PerformanceTiming.idl
+    page/PostMessageOptions.idl
     page/RemoteDOMWindow.idl
     page/ResizeObserver.idl
     page/ResizeObserverCallback.idl
index a837fa9..52ba14f 100644 (file)
@@ -1,3 +1,54 @@
+2019-12-13  Chris Dumez  <cdumez@apple.com>
+
+        Implement PostMessageOptions for postMessage
+        https://bugs.webkit.org/show_bug.cgi?id=191028
+
+        Reviewed by Alex Christensen.
+
+        Implement PostMessageOptions dictionary parameter for postMessage:
+        - https://github.com/whatwg/html/issues/3799
+        - https://github.com/w3c/ServiceWorker/pull/1344
+
+        Blink and Gecko already support this.
+
+        No new tests, rebaselined existing tests.
+
+        * CMakeLists.txt:
+        * DerivedSources-input.xcfilelist:
+        * DerivedSources-output.xcfilelist:
+        * DerivedSources.make:
+        * Headers.cmake:
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * dom/MessagePort.cpp:
+        (WebCore::MessagePort::postMessage):
+        * dom/MessagePort.h:
+        * dom/MessagePort.idl:
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::postMessage):
+        * page/DOMWindow.h:
+        (WebCore::WindowPostMessageOptions::WindowPostMessageOptions):
+        * page/DOMWindow.idl:
+        * page/PostMessageOptions.h: Copied from Source/WebCore/workers/service/ServiceWorkerClient.idl.
+        (WebCore::PostMessageOptions::PostMessageOptions):
+        * page/PostMessageOptions.idl: Copied from Source/WebCore/workers/service/ServiceWorkerClient.idl.
+        * workers/DedicatedWorkerGlobalScope.cpp:
+        (WebCore::DedicatedWorkerGlobalScope::postMessage):
+        * workers/DedicatedWorkerGlobalScope.h:
+        * workers/DedicatedWorkerGlobalScope.idl:
+        * workers/Worker.cpp:
+        (WebCore::Worker::postMessage):
+        * workers/Worker.h:
+        * workers/Worker.idl:
+        * workers/service/ServiceWorker.cpp:
+        (WebCore::ServiceWorker::postMessage):
+        * workers/service/ServiceWorker.h:
+        * workers/service/ServiceWorker.idl:
+        * workers/service/ServiceWorkerClient.cpp:
+        (WebCore::ServiceWorkerClient::postMessage):
+        * workers/service/ServiceWorkerClient.h:
+        * workers/service/ServiceWorkerClient.idl:
+
 2019-12-13  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         Implement encoding/decoding for DisplayList::DrawNativeImage
index f3fcda3..931c0ee 100644 (file)
@@ -914,6 +914,7 @@ $(PROJECT_DIR)/page/PerformanceObserverEntryList.idl
 $(PROJECT_DIR)/page/PerformanceResourceTiming.idl
 $(PROJECT_DIR)/page/PerformanceServerTiming.idl
 $(PROJECT_DIR)/page/PerformanceTiming.idl
+$(PROJECT_DIR)/page/PostMessageOptions.idl
 $(PROJECT_DIR)/page/RemoteDOMWindow.idl
 $(PROJECT_DIR)/page/ResizeObserver.idl
 $(PROJECT_DIR)/page/ResizeObserverCallback.idl
index 49f6ffb..ae119f9 100644 (file)
@@ -1279,6 +1279,8 @@ $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSPositionErrorCallback.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSPositionErrorCallback.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSPositionOptions.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSPositionOptions.h
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSPostMessageOptions.cpp
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSPostMessageOptions.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSProcessingInstruction.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSProcessingInstruction.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSProgressEvent.cpp
index 8c9c62e..fadcbe0 100644 (file)
@@ -911,6 +911,7 @@ JS_BINDING_IDLS = \
     $(WebCore)/page/PerformanceResourceTiming.idl \
     $(WebCore)/page/PerformanceServerTiming.idl \
     $(WebCore)/page/PerformanceTiming.idl \
+    $(WebCore)/page/PostMessageOptions.idl \
     $(WebCore)/page/RemoteDOMWindow.idl \
     $(WebCore)/page/ResizeObserver.idl \
     $(WebCore)/page/ResizeObserverCallback.idl \
index 8b847e2..2d7c2ce 100644 (file)
@@ -809,6 +809,7 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS
     page/PlugInClient.h
     page/PointerCaptureController.h
     page/PointerLockController.h
+    page/PostMessageOptions.h
     page/PrewarmInformation.h
     page/PrintContext.h
     page/ProcessWarming.h
index df29d98..8e92fda 100644 (file)
@@ -3160,6 +3160,7 @@ JSPopStateEvent.cpp
 JSPositionCallback.cpp
 JSPositionErrorCallback.cpp
 JSPositionOptions.cpp
+JSPostMessageOptions.cpp
 JSProcessingInstruction.cpp
 JSProgressEvent.cpp
 JSPromiseRejectionEvent.cpp
index 19a919f..88b8016 100644 (file)
                463521AD2081092A00C28922 /* WindowProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 463521AA2081090B00C28922 /* WindowProxy.h */; settings = {ATTRIBUTES = (Private, ); }; };
                463EB6231B8789E00096ED51 /* TagCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 463EB6211B8789CB0096ED51 /* TagCollection.h */; };
                465307D01DB6EE4800E4137C /* JSUIEventInit.h in Headers */ = {isa = PBXBuildFile; fileRef = 83E045EF1DAA104F00B0D8B9 /* JSUIEventInit.h */; };
+               466172EC23A2AC1F003AB309 /* PostMessageOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 466172EB23A2ABFA003AB309 /* PostMessageOptions.h */; settings = {ATTRIBUTES = (Private, ); }; };
                46658DC91FA24B8700F7DD54 /* SWContextManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 4672413B1FA24B140088BD6D /* SWContextManager.h */; settings = {ATTRIBUTES = (Private, ); }; };
                466ED8D31EDE0144005E43F6 /* JSDOMRectList.h in Headers */ = {isa = PBXBuildFile; fileRef = 466ED8D21EDE0135005E43F6 /* JSDOMRectList.h */; };
                4671E0661D67A59600C6B497 /* CanvasPath.h in Headers */ = {isa = PBXBuildFile; fileRef = 4671E0641D67A57B00C6B497 /* CanvasPath.h */; };
                465EDD9D222F4EC300B46E16 /* DeviceOrientationOrMotionEvent.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = DeviceOrientationOrMotionEvent.idl; sourceTree = "<group>"; };
                465EDD9F222F4EC300B46E16 /* DeviceOrientationOrMotionPermissionState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DeviceOrientationOrMotionPermissionState.h; sourceTree = "<group>"; };
                465EDDA0222F4EC400B46E16 /* DeviceOrientationOrMotionPermissionState.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = DeviceOrientationOrMotionPermissionState.idl; sourceTree = "<group>"; };
+               466172E923A2ABFA003AB309 /* PostMessageOptions.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = PostMessageOptions.idl; sourceTree = "<group>"; };
+               466172EB23A2ABFA003AB309 /* PostMessageOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PostMessageOptions.h; sourceTree = "<group>"; };
                466DC6AB1EDE021D00746224 /* JSDOMRectList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDOMRectList.cpp; sourceTree = "<group>"; };
                466ED8D21EDE0135005E43F6 /* JSDOMRectList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDOMRectList.h; sourceTree = "<group>"; };
                4671E0631D67A57B00C6B497 /* CanvasPath.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CanvasPath.cpp; sourceTree = "<group>"; };
                                5CFC434E192406A900A0D3B5 /* PointerLockController.cpp */,
                                5CFC434F192406A900A0D3B5 /* PointerLockController.h */,
                                3772B09516535856000A49CA /* PopupOpeningObserver.h */,
+                               466172EB23A2ABFA003AB309 /* PostMessageOptions.h */,
+                               466172E923A2ABFA003AB309 /* PostMessageOptions.idl */,
                                E4605FEA2166480800E53046 /* PrewarmInformation.h */,
                                B776D43C1104527500BEB0EC /* PrintContext.cpp */,
                                B776D43A1104525D00BEB0EC /* PrintContext.h */,
                                9746AF3014F4DDE6003E7A70 /* PositionErrorCallback.h in Headers */,
                                37919C240B7D188600A56998 /* PositionIterator.h in Headers */,
                                9746AF3214F4DDE6003E7A70 /* PositionOptions.h in Headers */,
+                               466172EC23A2AC1F003AB309 /* PostMessageOptions.h in Headers */,
                                46DBB6501AB8C96F00D9A813 /* PowerObserverMac.h in Headers */,
                                C0F2A44113869AAB0066C534 /* preprocessor.pm in Headers */,
                                A1C1507A1E3F2B3E0032C98C /* PreviewConverter.h in Headers */,
index d43b262..7f604f4 100644 (file)
@@ -128,14 +128,14 @@ void MessagePort::entangle()
     MessagePortChannelProvider::fromContext(*m_scriptExecutionContext).entangleLocalPortInThisProcessToRemote(m_identifier, m_remoteIdentifier);
 }
 
-ExceptionOr<void> MessagePort::postMessage(JSC::JSGlobalObject& state, JSC::JSValue messageValue, Vector<JSC::Strong<JSC::JSObject>>&& transfer)
+ExceptionOr<void> MessagePort::postMessage(JSC::JSGlobalObject& state, JSC::JSValue messageValue, PostMessageOptions&& options)
 {
     LOG(MessagePorts, "Attempting to post message to port %s (to be received by port %s)", m_identifier.logString().utf8().data(), m_remoteIdentifier.logString().utf8().data());
 
     registerLocalActivity();
 
     Vector<RefPtr<MessagePort>> ports;
-    auto messageData = SerializedScriptValue::create(state, messageValue, WTFMove(transfer), ports);
+    auto messageData = SerializedScriptValue::create(state, messageValue, WTFMove(options.transfer), ports);
     if (messageData.hasException())
         return messageData.releaseException();
 
index f0b5e9b..668d5b4 100644 (file)
@@ -32,6 +32,7 @@
 #include "MessagePortChannel.h"
 #include "MessagePortIdentifier.h"
 #include "MessageWithMessagePorts.h"
+#include "PostMessageOptions.h"
 #include <wtf/WeakPtr.h>
 
 namespace JSC {
@@ -51,7 +52,7 @@ public:
     static Ref<MessagePort> create(ScriptExecutionContext&, const MessagePortIdentifier& local, const MessagePortIdentifier& remote);
     virtual ~MessagePort();
 
-    ExceptionOr<void> postMessage(JSC::JSGlobalObject&, JSC::JSValue message, Vector<JSC::Strong<JSC::JSObject>>&&);
+    ExceptionOr<void> postMessage(JSC::JSGlobalObject&, JSC::JSValue message, PostMessageOptions&&);
 
     void start();
     void close();
index 3780db5..ad83571 100644 (file)
@@ -31,7 +31,8 @@
     GenerateIsReachable=Impl,
     JSCustomMarkFunction,
 ] interface MessagePort : EventTarget {
-    [CallWith=GlobalObject, MayThrowException] void postMessage(any message, optional sequence<object> transfer = []);
+    [CallWith=GlobalObject, MayThrowException] void postMessage(any message, sequence<object> transfer);
+    [CallWith=GlobalObject, MayThrowException] void postMessage(any message, optional PostMessageOptions options);
     void start();
     void close();
 
index 16c1417..a53f3ec 100644 (file)
@@ -872,7 +872,7 @@ ExceptionOr<Storage*> DOMWindow::localStorage()
     return m_localStorage.get();
 }
 
-ExceptionOr<void> DOMWindow::postMessage(JSC::JSGlobalObject& lexicalGlobalObject, DOMWindow& incumbentWindow, JSC::JSValue messageValue, const String& targetOrigin, Vector<JSC::Strong<JSC::JSObject>>&& transfer)
+ExceptionOr<void> DOMWindow::postMessage(JSC::JSGlobalObject& lexicalGlobalObject, DOMWindow& incumbentWindow, JSC::JSValue messageValue, WindowPostMessageOptions&& options)
 {
     if (!isCurrentlyDisplayedInFrame())
         return { };
@@ -882,12 +882,12 @@ ExceptionOr<void> DOMWindow::postMessage(JSC::JSGlobalObject& lexicalGlobalObjec
     // Compute the target origin.  We need to do this synchronously in order
     // to generate the SyntaxError exception correctly.
     RefPtr<SecurityOrigin> target;
-    if (targetOrigin == "/") {
+    if (options.targetOrigin == "/") {
         if (!sourceDocument)
             return { };
         target = &sourceDocument->securityOrigin();
-    } else if (targetOrigin != "*") {
-        target = SecurityOrigin::createFromString(targetOrigin);
+    } else if (options.targetOrigin != "*") {
+        target = SecurityOrigin::createFromString(options.targetOrigin);
         // It doesn't make sense target a postMessage at a unique origin
         // because there's no way to represent a unique origin in a string.
         if (target->isUnique())
@@ -895,7 +895,7 @@ ExceptionOr<void> DOMWindow::postMessage(JSC::JSGlobalObject& lexicalGlobalObjec
     }
 
     Vector<RefPtr<MessagePort>> ports;
-    auto messageData = SerializedScriptValue::create(lexicalGlobalObject, messageValue, WTFMove(transfer), ports, SerializationContext::WindowPostMessage);
+    auto messageData = SerializedScriptValue::create(lexicalGlobalObject, messageValue, WTFMove(options.transfer), ports, SerializationContext::WindowPostMessage);
     if (messageData.hasException())
         return messageData.releaseException();
 
index 4bb1c9f..6003378 100644 (file)
@@ -33,6 +33,7 @@
 #include "Frame.h"
 #include "FrameDestructionObserver.h"
 #include "ImageBitmap.h"
+#include "PostMessageOptions.h"
 #include "ScrollToOptions.h"
 #include "ScrollTypes.h"
 #include "Supplementable.h"
@@ -96,6 +97,16 @@ struct WindowFeatures;
 enum SetLocationLocking { LockHistoryBasedOnGestureState, LockHistoryAndBackForwardList };
 enum class IncludeTargetOrigin { No, Yes };
 
+struct WindowPostMessageOptions : public PostMessageOptions {
+    WindowPostMessageOptions() = default;
+    WindowPostMessageOptions(String&& targetOrigin, Vector<JSC::Strong<JSC::JSObject>>&& transfer)
+        : PostMessageOptions(WTFMove(transfer))
+        , targetOrigin(WTFMove(targetOrigin))
+    { }
+
+    String targetOrigin { "/"_s };
+};
+
 // FIXME: Rename DOMWindow to LocalWindow and AbstractDOMWindow to DOMWindow.
 class DOMWindow final
     : public AbstractDOMWindow
@@ -250,7 +261,12 @@ public:
 
     String crossDomainAccessErrorMessage(const DOMWindow& activeWindow, IncludeTargetOrigin);
 
-    ExceptionOr<void> postMessage(JSC::JSGlobalObject&, DOMWindow& incumbentWindow, JSC::JSValue message, const String& targetOrigin, Vector<JSC::Strong<JSC::JSObject>>&&);
+    ExceptionOr<void> postMessage(JSC::JSGlobalObject&, DOMWindow& incumbentWindow, JSC::JSValue message, WindowPostMessageOptions&&);
+    ExceptionOr<void> postMessage(JSC::JSGlobalObject& globalObject, DOMWindow& incumbentWindow, JSC::JSValue message, String&& targetOrigin, Vector<JSC::Strong<JSC::JSObject>>&& transfer)
+    {
+        return postMessage(globalObject, incumbentWindow, message, WindowPostMessageOptions { WTFMove(targetOrigin), WTFMove(transfer) });
+    }
+
     void postMessageTimerFired(PostMessageTimer&);
 
     void languagesChanged();
index 3d1f02b..694532c 100644 (file)
@@ -98,6 +98,7 @@ typedef USVString CSSOMString;
     [EnabledBySetting=requestIdleCallback] void cancelIdleCallback(unsigned long handle);
 
     [CallWith=GlobalObject&IncumbentWindow, DoNotCheckSecurity, ForwardDeclareInHeader, MayThrowException] void postMessage(any message, USVString targetOrigin, optional sequence<object> transfer = []);
+    [CallWith=GlobalObject&IncumbentWindow, DoNotCheckSecurity, ForwardDeclareInHeader, MayThrowException] void postMessage(any message, optional WindowPostMessageOptions options);
 
     // Obsolete members, still part of the HTML specification (https://html.spec.whatwg.org/#Window-partial).
     void captureEvents(); // Not implemented. Also not in modern standards. Empty function may help compatibility with legacy content.
@@ -205,6 +206,12 @@ typedef USVString CSSOMString;
     [NotEnumerable, ImplementedAs=onwebkitTransitionEnd] attribute EventHandler onwebkittransitionend;
 };
 
+[
+    ImplementedAs=WindowPostMessageOptions
+] dictionary WindowPostMessageOptions : PostMessageOptions {
+  USVString targetOrigin = "/";
+};
+
 DOMWindow implements GlobalCrypto;
 DOMWindow implements GlobalEventHandlers;
 DOMWindow implements GlobalPerformance;
diff --git a/Source/WebCore/page/PostMessageOptions.h b/Source/WebCore/page/PostMessageOptions.h
new file mode 100644 (file)
index 0000000..360a13a
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2019 Apple 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:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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.
+ */
+
+#pragma once
+
+#include <JavaScriptCore/JSObject.h>
+#include <JavaScriptCore/Strong.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+struct PostMessageOptions {
+    PostMessageOptions() = default;
+    PostMessageOptions(Vector<JSC::Strong<JSC::JSObject>>&& transfer)
+        : transfer(WTFMove(transfer))
+    { }
+
+    Vector<JSC::Strong<JSC::JSObject>> transfer;
+};
+
+}
diff --git a/Source/WebCore/page/PostMessageOptions.idl b/Source/WebCore/page/PostMessageOptions.idl
new file mode 100644 (file)
index 0000000..287fd42
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2019 Apple 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:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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.
+ */
+
+dictionary PostMessageOptions {
+  sequence<object> transfer = [];
+};
index fd43590..a14c7e6 100644 (file)
@@ -65,10 +65,10 @@ EventTargetInterface DedicatedWorkerGlobalScope::eventTargetInterface() const
     return DedicatedWorkerGlobalScopeEventTargetInterfaceType;
 }
 
-ExceptionOr<void> DedicatedWorkerGlobalScope::postMessage(JSC::JSGlobalObject& state, JSC::JSValue messageValue, Vector<JSC::Strong<JSC::JSObject>>&& transfer)
+ExceptionOr<void> DedicatedWorkerGlobalScope::postMessage(JSC::JSGlobalObject& state, JSC::JSValue messageValue, PostMessageOptions&& options)
 {
     Vector<RefPtr<MessagePort>> ports;
-    auto message = SerializedScriptValue::create(state, messageValue, WTFMove(transfer), ports, SerializationContext::WorkerPostMessage);
+    auto message = SerializedScriptValue::create(state, messageValue, WTFMove(options.transfer), ports, SerializationContext::WorkerPostMessage);
     if (message.hasException())
         return message.releaseException();
 
index e52a59f..1bc96a9 100644 (file)
@@ -31,6 +31,7 @@
 
 #pragma once
 
+#include "PostMessageOptions.h"
 #include "WorkerGlobalScope.h"
 
 namespace JSC {
@@ -54,7 +55,7 @@ public:
 
     const String& name() const { return m_name; }
 
-    ExceptionOr<void> postMessage(JSC::JSGlobalObject&, JSC::JSValue message, Vector<JSC::Strong<JSC::JSObject>>&&);
+    ExceptionOr<void> postMessage(JSC::JSGlobalObject&, JSC::JSValue message, PostMessageOptions&&);
 
     DedicatedWorkerThread& thread();
 
index 108c475..a24bec3 100644 (file)
@@ -39,7 +39,8 @@
 ] interface DedicatedWorkerGlobalScope : WorkerGlobalScope {
     [Replaceable] readonly attribute DOMString name;
 
-    [CallWith=GlobalObject, MayThrowException] void postMessage(any message, optional sequence<object> transfer = []);
+    [CallWith=GlobalObject, MayThrowException] void postMessage(any message, sequence<object> transfer);
+    [CallWith=GlobalObject, MayThrowException] void postMessage(any message, optional PostMessageOptions options);
 
     void close();
 
index 81d7f40..c3de446 100644 (file)
@@ -127,10 +127,10 @@ Worker::~Worker()
     m_contextProxy.workerObjectDestroyed();
 }
 
-ExceptionOr<void> Worker::postMessage(JSC::JSGlobalObject& state, JSC::JSValue messageValue, Vector<JSC::Strong<JSC::JSObject>>&& transfer)
+ExceptionOr<void> Worker::postMessage(JSC::JSGlobalObject& state, JSC::JSValue messageValue, PostMessageOptions&& options)
 {
     Vector<RefPtr<MessagePort>> ports;
-    auto message = SerializedScriptValue::create(state, messageValue, WTFMove(transfer), ports, SerializationContext::WorkerPostMessage);
+    auto message = SerializedScriptValue::create(state, messageValue, WTFMove(options.transfer), ports, SerializationContext::WorkerPostMessage);
     if (message.hasException())
         return message.releaseException();
 
index 7dcbf4f..b59dd01 100644 (file)
@@ -30,6 +30,7 @@
 #include "ContentSecurityPolicyResponseHeaders.h"
 #include "EventTarget.h"
 #include "MessagePort.h"
+#include "PostMessageOptions.h"
 #include "WorkerScriptLoaderClient.h"
 #include <JavaScriptCore/RuntimeFlags.h>
 #include <wtf/MonotonicTime.h>
@@ -57,7 +58,7 @@ public:
     static ExceptionOr<Ref<Worker>> create(ScriptExecutionContext&, JSC::RuntimeFlags, const String& url, const Options&);
     virtual ~Worker();
 
-    ExceptionOr<void> postMessage(JSC::JSGlobalObject&, JSC::JSValue message, Vector<JSC::Strong<JSC::JSObject>>&&);
+    ExceptionOr<void> postMessage(JSC::JSGlobalObject&, JSC::JSValue message, PostMessageOptions&&);
 
     void terminate();
 
index 78b1abc..9a14100 100644 (file)
@@ -32,7 +32,8 @@
 ] interface Worker : EventTarget {
     void terminate();
 
-    [CallWith=GlobalObject, MayThrowException] void postMessage(any message, optional sequence<object> transfer = []);
+    [CallWith=GlobalObject, MayThrowException] void postMessage(any message, sequence<object> transfer);
+    [CallWith=GlobalObject, MayThrowException] void postMessage(any message, optional PostMessageOptions options);
     attribute EventHandler onmessage;
 };
 
index c83b0f0..e3b80d4 100644 (file)
@@ -104,7 +104,7 @@ SWClientConnection& ServiceWorker::swConnection()
     return ServiceWorkerProvider::singleton().serviceWorkerConnection();
 }
 
-ExceptionOr<void> ServiceWorker::postMessage(ScriptExecutionContext& context, JSC::JSValue messageValue, Vector<JSC::Strong<JSC::JSObject>>&& transfer)
+ExceptionOr<void> ServiceWorker::postMessage(ScriptExecutionContext& context, JSC::JSValue messageValue, PostMessageOptions&& options)
 {
     if (m_isStopped)
         return Exception { InvalidStateError };
@@ -113,7 +113,7 @@ ExceptionOr<void> ServiceWorker::postMessage(ScriptExecutionContext& context, JS
     ASSERT(execState);
 
     Vector<RefPtr<MessagePort>> ports;
-    auto messageData = SerializedScriptValue::create(*execState, messageValue, WTFMove(transfer), ports, SerializationContext::WorkerPostMessage);
+    auto messageData = SerializedScriptValue::create(*execState, messageValue, WTFMove(options.transfer), ports, SerializationContext::WorkerPostMessage);
     if (messageData.hasException())
         return messageData.releaseException();
 
index 7e132be..f8b5725 100644 (file)
@@ -30,6 +30,7 @@
 #include "ActiveDOMObject.h"
 #include "ContextDestructionObserver.h"
 #include "EventTarget.h"
+#include "PostMessageOptions.h"
 #include "ServiceWorkerData.h"
 #include <JavaScriptCore/Strong.h>
 #include <wtf/RefCounted.h>
@@ -58,7 +59,7 @@ public:
     
     void updateState(State);
 
-    ExceptionOr<void> postMessage(ScriptExecutionContext&, JSC::JSValue message, Vector<JSC::Strong<JSC::JSObject>>&&);
+    ExceptionOr<void> postMessage(ScriptExecutionContext&, JSC::JSValue message, PostMessageOptions&&);
 
     ServiceWorkerIdentifier identifier() const { return m_data.identifier; }
     ServiceWorkerRegistrationIdentifier registrationIdentifier() const { return m_data.registrationIdentifier; }
index dbc0373..eb39a93 100644 (file)
@@ -36,7 +36,8 @@
 ] interface ServiceWorker : EventTarget {
     readonly attribute USVString scriptURL;
     readonly attribute ServiceWorkerState state;
-    [CallWith=ScriptExecutionContext, MayThrowException] void postMessage(any message, optional sequence<object> transfer = []);
+    [CallWith=ScriptExecutionContext, MayThrowException] void postMessage(any message, sequence<object> transfer);
+    [CallWith=ScriptExecutionContext, MayThrowException] void postMessage(any message, optional PostMessageOptions options);
 
     // event
     attribute EventHandler onstatechange;
index 5894964..b12436e 100644 (file)
@@ -82,13 +82,13 @@ String ServiceWorkerClient::id() const
     return identifier().toString();
 }
 
-ExceptionOr<void> ServiceWorkerClient::postMessage(ScriptExecutionContext& context, JSC::JSValue messageValue, Vector<JSC::Strong<JSC::JSObject>>&& transfer)
+ExceptionOr<void> ServiceWorkerClient::postMessage(ScriptExecutionContext& context, JSC::JSValue messageValue, PostMessageOptions&& options)
 {
     auto* execState = context.execState();
     ASSERT(execState);
 
     Vector<RefPtr<MessagePort>> ports;
-    auto messageData = SerializedScriptValue::create(*execState, messageValue, WTFMove(transfer), ports, SerializationContext::WorkerPostMessage);
+    auto messageData = SerializedScriptValue::create(*execState, messageValue, WTFMove(options.transfer), ports, SerializationContext::WorkerPostMessage);
     if (messageData.hasException())
         return messageData.releaseException();
 
index d98d3bc..9779772 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "ContextDestructionObserver.h"
 #include "ExceptionOr.h"
+#include "PostMessageOptions.h"
 #include "ServiceWorkerClientData.h"
 #include <JavaScriptCore/Strong.h>
 #include <wtf/RefCounted.h>
@@ -59,7 +60,7 @@ public:
 
     Identifier identifier() const { return m_data.identifier; }
 
-    ExceptionOr<void> postMessage(ScriptExecutionContext&, JSC::JSValue message, Vector<JSC::Strong<JSC::JSObject>>&& transfer);
+    ExceptionOr<void> postMessage(ScriptExecutionContext&, JSC::JSValue message, PostMessageOptions&&);
 
 protected:
     ServiceWorkerClient(ServiceWorkerGlobalScope&, ServiceWorkerClientData&&);
index d8acac9..96a6a30 100644 (file)
@@ -35,7 +35,8 @@
     readonly attribute ServiceWorkerClientType type;
     readonly attribute DOMString id;
 
-    [CallWith=ScriptExecutionContext, MayThrowException] void postMessage(any message, optional sequence<object> transfer = []);
+    [CallWith=ScriptExecutionContext, MayThrowException] void postMessage(any message, sequence<object> transfer);
+    [CallWith=ScriptExecutionContext, MayThrowException] void postMessage(any message, optional PostMessageOptions options);
 };
 
 enum FrameType {