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. To prevent sending message to iframe
that is not ready, in iframe-* test we are waiting message from
iframe only after that we send message to it.

Tests: wasm/iframe-parent-postmessage.html
       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/197046@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@226322 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
gskachkov committed Jan 2, 2018
1 parent f03ebdf commit 96c12e4708fc26cac0e6071a7a9253cdc97f2053
@@ -1,3 +1,25 @@
2018-01-02 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:

2018-01-02 Ms2ger <Ms2ger@igalia.com>

[WPE] Update some test expectations
@@ -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 ]
@@ -3672,6 +3672,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>
<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();
}

window.addEventListener("message", value => run(), { once:true }, false);

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);
}
};
</script>
<iframe src="./resources/frame-parent.html" id="iframe"></iframe>
@@ -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>
<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();
}

window.addEventListener("message", value => run(), { once:true }, false);

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) {
debug('error:' + e);
}
};
</script>
<iframe src="./resources/frame.html" id="iframe"></iframe>
@@ -0,0 +1,16 @@
<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);

window.parent.postMessage("ready", "*");
</script>
@@ -0,0 +1,15 @@
<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);
window.parent.postMessage("ready", "*");
</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 +1,23 @@
2018-01-02 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. To prevent sending message to iframe
that is not ready, in iframe-* test we are waiting message from
iframe only after that we send message to it.

Tests: wasm/iframe-parent-postmessage.html
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):

== Rolled over to ChangeLog-2018-01-01 ==
@@ -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)
@@ -927,7 +927,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 96c12e4

Please sign in to comment.