Source/WebCore: DataCloneError exception is not thrown when postMessage's second...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Dec 2013 12:42:54 +0000 (12:42 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Dec 2013 12:42:54 +0000 (12:42 +0000)
port or the target port.

https://bugs.webkit.org/show_bug.cgi?id=124708

Patch by Michal Poteralski <m.poteralski@samsung.com> on 2013-12-09
Reviewed by Alexey Proskuryakov.

According to specification:
http://www.whatwg.org/specs/web-apps/current-work/multipage/web-messaging.html#dom-window-postmessage

If the method was invoked with a second argument transfer then if any of the objects in the
transfer are either the source port or the target port (if any), then a DataCloneError
exception should be thrown. Currently an InvalidStateError exception is thrown what is an
incorrect behaviour.

The proposed solution is change to the correct the exception value.

Tests: fast/dom/Window/postMessage-clone-port-error.html

* dom/MessagePort.cpp:
(WebCore::MessagePort::postMessage): Improve exception value

LayoutTests: DataCloneError exception is not thrown when postMessage's second parameter
is the source port or the target port.

https://bugs.webkit.org/show_bug.cgi?id=124708

Patch by Michal Poteralski <m.poteralski@samsung.com> on 2013-12-09
Reviewed by Alexey Proskuryakov.

Added layout test to check correctness of value thrown by postMessage:

* fast/dom/Window/postMessage-clone-port-error-expected.txt: Added.
* fast/dom/Window/postMessage-clone-port-error.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/dom/Window/postMessage-clone-port-error-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/Window/postMessage-clone-port-error.html [new file with mode: 0644]
LayoutTests/fast/events/message-port-clone-expected.txt
LayoutTests/fast/events/message-port-multi-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/dom/MessagePort.cpp

index 37c08c8..d3dc7ec 100644 (file)
@@ -1,3 +1,17 @@
+2013-12-09  Michal Poteralski  <m.poteralski@samsung.com>
+
+        DataCloneError exception is not thrown when postMessage's second parameter
+        is the source port or the target port.
+
+        https://bugs.webkit.org/show_bug.cgi?id=124708
+
+        Reviewed by Alexey Proskuryakov.
+
+        Added layout test to check correctness of value thrown by postMessage:
+
+        * fast/dom/Window/postMessage-clone-port-error-expected.txt: Added.
+        * fast/dom/Window/postMessage-clone-port-error.html: Added.
+
 2013-12-09  Gustavo Noronha Silva  <gns@gnome.org>
 
         accessibility/press-targets-center-point.html should not depend on font layout
diff --git a/LayoutTests/fast/dom/Window/postMessage-clone-port-error-expected.txt b/LayoutTests/fast/dom/Window/postMessage-clone-port-error-expected.txt
new file mode 100644 (file)
index 0000000..d4f8606
--- /dev/null
@@ -0,0 +1,5 @@
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS exName is "DataCloneError"
+
diff --git a/LayoutTests/fast/dom/Window/postMessage-clone-port-error.html b/LayoutTests/fast/dom/Window/postMessage-clone-port-error.html
new file mode 100644 (file)
index 0000000..a1077b8
--- /dev/null
@@ -0,0 +1,21 @@
+<body onload="test();"></body>
+<script src="../../../resources/js-test-pre.js"></script>
+<script>
+var exName;
+function test() {
+    if (window.testRunner)
+        testRunner.dumpAsText();
+
+    var channel = new MessageChannel();
+    channel.port1.start();
+
+    try {
+        channel.port1.postMessage("ports", [channel.port1]);
+    } catch(ex) {
+        exName = ex.name
+        shouldBeEqualToString("exName", "DataCloneError");
+    }
+}
+</script>
+<script src="../../../resources/js-test-post.js"></script>
+</body>
index 226c04a..bb48727 100644 (file)
@@ -2,8 +2,8 @@ Tests various use cases when cloning MessagePorts.
 
 Should be a series of SUCCESS messages, followed with DONE.
 
-SUCCESS: Posting port to itself: Error: InvalidStateError: DOM Exception 11
-SUCCESS: Posting entangled port: Error: InvalidStateError: DOM Exception 11
+SUCCESS: Posting port to itself: Error: DataCloneError: DOM Exception 25
+SUCCESS: Posting entangled port: Error: DataCloneError: DOM Exception 25
 SUCCESS: Posting cloned port.
 SUCCESS: Posted messages to cloned port.
 SUCCESS: Cloned both endpoints of a channel.
index 2115051..167da40 100644 (file)
@@ -3,8 +3,8 @@ This test checks the various use cases around sending multiple ports through Mes
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
-PASS channel.port1.postMessage("same port", [channel.port1]) threw exception Error: InvalidStateError: DOM Exception 11.
-PASS channel.port1.postMessage("entangled port", [channel.port2]) threw exception Error: InvalidStateError: DOM Exception 11.
+PASS channel.port1.postMessage("same port", [channel.port1]) threw exception Error: DataCloneError: DOM Exception 25.
+PASS channel.port1.postMessage("entangled port", [channel.port2]) threw exception Error: DataCloneError: DOM Exception 25.
 PASS channel.port1.postMessage("null port", [channel3.port1, null, channel3.port2]) threw exception Error: InvalidStateError: DOM Exception 11.
 PASS channel.port1.postMessage("notAPort", [channel3.port1, {}, channel3.port2]) threw exception TypeError: Type error.
 PASS channel.port1.postMessage("duplicate port", [channel3.port1, channel3.port1]) threw exception Error: InvalidStateError: DOM Exception 11.
index 00a9786..564c458 100644 (file)
@@ -1,3 +1,27 @@
+2013-12-09  Michal Poteralski  <m.poteralski@samsung.com>
+
+        DataCloneError exception is not thrown when postMessage's second parameter is the source
+        port or the target port.
+
+        https://bugs.webkit.org/show_bug.cgi?id=124708
+
+        Reviewed by Alexey Proskuryakov.
+
+        According to specification:
+        http://www.whatwg.org/specs/web-apps/current-work/multipage/web-messaging.html#dom-window-postmessage
+
+        If the method was invoked with a second argument transfer then if any of the objects in the
+        transfer are either the source port or the target port (if any), then a DataCloneError
+        exception should be thrown. Currently an InvalidStateError exception is thrown what is an
+        incorrect behaviour.
+
+        The proposed solution is change to the correct the exception value.
+
+        Tests: fast/dom/Window/postMessage-clone-port-error.html
+
+        * dom/MessagePort.cpp:
+        (WebCore::MessagePort::postMessage): Improve exception value
+
 2013-12-09  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         Unreviewed. Fix the GTK+ build with NetworkProcess enabled.
index 3da853c..6416723 100644 (file)
@@ -72,7 +72,7 @@ void MessagePort::postMessage(PassRefPtr<SerializedScriptValue> message, const M
         for (unsigned int i = 0; i < ports->size(); ++i) {
             MessagePort* dataPort = (*ports)[i].get();
             if (dataPort == this || m_entangledChannel->isConnectedTo(dataPort)) {
-                ec = INVALID_STATE_ERR;
+                ec = DATA_CLONE_ERR;
                 return;
             }
         }