Skip to content

Commit

Permalink
[Wasm-GC] Update "read the imports" part of JS API for globals
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=264655

Reviewed by Justin Michaud.

The GC proposal JS API was recently updated
(WebAssembly/gc#467) to allow direct import of reftype
globals in more cases.

This patch also includes a version of the pending WPT tests for this case
(tracked upstream here: WebAssembly/gc#498) which
should be updated later if there are any changes in the accepted upstream
version.

* JSTests/wasm/gc/js-api.js:
(testImport.):
(testImport):
* LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/gc/global-import.tentative.any.js: Added.
(setup.doLink):
(setup):
(test):
* Source/JavaScriptCore/wasm/js/JSWebAssemblyHelpers.h:
(JSC::fromJSValue):
* Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp:
(JSC::WebAssemblyModuleRecord::initializeImports):

Canonical link: https://commits.webkit.org/272367@main
  • Loading branch information
takikawa committed Dec 20, 2023
1 parent b541bbc commit 62e8e45
Show file tree
Hide file tree
Showing 6 changed files with 413 additions and 6 deletions.
39 changes: 39 additions & 0 deletions JSTests/wasm/gc/js-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,45 @@ function testImport() {
"Argument value did not match reference type"
);
}

// Test direct global imports.
{
function doImport(type, val) {
instantiate(`
(module
(type (struct))
(type (array i32))
(global (import "m" "g") (ref ${type}))
)
`,
{ m: { g: val } });
}
function castError(type, val) {
assert.throws(
() => { doImport(type, val); },
WebAssembly.LinkError,
"Argument value did not match the reference type"
);
}
let m = instantiate(`
(module
(type (struct))
(type (array i32))
(func (export "makeS") (result anyref) (struct.new 0))
(func (export "makeA") (result anyref) (array.new_default 1 (i32.const 10)))
)
`);
doImport("any", "foo");
doImport("i31", 2 ** 30 - 1);
doImport("i31", -(2 ** 30));
castError("i31", 2.3);
doImport("any", "foo");
doImport("struct", m.exports.makeS());
doImport("array", m.exports.makeA());
doImport("0", m.exports.makeS());
doImport("1", m.exports.makeA());
castError("0", m.exports.makeA());
}
}

testArray();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

PASS anyref import
PASS eqref import
PASS structref import
PASS arrayref import
PASS i31ref import
PASS funcref import
PASS externref import
PASS null import
PASS concrete struct import
PASS concrete array import
PASS concrete func import

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!-- webkit-test-runner [ jscOptions=--useWebAssemblyTypedFunctionReferences=true,--useWebAssemblyGC=true ] -->
<!-- This file is required for WebKit test infrastructure to run the templated test -->
Loading

0 comments on commit 62e8e45

Please sign in to comment.