WebAssembly: sending module to iframe fails
authorgskachkov@gmail.com <gskachkov@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Dec 2017 00:56:18 +0000 (00:56 +0000)
committergskachkov@gmail.com <gskachkov@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Dec 2017 00:56:18 +0000 (00:56 +0000)
https://bugs.webkit.org/show_bug.cgi?id=179263

Reviewed by JF Bastien.

Source/WebCore:

Allow use WebAssembly.Module as input parameters for postMessage
in window and iframe object.

Tests: wasm/iframe-postmessage.html
       wasm/window-postmessage.html

* bindings/js/SerializedScriptValue.cpp:
(WebCore::CloneSerializer::dumpIfTerminal):
* bindings/js/SerializedScriptValue.h:
* page/DOMWindow.cpp:
(WebCore::DOMWindow::postMessage):

LayoutTests:

* platform/ios-simulator/TestExpectations:
* platform/win/TestExpectations:
* resources/wasm-builder.js: Renamed from LayoutTests/workers/wasm-resources/builder.js.
* wasm/iframe-parent-postmessage-expected.txt: Added.
* wasm/iframe-parent-postmessage.html: Added.
* wasm/iframe-postmessage-expected.txt: Added.
* wasm/iframe-postmessage.html: Added.
* wasm/resources/frame-parent.html: Added.
* wasm/resources/frame.html: Added.
* wasm/resources/load_wasm.js: Added.
(createWasmModule):
* wasm/window-postmessage-expected.txt: Added.
* wasm/window-postmessage.html: Added.
* workers/wasm-mem-post-message.html:

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

18 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/ios-simulator/TestExpectations
LayoutTests/platform/win/TestExpectations
LayoutTests/resources/wasm-builder.js [moved from LayoutTests/workers/wasm-resources/builder.js with 100% similarity]
LayoutTests/wasm/iframe-parent-postmessage-expected.txt [new file with mode: 0644]
LayoutTests/wasm/iframe-parent-postmessage.html [new file with mode: 0644]
LayoutTests/wasm/iframe-postmessage-expected.txt [new file with mode: 0644]
LayoutTests/wasm/iframe-postmessage.html [new file with mode: 0644]
LayoutTests/wasm/resources/frame-parent.html [new file with mode: 0644]
LayoutTests/wasm/resources/frame.html [new file with mode: 0644]
LayoutTests/wasm/resources/load_wasm.js [new file with mode: 0644]
LayoutTests/wasm/window-postmessage-expected.txt [new file with mode: 0644]
LayoutTests/wasm/window-postmessage.html [new file with mode: 0644]
LayoutTests/workers/wasm-mem-post-message.html
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/SerializedScriptValue.cpp
Source/WebCore/bindings/js/SerializedScriptValue.h
Source/WebCore/page/DOMWindow.cpp

index 89caa18..e587b80 100644 (file)
@@ -1,3 +1,25 @@
+2017-12-07  Oleksandr Skachkov  <gskachkov@gmail.com>
+
+        WebAssembly: sending module to iframe fails
+        https://bugs.webkit.org/show_bug.cgi?id=179263
+
+        Reviewed by JF Bastien.
+
+        * platform/ios-simulator/TestExpectations:
+        * platform/win/TestExpectations:
+        * resources/wasm-builder.js: Renamed from LayoutTests/workers/wasm-resources/builder.js.
+        * wasm/iframe-parent-postmessage-expected.txt: Added.
+        * wasm/iframe-parent-postmessage.html: Added.
+        * wasm/iframe-postmessage-expected.txt: Added.
+        * wasm/iframe-postmessage.html: Added.
+        * wasm/resources/frame-parent.html: Added.
+        * wasm/resources/frame.html: Added.
+        * wasm/resources/load_wasm.js: Added.
+        (createWasmModule):
+        * wasm/window-postmessage-expected.txt: Added.
+        * wasm/window-postmessage.html: Added.
+        * workers/wasm-mem-post-message.html:
+
 2017-12-07  Matt Lewis  <jlewis3@apple.com>
 
         Skipped imported/w3c/web-platform-tests/XMLHttpRequest/event-upload-progress-crossorigin.htm on macOS WK1
index 1c011f2..3d30b34 100644 (file)
@@ -52,6 +52,9 @@ http/tests/security/contentSecurityPolicy/WebAssembly-blocked-in-about-blank-ifr
 http/tests/security/contentSecurityPolicy/WebAssembly-blocked-in-external-script.html [ Failure ]
 http/tests/security/contentSecurityPolicy/WebAssembly-blocked-in-subframe.html [ Failure ]
 http/tests/security/contentSecurityPolicy/WebAssembly-blocked.html [ Failure ]
+wasm/iframe-postmessage.html [ Skip ]
+wasm/iframe-parent-postmessage.html [ Skip ]
+wasm/window-postmessage.html [ Skip ]
 
 # WebGL tests which need triaging https://bugs.webkit.org/b/174100
 webgl/1.0.2/conformance/uniforms/uniform-default-values.html [ Failure ]
