diff options
Diffstat (limited to 'js/src/jit-test/tests/wasm/gc/linking.js')
-rw-r--r-- | js/src/jit-test/tests/wasm/gc/linking.js | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/wasm/gc/linking.js b/js/src/jit-test/tests/wasm/gc/linking.js new file mode 100644 index 0000000000..586011219a --- /dev/null +++ b/js/src/jit-test/tests/wasm/gc/linking.js @@ -0,0 +1,72 @@ +// |jit-test| skip-if: !wasmGcEnabled() + +function linkGlobals(typeSection, exportInit, linkType) { + let {global} = wasmEvalText(`(module + ${typeSection} + (global (export "global") ${linkType} ${exportInit}) + )`).exports; + + wasmEvalText(`(module + ${typeSection} + (import "" "global" + (global ${linkType}) + ) + )`, {"": {global}}); +} + +function linkTables(typeSection, exportInit, linkType) { + let {table} = wasmEvalText(`(module + ${typeSection} + (table (export "table") ${linkType} (elem (${exportInit}))) + )`).exports; + + wasmEvalText(`(module + ${typeSection} + (import "" "table" + (table 0 1 ${linkType}) + ) + )`, {"": {table}}); +} + +function linkFuncs(typeSection, exportInit, linkType) { + let {func} = wasmEvalText(`(module + ${typeSection} + (func + (export "func") + (param ${linkType}) + (result ${linkType}) + unreachable + ) + )`).exports; + + wasmEvalText(`(module + ${typeSection} + (import "" "func" + (func (param ${linkType}) (result ${linkType})) + ) + )`, {"": {func}}); +} + +const TESTS = [ + [ + "(type (struct (field i32)))", + "ref.null 0", + "(ref null 0)", + ], + [ + "(type (array i32))", + "ref.null 0", + "(ref null 0)", + ], + [ + "(type (struct (field i32))) (type (struct (field (ref 0))))", + "ref.null 1", + "(ref null 1)", + ] +]; + +for (let test of TESTS) { + linkGlobals(...test); + linkTables(...test); + linkFuncs(...test); +} |