Skip to content
Permalink
Browse files
WebAssembly: sending module to iframe fails
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:


Canonical link: https://commits.webkit.org/196476@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225656 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
gskachkov committed Dec 8, 2017
1 parent a17fd62 commit eb1df48d44996093dd6d645561929895c301e4f2
@@ -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
@@ -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 ]
@@ -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 ]
File renamed without changes.
@@ -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

@@ -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>
@@ -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

@@ -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>
@@ -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>
@@ -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>
@@ -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());
}
@@ -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

@@ -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>
@@ -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>
@@ -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
@@ -1066,7 +1066,7 @@ class CloneSerializer : CloneBase {

#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();
@@ -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)
@@ -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();

0 comments on commit eb1df48

Please sign in to comment.