index d92be7e..8a25534 100644 (file)
@@ -3673,6 +3673,9 @@ workers/wasm-hashset.html [ Skip ]
 workers/wasm-long-compile-many.html [ Skip ]
 workers/wasm-long-compile.html [ Skip ]
 workers/wasm-mem-post-message.html [ Skip ]
+wasm/iframe-postmessage.html [ Skip ]
+wasm/iframe-parent-postmessage.html [ Skip ]
+wasm/window-postmessage.html [ Skip ]
 
 # Animated image throttling behaves differently on WK1.
 svg/animations/animated-svg-image-outside-viewport-paused.html [ Skip ]
diff --git a/LayoutTests/wasm/iframe-parent-postmessage-expected.txt b/LayoutTests/wasm/iframe-parent-postmessage-expected.txt
new file mode 100644 (file)
index 0000000..2f87a5e
--- /dev/null
@@ -0,0 +1,10 @@
+Test that expected Wasm Module can be sent over window.parent.postMessage from iframe.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS () => value is 35010
+
diff --git a/LayoutTests/wasm/iframe-parent-postmessage.html b/LayoutTests/wasm/iframe-parent-postmessage.html
new file mode 100644 (file)
index 0000000..dfa1c9d
--- /dev/null
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<iframe src="./resources/frame-parent.html" id="iframe"></iframe>
+<script src="../resources/js-test.js"></script>
+<script src="../resources/wasm-builder.js"></script>
+<script src="./resources/load_wasm.js"></script>
+<script>
+description("Test that expected Wasm Module can be sent over window.parent.postMessage from iframe.");
+if (window.testRunner)
+    testRunner.waitUntilDone();
+
+function finish(value) {
+    shouldBe(() => value, () => 35010);
+
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+
+var run = async function () {
+    try {
+        window.addEventListener("message", (answer) => finish(answer.data), false);
+        var mod = await createWasmModule();
+        var iframe = document.getElementById("iframe").contentWindow;
+        iframe.postMessage(mod, '*');
+    } catch (e) {
+        console.log('error:', e);
+    }
+};
+
+setTimeout(run);
+</script>
\ No newline at end of file
diff --git a/LayoutTests/wasm/iframe-postmessage-expected.txt b/LayoutTests/wasm/iframe-postmessage-expected.txt
new file mode 100644 (file)
index 0000000..861ec7f
--- /dev/null
@@ -0,0 +1,10 @@
+Test that expected Wasm Module can be sent over iframe.postMessage.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS () => value is 35010
+
diff --git a/LayoutTests/wasm/iframe-postmessage.html b/LayoutTests/wasm/iframe-postmessage.html
new file mode 100644 (file)
index 0000000..3176c2d
--- /dev/null
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<iframe src="./resources/frame.html" id="iframe"></iframe>
+<script src="../resources/js-test.js"></script>
+<script src="../resources/wasm-builder.js"></script>
+<script src="./resources/load_wasm.js"></script>
+<script>
+description("Test that expected Wasm Module can be sent over iframe.postMessage.");
+if (window.testRunner)
+    testRunner.waitUntilDone();
+
+function finish(value) {
+    shouldBe(() => value, () => 35010);
+
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+
+var run = async function () {
+    try {
+        window.addEventListener("message", (answer) => finish(answer.data), false);
+        var mod = await createWasmModule();
+        var iframe = document.getElementById("iframe").contentWindow;
+        iframe.postMessage(mod, '*');
+    } catch (e) {
+        console.log('error:', e);
+    }
+};
+
+setTimeout(run);
+</script>
\ No newline at end of file
diff --git a/LayoutTests/wasm/resources/frame-parent.html b/LayoutTests/wasm/resources/frame-parent.html
new file mode 100644 (file)
index 0000000..a4135a2
--- /dev/null
@@ -0,0 +1,14 @@
+<script>
+function listener(event) {
+  var mod = event.data;
+  try {
+    var i = new WebAssembly.Instance(mod);
+    var ans = i.exports.calc(5);
+    window.parent.postMessage(ans, event.origin);
+  } catch (e) {
+    window.parent.postMessage(e, event.origin);
+  }
+}
+
+addEventListener("message", listener, false)
+</script>
diff --git a/LayoutTests/wasm/resources/frame.html b/LayoutTests/wasm/resources/frame.html
new file mode 100644 (file)
index 0000000..2d24d92
--- /dev/null
@@ -0,0 +1,14 @@
+<script>
+function listener(event) {
+  var mod = event.data;
+  try {
+    var i = new WebAssembly.Instance(mod);
+    var ans = i.exports.calc(5);
+    event.source.postMessage(ans, event.origin);
+  } catch (e) {
+    event.source.postMessage(e, event.origin);
+  }
+}
+
+addEventListener("message", listener, false)
+</script>
diff --git a/LayoutTests/wasm/resources/load_wasm.js b/LayoutTests/wasm/resources/load_wasm.js
new file mode 100644 (file)
index 0000000..b6286de
--- /dev/null
@@ -0,0 +1,19 @@
+function createWasmModule() {
+    let builder = new Builder();
+    builder = builder.Type().End()
+        .Function().End()
+        .Export().Function("calc").End()
+        .Code()
+            .Function("calc", { params: ["i32"], ret: "i32" })
+                .GetLocal(0)
+                .GetLocal(0)
+                .I32Add();
+
+    const count = 7000;
+    for (let i = 0; i < count; i++) {
+        builder = builder.GetLocal(0).I32Add();
+    }
+    builder = builder.Return().End().End();
+
+    return new WebAssembly.Module(builder.WebAssembly().get());
+}
\ No newline at end of file
diff --git a/LayoutTests/wasm/window-postmessage-expected.txt b/LayoutTests/wasm/window-postmessage-expected.txt
new file mode 100644 (file)
index 0000000..40f7715
--- /dev/null
@@ -0,0 +1,10 @@
+Test that expected Wasm Module can be sent over window.postMessage.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS () => value is 7002
+
diff --git a/LayoutTests/wasm/window-postmessage.html b/LayoutTests/wasm/window-postmessage.html
new file mode 100644 (file)
index 0000000..8e12ca6
--- /dev/null
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<script src="../resources/js-test.js"></script>
+<script src="../resources/wasm-builder.js"></script>
+<script src="./resources/load_wasm.js"></script>
+<script>
+description("Test that expected Wasm Module can be sent over window.postMessage.");
+if (window.testRunner)
+    testRunner.waitUntilDone();
+
+window.addEventListener("message", (answer) => finish(answer.data), false);
+
+function finish(module) {
+    var i = new WebAssembly.Instance(module);
+    var value = i.exports.calc(1);
+    shouldBe(() => value, () => 7002);
+
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+
+var run = async function () {
+    try {
+        var mod = await createWasmModule();
+        window.postMessage(mod, '*');
+    } catch (e) {
+        console.log('error:', e);
+    }
+};
+
+setTimeout(run);
+</script>
\ No newline at end of file
index 90fe161..c173b81 100644 (file)
@@ -1,6 +1,6 @@
 <html>
   <head>
-    <script src="./wasm-resources/builder.js"></script>
+    <script src="../resources/wasm-builder.js"></script>
     <script src="../resources/js-test-pre.js"></script>
 </head>
 <body>
index b841be9..f5f86b5 100644 (file)
@@ -1,3 +1,22 @@
+2017-12-07  Oleksandr Skachkov  <gskachkov@gmail.com>
+
+        WebAssembly: sending module to iframe fails
+        https://bugs.webkit.org/show_bug.cgi?id=179263
+
+        Reviewed by JF Bastien.
+
+        Allow use WebAssembly.Module as input parameters for postMessage 
+        in window and iframe object.
+
+        Tests: wasm/iframe-postmessage.html
+               wasm/window-postmessage.html
+
+        * bindings/js/SerializedScriptValue.cpp:
+        (WebCore::CloneSerializer::dumpIfTerminal):
+        * bindings/js/SerializedScriptValue.h:
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::postMessage):
+
 2017-12-07  Joseph Pecoraro  <pecoraro@apple.com>
 
         Web Inspector: Fix style in remote inspector classes
index 1a886dd..a9adf99 100644 (file)
@@ -1066,7 +1066,7 @@ private:
 
 #if ENABLE(WEBASSEMBLY)
             if (JSWebAssemblyModule* module = jsDynamicDowncast<JSWebAssemblyModule*>(vm, obj)) {
-                if (m_context != SerializationContext::WorkerPostMessage)
+                if (m_context != SerializationContext::WorkerPostMessage && m_context != SerializationContext::WindowPostMessage)
                     return false;
 
                 uint32_t index = m_wasmModules.size(); 
index 2eb1ddc..9dbd565 100644 (file)
@@ -51,7 +51,7 @@ class SharedBuffer;
 enum class SerializationReturnCode;
 
 enum class SerializationErrorMode { NonThrowing, Throwing };
-enum class SerializationContext { Default, WorkerPostMessage };
+enum class SerializationContext { Default, WorkerPostMessage, WindowPostMessage };
 
 using ArrayBufferContentsArray = Vector<JSC::ArrayBufferContents>;
 #if ENABLE(WEBASSEMBLY)
index b73348f..2babb61 100644 (file)
@@ -928,7 +928,7 @@ ExceptionOr<void> DOMWindow::postMessage(JSC::ExecState& state, DOMWindow& incum
     }
 
     Vector<RefPtr<MessagePort>> ports;
-    auto message = SerializedScriptValue::create(state, messageValue, WTFMove(transfer), ports);
+    auto message = SerializedScriptValue::create(state, messageValue, WTFMove(transfer), ports, SerializationContext::WindowPostMessage);
     if (message.hasException())
         return message.releaseException();