Skip to content

Truly independent web browser

LibWeb: Keep a serialized WebAssembly.Module within its agent cluster

Shannon Booth668ff086e529
diff --git a/Libraries/LibWeb/HTML/StructuredSerialize.cpp b/Libraries/LibWeb/HTML/StructuredSerialize.cpp
index 103d1c6d64e..e76c9416453 100644
--- a/Libraries/LibWeb/HTML/StructuredSerialize.cpp
+++ b/Libraries/LibWeb/HTML/StructuredSerialize.cpp
@@ -1148,6 +1148,7 @@ template WEB_API void StructuredSerializeWriter::encode(int const&);
template WEB_API void StructuredSerializeWriter::encode(Utf16String const&);
template WEB_API void StructuredSerializeWriter::encode(Optional<Utf16String> const&);
template WEB_API void StructuredSerializeWriter::encode(Optional<bool> const&);
+template WEB_API void StructuredSerializeWriter::encode(Optional<u64> const&);
template WEB_API void StructuredSerializeWriter::encode(long const&);
template WEB_API void StructuredSerializeWriter::encode(long long const&);
template WEB_API void StructuredSerializeWriter::encode(unsigned long const&);
@@ -1173,6 +1174,7 @@ template WEB_API ErrorOr<double> StructuredSerializeReader::decode();
template WEB_API ErrorOr<Utf16String> StructuredSerializeReader::decode();
template WEB_API ErrorOr<Optional<Utf16String>> StructuredSerializeReader::decode();
template WEB_API ErrorOr<Optional<bool>> StructuredSerializeReader::decode();
+template WEB_API ErrorOr<Optional<u64>> StructuredSerializeReader::decode();
template WEB_API ErrorOr<long> StructuredSerializeReader::decode();
template WEB_API ErrorOr<long long> StructuredSerializeReader::decode();
template WEB_API ErrorOr<unsigned long> StructuredSerializeReader::decode();
diff --git a/Libraries/LibWeb/WebAssembly/Module.cpp b/Libraries/LibWeb/WebAssembly/Module.cpp
index 2e5f2f14b4c..240ae1468e7 100644
--- a/Libraries/LibWeb/WebAssembly/Module.cpp
+++ b/Libraries/LibWeb/WebAssembly/Module.cpp
@@ -10,6 +10,8 @@
#include <LibJS/Runtime/Realm.h>
#include <LibJS/Runtime/VM.h>
#include <LibWeb/Bindings/Module.h>
+#include <LibWeb/Bindings/PrincipalHostDefined.h>
+#include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/HTML/StructuredSerialize.h>
#include <LibWeb/WebAssembly/Module.h>
#include <LibWeb/WebAssembly/WebAssembly.h>
@@ -175,7 +177,8 @@ WebIDL::ExceptionOr<void> Module::serialization_steps(HTML::StructuredSerializeW
// 2. Set serialized.[[Bytes]] to the sub-serialization of value.[[Bytes]].
serialized.encode(m_bytes);
- // FIXME: 3. Set serialized.[[AgentCluster]] to the current Realm’s corresponding agent cluster.
+ // 3. Set serialized.[[AgentCluster]] to the current Realm’s corresponding agent cluster.
+ serialized.encode(HTML::current_settings_object().agent_cluster_id());
return {};
}
@@ -189,7 +192,11 @@ WebIDL::ExceptionOr<void> Module::deserialization_steps(JS::Realm& realm, HTML::
// 2. Set value.[[Bytes]] to bytes.
m_bytes = move(bytes);
- // FIXME: 3. If targetRealm’s corresponding agent cluster is not serialized.[[AgentCluster]], then throw a "DataCloneError" DOMException.
+ // 3. If targetRealm’s corresponding agent cluster is not serialized.[[AgentCluster]], then throw a "DataCloneError" DOMException.
+ auto agent_cluster = TRY(HTML::decode_or_throw_data_clone_error<Optional<u64>>(realm, serialized));
+ auto target_agent_cluster = Bindings::principal_host_defined_environment_settings_object(realm).agent_cluster_id();
+ if (!agent_cluster.has_value() || agent_cluster != target_agent_cluster)
+ return WebIDL::DataCloneError::create("Cannot deserialize WebAssembly Module outside its agent cluster"_utf16);
// 4. Compile a WebAssembly module from bytes and set value.[[Module]] to the result.
m_compiled_module = TRY(Detail::compile_a_webassembly_module(realm, m_bytes));
diff --git a/Tests/LibWeb/StructuredSerializeTestHelpers.h b/Tests/LibWeb/StructuredSerializeTestHelpers.h
index d3c03c30416..e34e91d0f45 100644
--- a/Tests/LibWeb/StructuredSerializeTestHelpers.h
+++ b/Tests/LibWeb/StructuredSerializeTestHelpers.h
@@ -422,12 +422,12 @@ inline Web::HTML::StorageSerializationRecord frozen_image_data_record(ReadonlyBy
return serializable_storage_record("ImageData"sv, 1, body);
}
-// CryptoKey is [SecureContext], and WebAssembly module compilation consults Content Security Policy, so decode them through a principal realm.
-inline Web::WebIDL::ExceptionOr<JS::Value> principal_storage_deserialize(Web::HTML::StorageSerializationRecord const& record)
+// CryptoKey is [SecureContext], and WebAssembly module compilation consults Content Security Policy, so they need a principal realm.
+inline JS::Realm& principal_test_realm()
{
static GC::Root<JS::Realm> realm;
- auto& vm = test_realm().vm();
if (!realm) {
+ auto& vm = test_realm().vm();
auto depth = vm.execution_context_stack().size();
realm = Web::Bindings::create_a_principal_javascript_realm();
while (vm.execution_context_stack().size() > depth)
@@ -445,29 +445,26 @@ inline Web::WebIDL::ExceptionOr<JS::Value> principal_storage_deserialize(Web::HT
window->set_associated_document(document);
document->set_window(*window);
}
+ return *realm;
+}
- auto& settings = Web::Bindings::principal_host_defined_environment_settings_object(*realm);
+inline Web::WebIDL::ExceptionOr<JS::Value> principal_storage_deserialize(Web::HTML::StorageSerializationRecord const& record)
+{
+ auto& realm = principal_test_realm();
+ auto& vm = realm.vm();
+ auto& settings = Web::Bindings::principal_host_defined_environment_settings_object(realm);
auto depth = vm.execution_context_stack().size();
vm.push_execution_context(settings.realm_execution_context());
Web::HTML::StructuredSerializeReader reader { record };
Web::HTML::DeserializationMemory memory;
- auto result = Web::HTML::structured_deserialize_internal(vm, reader, *realm, memory, Web::HTML::CheckFullyConsumed::Yes);
+ auto result = Web::HTML::structured_deserialize_internal(vm, reader, realm, memory, Web::HTML::CheckFullyConsumed::Yes);
while (vm.execution_context_stack().size() > depth)
vm.pop_execution_context();
return result;
}
-constexpr inline auto s_minimal_webassembly_module_bytes = to_array<u8>({ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00 });
-
-inline Web::HTML::StorageSerializationRecord webassembly_module_storage_record(ReadonlyBytes module_bytes)
-{
- Vector<u8> body;
- append_storage_bytes(body, module_bytes);
- return serializable_storage_record("Module"sv, 1, body);
-}
-
// `declared_handle_size` lets tests overstate the raw ByteBuffer handle length.
inline Web::HTML::StorageSerializationRecord crypto_key_secret_record(ReadonlyBytes handle, u64 declared_handle_size)
{
diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.ini
index 22a2044e385..ca7a5a07d88 100644
--- a/Tests/LibWeb/TestConfig.ini
+++ b/Tests/LibWeb/TestConfig.ini
@@ -136,6 +136,9 @@ Text/input/wpt-import/html/syntax/parsing/html5lib_url.html
Text/input/wpt-import/html/syntax/parsing/html5lib_write.html
Text/input/wpt-import/html/syntax/parsing/html5lib_write_single.html
Text/input/wpt-import/wasm/serialization/module/window-simple-success.html
+Text/input/wpt-import/wasm/serialization/module/window-sharedworker-failure.html
+Text/input/wpt-import/wasm/serialization/module/window-cross-site-failure.html
+Text/input/wpt-import/wasm/serialization/module/window-same-site-success.sub.html
; The iframes they load need their .headers files to be served.
Text/input/wpt-import/html/syntax/xmldecl/xmldecl-1.html
diff --git a/Tests/LibWeb/TestStructuredSerializeCorpus.cpp b/Tests/LibWeb/TestStructuredSerializeCorpus.cpp
index 16c0af10c9e..355b8689e75 100644
--- a/Tests/LibWeb/TestStructuredSerializeCorpus.cpp
+++ b/Tests/LibWeb/TestStructuredSerializeCorpus.cpp
@@ -257,8 +257,6 @@ static Vector<CorpusEntry> build_corpus_entries()
add("serializable-ImageBitmap-display-p3"_string, image_bitmap_record(2, 2, 8, "BGRA8888"sv, "premultiplied"sv, { bitmap_pixels.data(), bitmap_pixels.size() }, { display_p3.data(), display_p3.size() }));
}
- add("serializable-Module"_string, webassembly_module_storage_record(s_minimal_webassembly_module_bytes.span()));
-
add("serializable-CryptoKey"_string, crypto_key_full_record("secret"sv, "deriveKey"sv, alg_key_algorithm("HKDF"sv), handle_byte_buffer("0123456789abcdef"sv.bytes())));
for (auto const& golden : crypto_algorithm_goldens())
add(MUST(String::formatted("cryptokey-algorithm-{}", to_underlying(golden.tag))), crypto_key_full_record(golden.type, golden.usage, golden.algorithm, golden.handle));
@@ -349,8 +347,12 @@ TEST_CASE(corpus_covers_the_stable_format_surface)
EXPECT(has_entry(*name));
}
- for (auto const& entry : Web::HTML::serializable_storage_registry())
+ for (auto const& entry : Web::HTML::serializable_storage_registry()) {
+ // A WebAssembly.Module is never serialized for storage.
+ if (entry.interface_name == Web::Bindings::InterfaceName::Module)
+ continue;
EXPECT(has_entry(MUST(String::formatted("serializable-{}", entry.identifier))));
+ }
for (auto const& expectation : Web::Crypto::s_key_algorithm_tag_expectations) {
if (expectation.expectation == Web::HTML::Expectation::PositiveGolden)
diff --git a/Tests/LibWeb/TestStructuredSerializeDurability.cpp b/Tests/LibWeb/TestStructuredSerializeDurability.cpp
index e56284edc99..d2ec0436cf3 100644
--- a/Tests/LibWeb/TestStructuredSerializeDurability.cpp
+++ b/Tests/LibWeb/TestStructuredSerializeDurability.cpp
@@ -32,7 +32,6 @@
#include <LibWeb/Geometry/DOMRectReadOnly.h>
#include <LibWeb/HTML/ImageBitmap.h>
#include <LibWeb/HTML/ImageData.h>
-#include <LibWeb/WebAssembly/Module.h>
#include <LibWeb/WebIDL/DOMException.h>
#include <LibWeb/WebIDL/QuotaExceededError.h>
@@ -586,16 +585,6 @@ TEST_CASE(image_data_over_a_shrunk_resizable_buffer_has_no_pixels)
EXPECT(image.bitmap().is_error());
}
-TEST_CASE(webassembly_module_decodes_from_frozen_bytes)
-{
- auto value = MUST(principal_storage_deserialize(webassembly_module_storage_record(s_minimal_webassembly_module_bytes.span())));
- auto module = GC::Ref { unwrap_wrappable<Web::WebAssembly::Module>(value) };
-
- auto compiled_module = module->compiled_module();
- EXPECT_EQ(compiled_module->module->import_count(), 0u);
- EXPECT_EQ(compiled_module->module->export_count(), 0u);
-}
-
TEST_CASE(crypto_key_algorithm_variants_decode_from_frozen_bytes)
{
for (auto const& golden : crypto_algorithm_goldens()) {
diff --git a/Tests/LibWeb/TestStructuredSerializeFormat.cpp b/Tests/LibWeb/TestStructuredSerializeFormat.cpp
index 377c0b44f1a..3980e02667e 100644
--- a/Tests/LibWeb/TestStructuredSerializeFormat.cpp
+++ b/Tests/LibWeb/TestStructuredSerializeFormat.cpp
@@ -9,9 +9,12 @@
#include <AK/ScopeGuard.h>
#include <LibCore/System.h>
#include <LibIPC/Limits.h>
+#include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/Array.h>
#include <LibJS/Runtime/ArrayBuffer.h>
#include <LibJS/Runtime/TypedArray.h>
+#include <LibWeb/Bindings/Intrinsics.h>
+#include <LibWeb/Bindings/Module.h>
#include <LibWeb/Bindings/Serializable.h>
#include <LibWeb/Crypto/CryptoKeySerializationTags.h>
#include <LibWeb/FileAPI/File.h>
@@ -23,7 +26,6 @@
#include <LibWeb/HTML/ImageBitmap.h>
#include <LibWeb/HTML/ImageData.h>
#include <LibWeb/HTML/MessagePort.h>
-#include <LibWeb/WebAssembly/Module.h>
#include <LibWeb/WebIDL/DOMException.h>
#include <LibWeb/WebIDL/QuotaExceededError.h>
@@ -464,15 +466,28 @@ TEST_CASE(ipc_serializable_object_has_no_version_framing)
TEST_CASE(webassembly_module_encodes_to_frozen_ipc_bytes)
{
- auto value = MUST(principal_storage_deserialize(webassembly_module_storage_record(s_minimal_webassembly_module_bytes.span())));
- auto module = GC::Ref { unwrap_wrappable<Web::WebAssembly::Module>(value) };
+ static constexpr auto module_bytes = to_array<u8>({ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00 });
+
+ auto& realm = principal_test_realm();
+ auto& vm = realm.vm();
+ auto& settings = Web::Bindings::principal_host_defined_environment_settings_object(realm);
+ auto depth = vm.execution_context_stack().size();
+ vm.push_execution_context(settings.realm_execution_context());
+
+ auto bytes = JS::ArrayBuffer::create(realm, MUST(ByteBuffer::copy(module_bytes.span())));
+ auto& module_constructor = Web::Bindings::ensure_web_constructor<Web::Bindings::ModulePrototype>(realm, "WebAssembly.Module"_utf16_fly_string);
+ auto module = MUST(JS::construct(vm, module_constructor, bytes.ptr()));
+ auto record = MUST(Web::HTML::structured_serialize(vm, JS::Value(module.ptr())));
+
+ while (vm.execution_context_stack().size() > depth)
+ vm.pop_execution_context();
- auto record = structured_serialize(test_realm().vm(), module);
Web::HTML::StructuredSerializeReader reader { record };
EXPECT_EQ(MUST(reader.decode<u8>()), to_underlying(ValueTag::SerializableObject));
EXPECT_EQ(MUST(reader.decode<Web::Bindings::InterfaceName>()), Web::Bindings::InterfaceName::Module);
- EXPECT_EQ(MUST(reader.decode<ByteBuffer>()).span(), s_minimal_webassembly_module_bytes.span());
+ EXPECT_EQ(MUST(reader.decode<ByteBuffer>()).span(), module_bytes.span());
+ EXPECT_EQ(MUST(reader.decode<Optional<u64>>()), settings.agent_cluster_id());
}
TEST_CASE(realm_helpers_share_vm_initialization)
diff --git a/Tests/LibWeb/Text/expected/wpt-import/wasm/serialization/module/serialization-via-idb.any.txt b/Tests/LibWeb/Text/expected/wpt-import/wasm/serialization/module/serialization-via-idb.any.txt
new file mode 100644
index 00000000000..711321a84a3
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/wasm/serialization/module/serialization-via-idb.any.txt
@@ -0,0 +1,7 @@
+Harness status: OK
+
+Found 2 tests
+
+2 Pass
+Pass WebAssembly.Module cloning via IndexedDB: basic case
+Pass WebAssembly.Module cloning via the IndexedDB: is interleaved correctly
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/wasm/serialization/module/window-cross-site-failure.txt b/Tests/LibWeb/Text/expected/wpt-import/wasm/serialization/module/window-cross-site-failure.txt
new file mode 100644
index 00000000000..53aa231f0e8
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/wasm/serialization/module/window-cross-site-failure.txt
@@ -0,0 +1,7 @@
+Harness status: OK
+
+Found 2 tests
+
+2 Pass
+Pass postMessaging a wasm module to a cross-site iframe fails
+Pass postMessaging a wasm module to a sandboxed iframe fails
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/wasm/serialization/module/window-same-site-success.sub.txt b/Tests/LibWeb/Text/expected/wpt-import/wasm/serialization/module/window-same-site-success.sub.txt
new file mode 100644
index 00000000000..acfbd807cd4
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/wasm/serialization/module/window-same-site-success.sub.txt
@@ -0,0 +1,7 @@
+Harness status: OK
+
+Found 2 tests
+
+2 Pass
+Pass postMessaging a wasm module to a same-site iframe on another host succeeds
+Pass postMessaging a wasm module to a same-site iframe on another port succeeds
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/wasm/serialization/module/window-sharedworker-failure.txt b/Tests/LibWeb/Text/expected/wpt-import/wasm/serialization/module/window-sharedworker-failure.txt
new file mode 100644
index 00000000000..f38a0b7fea1
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/wasm/serialization/module/window-sharedworker-failure.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Pass
+Pass WebAssembly.Modules cannot cross agent clusters, shared worker edition
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/wpt-import/wasm/serialization/module/resources/create-empty-wasm-module.js b/Tests/LibWeb/Text/input/wpt-import/wasm/serialization/module/resources/create-empty-wasm-module.js
new file mode 100644
index 00000000000..7326710c9e4
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/wasm/serialization/module/resources/create-empty-wasm-module.js
@@ -0,0 +1,4 @@
+function createEmptyWasmModule() {
+ return new WebAssembly.Module(
+ new Uint8Array([0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00]));
+}
diff --git a/Tests/LibWeb/Text/input/wpt-import/wasm/serialization/module/resources/incrementer-iframe-failure.html b/Tests/LibWeb/Text/input/wpt-import/wasm/serialization/module/resources/incrementer-iframe-failure.html
new file mode 100644
index 00000000000..5212a9ec72d
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/wasm/serialization/module/resources/incrementer-iframe-failure.html
@@ -0,0 +1,5 @@
+<title>A test page that is sent a WebAssembly Module cross-origin cannot receive it</title>
+
+<script>
+self.onmessageerror = () => parent.postMessage('messageerror received', "*");
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/wasm/serialization/module/resources/sharedworker-failure.js b/Tests/LibWeb/Text/input/wpt-import/wasm/serialization/module/resources/sharedworker-failure.js
new file mode 100644
index 00000000000..854c70b9e84
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/wasm/serialization/module/resources/sharedworker-failure.js
@@ -0,0 +1,21 @@
+importScripts("./test-incrementer.js");
+importScripts("./create-empty-wasm-module.js");
+
+let state = "send-sw-failure"
+onconnect = initialE => {
+ let port = initialE.source;
+ port.postMessage(state)
+ port.onmessage = e => {
+ if(state === "" && e.data === "send-window-failure") {
+ port.postMessage(createEmptyWasmModule())
+ } else {
+ port.postMessage("failure")
+ }
+ }
+ port.onmessageerror = e => {
+ if(state === "send-sw-failure") {
+ port.postMessage("send-sw-failure-success")
+ state = ""
+ }
+ }
+}
diff --git a/Tests/LibWeb/Text/input/wpt-import/wasm/serialization/module/serialization-via-idb.any.html b/Tests/LibWeb/Text/input/wpt-import/wasm/serialization/module/serialization-via-idb.any.html
new file mode 100644
index 00000000000..8941fbf14f0
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/wasm/serialization/module/serialization-via-idb.any.html
@@ -0,0 +1,15 @@
+<!doctype html>
+<meta charset=utf-8>
+
+<script>
+self.GLOBAL = {
+ isWindow: function() { return true; },
+ isWorker: function() { return false; },
+ isShadowRealm: function() { return false; },
+};
+</script>
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+<script src="../../../IndexedDB/resources/support.js"></script>
+<div id=log></div>
+<script src="../../../wasm/serialization/module/serialization-via-idb.any.js"></script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/wasm/serialization/module/serialization-via-idb.any.js b/Tests/LibWeb/Text/input/wpt-import/wasm/serialization/module/serialization-via-idb.any.js
new file mode 100644
index 00000000000..2591d2fe747
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/wasm/serialization/module/serialization-via-idb.any.js
@@ -0,0 +1,45 @@
+// META: script=/IndexedDB/resources/support.js
+"use strict";
+
+function createEmptyWasmModule() {
+ return new WebAssembly.Module(
+ new Uint8Array([0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00]));
+}
+
+async_test(t => {
+ const openReq = createdb(t);
+
+ openReq.onupgradeneeded = e => {
+ const db = e.target.result;
+ const store = db.createObjectStore("store", { keyPath: "key" });
+
+ assert_throws_dom("DataCloneError", () => {
+ store.put({ key: 1, property: createEmptyWasmModule() });
+ });
+ t.done();
+ };
+}, "WebAssembly.Module cloning via IndexedDB: basic case");
+
+async_test(t => {
+ const openReq = createdb(t);
+
+ openReq.onupgradeneeded = e => {
+ const db = e.target.result;
+ const store = db.createObjectStore("store", { keyPath: "key" });
+
+ let getter1Called = false;
+ let getter2Called = false;
+
+ assert_throws_dom("DataCloneError", () => {
+ store.put({ key: 1, property: [
+ { get x() { getter1Called = true; return 5; } },
+ createEmptyWasmModule(),
+ { get x() { getter2Called = true; return 5; } }
+ ]});
+ });
+
+ assert_true(getter1Called, "The getter before the WebAssembly.Module must have been called");
+ assert_false(getter2Called, "The getter after the WebAssembly.Module must not have been called");
+ t.done();
+ };
+}, "WebAssembly.Module cloning via the IndexedDB: is interleaved correctly");
diff --git a/Tests/LibWeb/Text/input/wpt-import/wasm/serialization/module/window-cross-site-failure.html b/Tests/LibWeb/Text/input/wpt-import/wasm/serialization/module/window-cross-site-failure.html
new file mode 100644
index 00000000000..6cfe23add45
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/wasm/serialization/module/window-cross-site-failure.html
@@ -0,0 +1,39 @@
+<title>Postmessage of a WebAssembly.Module cross-site fails with a messageerror</title>
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+<script src="../../../common/get-host-info.sub.js"></script>
+<script src="../../../service-workers/service-worker/resources/test-helpers.sub.js"></script>
+<script src="resources/test-incrementer.js"></script>
+
+<body>
+<script>
+async function testPostMessageErrorForOrigin(t, remoteOrigin, sandbox){
+ const iframe = document.createElement('iframe');
+ if (sandbox)
+ iframe.sandbox = sandbox;
+ iframe.src = `${remoteOrigin}${base_path()}resources/incrementer-iframe-failure.html`;
+ const iframeLoaded = new Promise(resolve => iframe.onload = resolve);
+ document.body.appendChild(iframe);
+ t.add_cleanup(() => {
+ iframe.remove();
+ });
+ await iframeLoaded;
+
+ const module = await createWasmModule();
+ const messageErrorReceived =
+ new Promise(resolve => window.onmessage = resolve);
+ iframe.contentWindow.postMessage({message: 'send module', module}, "*");
+ let reply = await messageErrorReceived;
+ assert_equals(reply.data, 'messageerror received');
+}
+
+promise_test(async t => {
+ const remoteOrigin = get_host_info().HTTP_NOTSAMESITE_ORIGIN;
+ await testPostMessageErrorForOrigin(t, remoteOrigin);
+}, "postMessaging a wasm module to a cross-site iframe fails");
+
+promise_test(async t => {
+ await testPostMessageErrorForOrigin(t, "", "allow-scripts");
+}, "postMessaging a wasm module to a sandboxed iframe fails");
+</script>
+</body>
diff --git a/Tests/LibWeb/Text/input/wpt-import/wasm/serialization/module/window-same-site-success.sub.html b/Tests/LibWeb/Text/input/wpt-import/wasm/serialization/module/window-same-site-success.sub.html
new file mode 100644
index 00000000000..a8403b499a8
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/wasm/serialization/module/window-same-site-success.sub.html
@@ -0,0 +1,29 @@
+<title>Postmessage of a WebAssembly.Module to a same-site cross-origin iframe succeeds without document.domain</title>
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+<script src="./resources/test-incrementer.js"></script>
+
+<body></body>
+
+<script>
+async function testSharingWithIframe(t, origin) {
+ const iframe = document.createElement("iframe");
+ iframe.src = `${origin}/wasm/serialization/module/resources/incrementer-iframe.html`;
+
+ // Instantiate and wait for the document to be loaded.
+ const iframeLoaded = new Promise(resolve => iframe.onload = resolve);
+ document.body.appendChild(iframe);
+ t.add_cleanup(() => iframe.remove());
+ await iframeLoaded;
+
+ await testSharingViaIncrementerScript(t, window, "window", iframe.contentWindow, "iframe", "*");
+}
+
+promise_test(async t => {
+ await testSharingWithIframe(t, "//{{domains[www1]}}:{{location[port]}}");
+}, "postMessaging a wasm module to a same-site iframe on another host succeeds");
+
+promise_test(async t => {
+ await testSharingWithIframe(t, "//{{host}}:{{ports[http][1]}}");
+}, "postMessaging a wasm module to a same-site iframe on another port succeeds");
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/wasm/serialization/module/window-sharedworker-failure.html b/Tests/LibWeb/Text/input/wpt-import/wasm/serialization/module/window-sharedworker-failure.html
new file mode 100644
index 00000000000..5b38f554976
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/wasm/serialization/module/window-sharedworker-failure.html
@@ -0,0 +1,33 @@
+<!doctype html>
+<!-- Based on similar tests in html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/ -->
+<title>WebAssembly.Modules cannot cross agent clusters, shared worker edition</title>
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+<script src="./resources/create-empty-wasm-module.js"></script>
+<script>
+async_test(t => {
+ const sw = new SharedWorker("resources/sharedworker-failure.js")
+ let state = ""
+ sw.port.onmessage = t.step_func(e => {
+ if(e.data === "send-sw-failure") {
+ sw.port.postMessage(createEmptyWasmModule())
+ } else if(e.data === "send-sw-failure-success") {
+ state = "send-window-failure"
+ sw.port.postMessage(state)
+ } else {
+ assert_unreached()
+ }
+ })
+ sw.port.onmessageerror = t.step_func(e => {
+ if(state === "send-window-failure") {
+ assert_equals(e.data, null, "data")
+ assert_equals(e.origin, "", "origin")
+ assert_equals(e.source, null, "source")
+ assert_equals(e.ports.length, 0, "ports length")
+ t.done()
+ } else {
+ assert_unreached()
+ }
+ })
+})
+</script>
diff --git a/Tests/LibWeb/test-inputs/structured-serialize-corpus/serializable-Module.bin b/Tests/LibWeb/test-inputs/structured-serialize-corpus/serializable-Module.bin
deleted file mode 100644
index ded2e2583cf..00000000000
Binary files a/Tests/LibWeb/test-inputs/structured-serialize-corpus/serializable-Module.bin and /dev/null differ