Skip to content

Commit 62e8e45

Browse files
committed
[Wasm-GC] Update "read the imports" part of JS API for globals
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
1 parent b541bbc commit 62e8e45

File tree

6 files changed

+413
-6
lines changed

6 files changed

+413
-6
lines changed

JSTests/wasm/gc/js-api.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,45 @@ function testImport() {
595595
"Argument value did not match reference type"
596596
);
597597
}
598+
599+
// Test direct global imports.
600+
{
601+
function doImport(type, val) {
602+
instantiate(`
603+
(module
604+
(type (struct))
605+
(type (array i32))
606+
(global (import "m" "g") (ref ${type}))
607+
)
608+
`,
609+
{ m: { g: val } });
610+
}
611+
function castError(type, val) {
612+
assert.throws(
613+
() => { doImport(type, val); },
614+
WebAssembly.LinkError,
615+
"Argument value did not match the reference type"
616+
);
617+
}
618+
let m = instantiate(`
619+
(module
620+
(type (struct))
621+
(type (array i32))
622+
(func (export "makeS") (result anyref) (struct.new 0))
623+
(func (export "makeA") (result anyref) (array.new_default 1 (i32.const 10)))
624+
)
625+
`);
626+
doImport("any", "foo");
627+
doImport("i31", 2 ** 30 - 1);
628+
doImport("i31", -(2 ** 30));
629+
castError("i31", 2.3);
630+
doImport("any", "foo");
631+
doImport("struct", m.exports.makeS());
632+
doImport("array", m.exports.makeA());
633+
doImport("0", m.exports.makeS());
634+
doImport("1", m.exports.makeA());
635+
castError("0", m.exports.makeA());
636+
}
598637
}
599638

600639
testArray();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
PASS anyref import
3+
PASS eqref import
4+
PASS structref import
5+
PASS arrayref import
6+
PASS i31ref import
7+
PASS funcref import
8+
PASS externref import
9+
PASS null import
10+
PASS concrete struct import
11+
PASS concrete array import
12+
PASS concrete func import
13+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<!-- webkit-test-runner [ jscOptions=--useWebAssemblyTypedFunctionReferences=true,--useWebAssemblyGC=true ] -->
2+
<!-- This file is required for WebKit test infrastructure to run the templated test -->

0 commit comments

Comments
 (0)