diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/jit-test/tests/wasm/gc/externref-conversions.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/wasm/gc/externref-conversions.js')
-rw-r--r-- | js/src/jit-test/tests/wasm/gc/externref-conversions.js | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/wasm/gc/externref-conversions.js b/js/src/jit-test/tests/wasm/gc/externref-conversions.js new file mode 100644 index 0000000000..edfcbe9e4f --- /dev/null +++ b/js/src/jit-test/tests/wasm/gc/externref-conversions.js @@ -0,0 +1,94 @@ +// |jit-test| skip-if: !wasmGcEnabled() + +// Output type is non-nullable if the input type is non-nullable +wasmValidateText(`(module + (func (param externref) (result anyref) + local.get 0 + any.convert_extern + ) + (func (param anyref) (result externref) + local.get 0 + extern.convert_any + ) + (func (param (ref extern)) (result (ref any)) + local.get 0 + any.convert_extern + ) + (func (param (ref any)) (result (ref extern)) + local.get 0 + extern.convert_any + ) + (func (result (ref any)) + unreachable + any.convert_extern + ) + (func (result (ref extern)) + unreachable + extern.convert_any + ) +)`); + +// Output type is nullable if the input type is nullable +wasmFailValidateText(`(module + (func (param externref) (result (ref any)) + local.get 0 + any.convert_extern + ) +)`, /expected/); +wasmFailValidateText(`(module + (func (param anyref) (result (ref extern)) + local.get 0 + extern.convert_any + ) +)`, /expected/); + +// Can round trip an externref through anyref and get the same thing back +let {roundtripThroughAny} = wasmEvalText(`(module + (func (export "roundtripThroughAny") (param externref) (result externref) + local.get 0 + any.convert_extern + extern.convert_any + ) +)`).exports; +for (let value of WasmExternrefValues) { + assertEq(value, roundtripThroughAny(value)); +} + +// Can round trip GC objects through externref and get the same thing back +let {testStruct, testArray} = wasmEvalText(`(module + (type $struct (struct)) + (type $array (array i32)) + + (func (export "testStruct") (result i32) + (local (ref $struct)) + (local.set 0 struct.new $struct) + local.get 0 + (ref.eq + (ref.cast (ref null $struct) + (any.convert_extern + (extern.convert_any + local.get 0 + ) + ) + ) + ) + ) + + (func (export "testArray") (result i32) + (local (ref $array)) + (local.set 0 (array.new $array i32.const 0 i32.const 0)) + local.get 0 + (ref.eq + (ref.cast (ref null $array) + (any.convert_extern + (extern.convert_any + local.get 0 + ) + ) + ) + ) + ) +)`).exports; + +assertEq(testStruct(), 1); +assertEq(testArray(), 1); |