From 76ee1ce04cdef8785761f3c25200515ef67d9bb1 Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Fri, 25 Jul 2025 15:08:31 +0200 Subject: [PATCH] LibWeb: Support wasm module instantiation using a global address Fixes 1 WPT subtest in `wasm/core/simd`. --- Libraries/LibWeb/WebAssembly/WebAssembly.cpp | 7 +++++-- .../wasm/core/simd/simd_linking.wast.js.txt | 9 +++++++++ .../wasm/core/js/simd/simd_linking.wast.js | 12 ++++++++++++ .../wasm/core/simd/simd_linking.wast.js.html | 16 ++++++++++++++++ 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/wpt-import/wasm/core/simd/simd_linking.wast.js.txt create mode 100644 Tests/LibWeb/Text/input/wpt-import/wasm/core/js/simd/simd_linking.wast.js create mode 100644 Tests/LibWeb/Text/input/wpt-import/wasm/core/simd/simd_linking.wast.js.html diff --git a/Libraries/LibWeb/WebAssembly/WebAssembly.cpp b/Libraries/LibWeb/WebAssembly/WebAssembly.cpp index f02c479baeb..bc32eb9b6dd 100644 --- a/Libraries/LibWeb/WebAssembly/WebAssembly.cpp +++ b/Libraries/LibWeb/WebAssembly/WebAssembly.cpp @@ -342,8 +342,11 @@ JS::ThrowCompletionOr> instantiate_module(JS // 3.5.1.7. Set the surrounding agent's associated store to store. address = cache.abstract_machine().store().allocate({ type.type(), false }, cast_value); } - // FIXME: 3.5.2. Otherwise, if v implements Global, - // FIXME: 3.5.2.1. Let globaladdr be v.[[Global]]. + // 3.5.2. Otherwise, if v implements Global, + else if (import_.is_object() && is(import_.as_object())) { + // 3.5.2.1. Let globaladdr be v.[[Global]]. + address = as(import_.as_object()).address(); + } // 3.5.3. Otherwise, else { // 3.5.3.1. Throw a LinkError exception. diff --git a/Tests/LibWeb/Text/expected/wpt-import/wasm/core/simd/simd_linking.wast.js.txt b/Tests/LibWeb/Text/expected/wpt-import/wasm/core/simd/simd_linking.wast.js.txt new file mode 100644 index 00000000000..57e5876cf29 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/wasm/core/simd/simd_linking.wast.js.txt @@ -0,0 +1,9 @@ +Harness status: OK + +Found 4 tests + +4 Pass +Pass #1 Reinitialize the default imports +Pass #2 Reinitialize the default imports +Pass #3 Test that WebAssembly instantiation succeeds +Pass #4 Test that WebAssembly instantiation succeeds \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/wasm/core/js/simd/simd_linking.wast.js b/Tests/LibWeb/Text/input/wpt-import/wasm/core/js/simd/simd_linking.wast.js new file mode 100644 index 00000000000..368cf7cb927 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/wasm/core/js/simd/simd_linking.wast.js @@ -0,0 +1,12 @@ +(function simd_linking_wast_js() { + +// simd_linking.wast:1 +let $1 = instance("\x00\x61\x73\x6d\x01\x00\x00\x00\x06\xab\x80\x80\x80\x00\x02\x7b\x00\xfd\x0c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0b\x7b\x01\xfd\x0c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0b\x07\x94\x80\x80\x80\x00\x02\x06\x67\x2d\x76\x31\x32\x38\x03\x00\x07\x6d\x67\x2d\x76\x31\x32\x38\x03\x01"); + +// simd_linking.wast:5 +register("Mv128", $1) + +// simd_linking.wast:7 +let $2 = instance("\x00\x61\x73\x6d\x01\x00\x00\x00\x02\x92\x80\x80\x80\x00\x01\x05\x4d\x76\x31\x32\x38\x07\x6d\x67\x2d\x76\x31\x32\x38\x03\x7b\x01"); +reinitializeRegistry(); +})(); diff --git a/Tests/LibWeb/Text/input/wpt-import/wasm/core/simd/simd_linking.wast.js.html b/Tests/LibWeb/Text/input/wpt-import/wasm/core/simd/simd_linking.wast.js.html new file mode 100644 index 00000000000..c59ba012097 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/wasm/core/simd/simd_linking.wast.js.html @@ -0,0 +1,16 @@ + + + + + WebAssembly Web Platform Test + + + + + + + +
+ + +