summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/wasm/gc/externref-conversions.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/jit-test/tests/wasm/gc/externref-conversions.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
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.js94
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..12c5a2bbcc
--- /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
+ extern.internalize
+ )
+ (func (param anyref) (result externref)
+ local.get 0
+ extern.externalize
+ )
+ (func (param (ref extern)) (result (ref any))
+ local.get 0
+ extern.internalize
+ )
+ (func (param (ref any)) (result (ref extern))
+ local.get 0
+ extern.externalize
+ )
+ (func (result (ref any))
+ unreachable
+ extern.internalize
+ )
+ (func (result (ref extern))
+ unreachable
+ extern.externalize
+ )
+)`);
+
+// Output type is nullable if the input type is nullable
+wasmFailValidateText(`(module
+ (func (param externref) (result (ref any))
+ local.get 0
+ extern.internalize
+ )
+)`, /expected/);
+wasmFailValidateText(`(module
+ (func (param anyref) (result (ref extern))
+ local.get 0
+ extern.externalize
+ )
+)`, /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
+ extern.internalize
+ extern.externalize
+ )
+)`).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)
+ (extern.internalize
+ (extern.externalize
+ 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)
+ (extern.internalize
+ (extern.externalize
+ local.get 0
+ )
+ )
+ )
+ )
+ )
+)`).exports;
+
+assertEq(testStruct(), 1);
+assertEq(testArray(), 1);