summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/wasm/spec/gc
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/jit-test/tests/wasm/spec/gc')
-rw-r--r--js/src/jit-test/tests/wasm/spec/gc/array.wast.js385
-rw-r--r--js/src/jit-test/tests/wasm/spec/gc/array_copy.wast.js202
-rw-r--r--js/src/jit-test/tests/wasm/spec/gc/array_fill.wast.js112
-rw-r--r--js/src/jit-test/tests/wasm/spec/gc/binary-gc.wast.js30
-rw-r--r--js/src/jit-test/tests/wasm/spec/gc/br_if.wast.js886
-rw-r--r--js/src/jit-test/tests/wasm/spec/gc/br_on_cast.wast.js337
-rw-r--r--js/src/jit-test/tests/wasm/spec/gc/br_on_cast_fail.wast.js352
-rw-r--r--js/src/jit-test/tests/wasm/spec/gc/comments.wast.js51
-rw-r--r--js/src/jit-test/tests/wasm/spec/gc/directives.txt1
-rw-r--r--js/src/jit-test/tests/wasm/spec/gc/extern.wast.js101
-rw-r--r--js/src/jit-test/tests/wasm/spec/gc/float_literals.wast.js776
-rw-r--r--js/src/jit-test/tests/wasm/spec/gc/global.wast.js869
-rw-r--r--js/src/jit-test/tests/wasm/spec/gc/harness/directives.txt1
-rw-r--r--js/src/jit-test/tests/wasm/spec/gc/harness/harness.js448
-rw-r--r--js/src/jit-test/tests/wasm/spec/gc/i31.wast.js104
-rw-r--r--js/src/jit-test/tests/wasm/spec/gc/if.wast.js1928
-rw-r--r--js/src/jit-test/tests/wasm/spec/gc/obsolete-keywords.wast.js82
-rw-r--r--js/src/jit-test/tests/wasm/spec/gc/ref_cast.wast.js279
-rw-r--r--js/src/jit-test/tests/wasm/spec/gc/ref_eq.wast.js351
-rw-r--r--js/src/jit-test/tests/wasm/spec/gc/ref_null.wast.js127
-rw-r--r--js/src/jit-test/tests/wasm/spec/gc/ref_test.wast.js470
-rw-r--r--js/src/jit-test/tests/wasm/spec/gc/struct.wast.js271
-rw-r--r--js/src/jit-test/tests/wasm/spec/gc/token.wast.js289
-rw-r--r--js/src/jit-test/tests/wasm/spec/gc/type-canon.wast.js36
-rw-r--r--js/src/jit-test/tests/wasm/spec/gc/type-equivalence.wast.js345
-rw-r--r--js/src/jit-test/tests/wasm/spec/gc/type-rec.wast.js189
-rw-r--r--js/src/jit-test/tests/wasm/spec/gc/type-subtyping.wast.js943
-rw-r--r--js/src/jit-test/tests/wasm/spec/gc/unreachable.wast.js424
-rw-r--r--js/src/jit-test/tests/wasm/spec/gc/unreached-valid.wast.js138
29 files changed, 10527 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/wasm/spec/gc/array.wast.js b/js/src/jit-test/tests/wasm/spec/gc/array.wast.js
new file mode 100644
index 0000000000..4161a6b5f9
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/spec/gc/array.wast.js
@@ -0,0 +1,385 @@
+/* Copyright 2021 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ./test/core/gc/array.wast
+
+// ./test/core/gc/array.wast:3
+let $0 = instantiate(`(module
+ (type (array i8))
+ (type (array i16))
+ (type (array i32))
+ (type (array i64))
+ (type (array f32))
+ (type (array f64))
+ (type (array anyref))
+ (type (array (ref struct)))
+ (type (array (ref 0)))
+ (type (array (ref null 1)))
+ (type (array (mut i8)))
+ (type (array (mut i16)))
+ (type (array (mut i32)))
+ (type (array (mut i64)))
+ (type (array (mut i32)))
+ (type (array (mut i64)))
+ (type (array (mut anyref)))
+ (type (array (mut (ref struct))))
+ (type (array (mut (ref 0))))
+ (type (array (mut (ref null i31))))
+)`);
+
+// ./test/core/gc/array.wast:27
+assert_invalid(
+ () => instantiate(`(module
+ (type (array (mut (ref null 10))))
+ )`),
+ `unknown type`,
+);
+
+// ./test/core/gc/array.wast:37
+let $1 = instantiate(`(module
+ (rec
+ (type $$s0 (array (ref $$s1)))
+ (type $$s1 (array (ref $$s0)))
+ )
+
+ (func (param (ref $$forward)))
+
+ (type $$forward (array i32))
+)`);
+
+// ./test/core/gc/array.wast:48
+assert_invalid(() => instantiate(`(module (type (array (ref 1))))`), `unknown type`);
+
+// ./test/core/gc/array.wast:52
+assert_invalid(() => instantiate(`(module (type (array (mut (ref 1)))))`), `unknown type`);
+
+// ./test/core/gc/array.wast:60
+let $2 = instantiate(`(module
+ (type $$vec (array f32))
+ (type $$mvec (array (mut f32)))
+
+ (global (ref $$vec) (array.new $$vec (f32.const 1) (i32.const 3)))
+ (global (ref $$vec) (array.new_default $$vec (i32.const 3)))
+
+ (func $$new (export "new") (result (ref $$vec))
+ (array.new_default $$vec (i32.const 3))
+ )
+
+ (func $$get (param $$i i32) (param $$v (ref $$vec)) (result f32)
+ (array.get $$vec (local.get $$v) (local.get $$i))
+ )
+ (func (export "get") (param $$i i32) (result f32)
+ (call $$get (local.get $$i) (call $$new))
+ )
+
+ (func $$set_get (param $$i i32) (param $$v (ref $$mvec)) (param $$y f32) (result f32)
+ (array.set $$mvec (local.get $$v) (local.get $$i) (local.get $$y))
+ (array.get $$mvec (local.get $$v) (local.get $$i))
+ )
+ (func (export "set_get") (param $$i i32) (param $$y f32) (result f32)
+ (call $$set_get (local.get $$i)
+ (array.new_default $$mvec (i32.const 3))
+ (local.get $$y)
+ )
+ )
+
+ (func $$len (param $$v (ref array)) (result i32)
+ (array.len (local.get $$v))
+ )
+ (func (export "len") (result i32)
+ (call $$len (call $$new))
+ )
+)`);
+
+// ./test/core/gc/array.wast:97
+assert_return(() => invoke($2, `new`, []), [new RefWithType('arrayref')]);
+
+// ./test/core/gc/array.wast:98
+assert_return(() => invoke($2, `new`, []), [new RefWithType('eqref')]);
+
+// ./test/core/gc/array.wast:99
+assert_return(() => invoke($2, `get`, [0]), [value("f32", 0)]);
+
+// ./test/core/gc/array.wast:100
+assert_return(() => invoke($2, `set_get`, [1, value("f32", 7)]), [value("f32", 7)]);
+
+// ./test/core/gc/array.wast:101
+assert_return(() => invoke($2, `len`, []), [value("i32", 3)]);
+
+// ./test/core/gc/array.wast:103
+assert_trap(() => invoke($2, `get`, [10]), `out of bounds array access`);
+
+// ./test/core/gc/array.wast:104
+assert_trap(() => invoke($2, `set_get`, [10, value("f32", 7)]), `out of bounds array access`);
+
+// ./test/core/gc/array.wast:106
+let $3 = instantiate(`(module
+ (type $$vec (array f32))
+ (type $$mvec (array (mut f32)))
+
+ (global (ref $$vec) (array.new_fixed $$vec 2 (f32.const 1) (f32.const 2)))
+
+ (func $$new (export "new") (result (ref $$vec))
+ (array.new_fixed $$vec 2 (f32.const 1) (f32.const 2))
+ )
+
+ (func $$get (param $$i i32) (param $$v (ref $$vec)) (result f32)
+ (array.get $$vec (local.get $$v) (local.get $$i))
+ )
+ (func (export "get") (param $$i i32) (result f32)
+ (call $$get (local.get $$i) (call $$new))
+ )
+
+ (func $$set_get (param $$i i32) (param $$v (ref $$mvec)) (param $$y f32) (result f32)
+ (array.set $$mvec (local.get $$v) (local.get $$i) (local.get $$y))
+ (array.get $$mvec (local.get $$v) (local.get $$i))
+ )
+ (func (export "set_get") (param $$i i32) (param $$y f32) (result f32)
+ (call $$set_get (local.get $$i)
+ (array.new_fixed $$mvec 3 (f32.const 1) (f32.const 2) (f32.const 3))
+ (local.get $$y)
+ )
+ )
+
+ (func $$len (param $$v (ref array)) (result i32)
+ (array.len (local.get $$v))
+ )
+ (func (export "len") (result i32)
+ (call $$len (call $$new))
+ )
+)`);
+
+// ./test/core/gc/array.wast:142
+assert_return(() => invoke($3, `new`, []), [new RefWithType('arrayref')]);
+
+// ./test/core/gc/array.wast:143
+assert_return(() => invoke($3, `new`, []), [new RefWithType('eqref')]);
+
+// ./test/core/gc/array.wast:144
+assert_return(() => invoke($3, `get`, [0]), [value("f32", 1)]);
+
+// ./test/core/gc/array.wast:145
+assert_return(() => invoke($3, `set_get`, [1, value("f32", 7)]), [value("f32", 7)]);
+
+// ./test/core/gc/array.wast:146
+assert_return(() => invoke($3, `len`, []), [value("i32", 2)]);
+
+// ./test/core/gc/array.wast:148
+assert_trap(() => invoke($3, `get`, [10]), `out of bounds array access`);
+
+// ./test/core/gc/array.wast:149
+assert_trap(() => invoke($3, `set_get`, [10, value("f32", 7)]), `out of bounds array access`);
+
+// ./test/core/gc/array.wast:151
+let $4 = instantiate(`(module
+ (type $$vec (array i8))
+ (type $$mvec (array (mut i8)))
+
+ (data $$d "\\00\\01\\02\\ff\\04")
+
+ (func $$new (export "new") (result (ref $$vec))
+ (array.new_data $$vec $$d (i32.const 1) (i32.const 3))
+ )
+
+ (func $$get_u (param $$i i32) (param $$v (ref $$vec)) (result i32)
+ (array.get_u $$vec (local.get $$v) (local.get $$i))
+ )
+ (func (export "get_u") (param $$i i32) (result i32)
+ (call $$get_u (local.get $$i) (call $$new))
+ )
+
+ (func $$get_s (param $$i i32) (param $$v (ref $$vec)) (result i32)
+ (array.get_s $$vec (local.get $$v) (local.get $$i))
+ )
+ (func (export "get_s") (param $$i i32) (result i32)
+ (call $$get_s (local.get $$i) (call $$new))
+ )
+
+ (func $$set_get (param $$i i32) (param $$v (ref $$mvec)) (param $$y i32) (result i32)
+ (array.set $$mvec (local.get $$v) (local.get $$i) (local.get $$y))
+ (array.get_u $$mvec (local.get $$v) (local.get $$i))
+ )
+ (func (export "set_get") (param $$i i32) (param $$y i32) (result i32)
+ (call $$set_get (local.get $$i)
+ (array.new_data $$mvec $$d (i32.const 1) (i32.const 3))
+ (local.get $$y)
+ )
+ )
+
+ (func $$len (param $$v (ref array)) (result i32)
+ (array.len (local.get $$v))
+ )
+ (func (export "len") (result i32)
+ (call $$len (call $$new))
+ )
+)`);
+
+// ./test/core/gc/array.wast:194
+assert_return(() => invoke($4, `new`, []), [new RefWithType('arrayref')]);
+
+// ./test/core/gc/array.wast:195
+assert_return(() => invoke($4, `new`, []), [new RefWithType('eqref')]);
+
+// ./test/core/gc/array.wast:196
+assert_return(() => invoke($4, `get_u`, [2]), [value("i32", 255)]);
+
+// ./test/core/gc/array.wast:197
+assert_return(() => invoke($4, `get_s`, [2]), [value("i32", -1)]);
+
+// ./test/core/gc/array.wast:198
+assert_return(() => invoke($4, `set_get`, [1, 7]), [value("i32", 7)]);
+
+// ./test/core/gc/array.wast:199
+assert_return(() => invoke($4, `len`, []), [value("i32", 3)]);
+
+// ./test/core/gc/array.wast:201
+assert_trap(() => invoke($4, `get_u`, [10]), `out of bounds array access`);
+
+// ./test/core/gc/array.wast:202
+assert_trap(() => invoke($4, `get_s`, [10]), `out of bounds array access`);
+
+// ./test/core/gc/array.wast:203
+assert_trap(() => invoke($4, `set_get`, [10, 7]), `out of bounds array access`);
+
+// ./test/core/gc/array.wast:205
+let $5 = instantiate(`(module
+ (type $$bvec (array i8))
+ (type $$vec (array (ref $$bvec)))
+ (type $$mvec (array (mut (ref $$bvec))))
+ (type $$nvec (array (ref null $$bvec)))
+ (type $$avec (array (mut anyref)))
+
+ (elem $$e (ref $$bvec)
+ (array.new $$bvec (i32.const 7) (i32.const 3))
+ (array.new_fixed $$bvec 2 (i32.const 1) (i32.const 2))
+ )
+
+ (func $$new (export "new") (result (ref $$vec))
+ (array.new_elem $$vec $$e (i32.const 0) (i32.const 2))
+ )
+
+ (func $$sub1 (result (ref $$nvec))
+ (array.new_elem $$nvec $$e (i32.const 0) (i32.const 2))
+ )
+ (func $$sub2 (result (ref $$avec))
+ (array.new_elem $$avec $$e (i32.const 0) (i32.const 2))
+ )
+
+ (func $$get (param $$i i32) (param $$j i32) (param $$v (ref $$vec)) (result i32)
+ (array.get_u $$bvec (array.get $$vec (local.get $$v) (local.get $$i)) (local.get $$j))
+ )
+ (func (export "get") (param $$i i32) (param $$j i32) (result i32)
+ (call $$get (local.get $$i) (local.get $$j) (call $$new))
+ )
+
+ (func $$set_get (param $$i i32) (param $$j i32) (param $$v (ref $$mvec)) (param $$y i32) (result i32)
+ (array.set $$mvec (local.get $$v) (local.get $$i) (array.get $$mvec (local.get $$v) (local.get $$y)))
+ (array.get_u $$bvec (array.get $$mvec (local.get $$v) (local.get $$i)) (local.get $$j))
+ )
+ (func (export "set_get") (param $$i i32) (param $$j i32) (param $$y i32) (result i32)
+ (call $$set_get (local.get $$i) (local.get $$j)
+ (array.new_elem $$mvec $$e (i32.const 0) (i32.const 2))
+ (local.get $$y)
+ )
+ )
+
+ (func $$len (param $$v (ref array)) (result i32)
+ (array.len (local.get $$v))
+ )
+ (func (export "len") (result i32)
+ (call $$len (call $$new))
+ )
+)`);
+
+// ./test/core/gc/array.wast:254
+assert_return(() => invoke($5, `new`, []), [new RefWithType('arrayref')]);
+
+// ./test/core/gc/array.wast:255
+assert_return(() => invoke($5, `new`, []), [new RefWithType('eqref')]);
+
+// ./test/core/gc/array.wast:256
+assert_return(() => invoke($5, `get`, [0, 0]), [value("i32", 7)]);
+
+// ./test/core/gc/array.wast:257
+assert_return(() => invoke($5, `get`, [1, 0]), [value("i32", 1)]);
+
+// ./test/core/gc/array.wast:258
+assert_return(() => invoke($5, `set_get`, [0, 1, 1]), [value("i32", 2)]);
+
+// ./test/core/gc/array.wast:259
+assert_return(() => invoke($5, `len`, []), [value("i32", 2)]);
+
+// ./test/core/gc/array.wast:261
+assert_trap(() => invoke($5, `get`, [10, 0]), `out of bounds array access`);
+
+// ./test/core/gc/array.wast:262
+assert_trap(() => invoke($5, `set_get`, [10, 0, 0]), `out of bounds array access`);
+
+// ./test/core/gc/array.wast:264
+assert_invalid(
+ () => instantiate(`(module
+ (type $$a (array i64))
+ (func (export "array.set-immutable") (param $$a (ref $$a))
+ (array.set $$a (local.get $$a) (i32.const 0) (i64.const 1))
+ )
+ )`),
+ `array is immutable`,
+);
+
+// ./test/core/gc/array.wast:274
+assert_invalid(
+ () => instantiate(`(module
+ (type $$bvec (array i8))
+
+ (data $$d "\\00\\01\\02\\03\\04")
+
+ (global (ref $$bvec)
+ (array.new_data $$bvec $$d (i32.const 1) (i32.const 3))
+ )
+ )`),
+ `constant expression required`,
+);
+
+// ./test/core/gc/array.wast:287
+assert_invalid(
+ () => instantiate(`(module
+ (type $$bvec (array i8))
+ (type $$vvec (array (ref $$bvec)))
+
+ (elem $$e (ref $$bvec) (ref.null $$bvec))
+
+ (global (ref $$vvec)
+ (array.new_elem $$vvec $$e (i32.const 0) (i32.const 1))
+ )
+ )`),
+ `constant expression required`,
+);
+
+// ./test/core/gc/array.wast:304
+let $6 = instantiate(`(module
+ (type $$t (array (mut i32)))
+ (func (export "array.get-null")
+ (local (ref null $$t)) (drop (array.get $$t (local.get 0) (i32.const 0)))
+ )
+ (func (export "array.set-null")
+ (local (ref null $$t)) (array.set $$t (local.get 0) (i32.const 0) (i32.const 0))
+ )
+)`);
+
+// ./test/core/gc/array.wast:314
+assert_trap(() => invoke($6, `array.get-null`, []), `null array reference`);
+
+// ./test/core/gc/array.wast:315
+assert_trap(() => invoke($6, `array.set-null`, []), `null array reference`);
diff --git a/js/src/jit-test/tests/wasm/spec/gc/array_copy.wast.js b/js/src/jit-test/tests/wasm/spec/gc/array_copy.wast.js
new file mode 100644
index 0000000000..0109df19e9
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/spec/gc/array_copy.wast.js
@@ -0,0 +1,202 @@
+/* Copyright 2021 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ./test/core/gc/array_copy.wast
+
+// ./test/core/gc/array_copy.wast:5
+assert_invalid(
+ () => instantiate(`(module
+ (type $$a (array i8))
+ (type $$b (array (mut i8)))
+
+ (func (export "array.copy-immutable") (param $$1 (ref $$a)) (param $$2 (ref $$b))
+ (array.copy $$a $$b (local.get $$1) (i32.const 0) (local.get $$2) (i32.const 0) (i32.const 0))
+ )
+ )`),
+ `array is immutable`,
+);
+
+// ./test/core/gc/array_copy.wast:17
+assert_invalid(
+ () => instantiate(`(module
+ (type $$a (array (mut i8)))
+ (type $$b (array i16))
+
+ (func (export "array.copy-packed-invalid") (param $$1 (ref $$a)) (param $$2 (ref $$b))
+ (array.copy $$a $$b (local.get $$1) (i32.const 0) (local.get $$2) (i32.const 0) (i32.const 0))
+ )
+ )`),
+ `array types do not match`,
+);
+
+// ./test/core/gc/array_copy.wast:29
+assert_invalid(
+ () => instantiate(`(module
+ (type $$a (array (mut i8)))
+ (type $$b (array (mut (ref $$a))))
+
+ (func (export "array.copy-ref-invalid-1") (param $$1 (ref $$a)) (param $$2 (ref $$b))
+ (array.copy $$a $$b (local.get $$1) (i32.const 0) (local.get $$2) (i32.const 0) (i32.const 0))
+ )
+ )`),
+ `array types do not match`,
+);
+
+// ./test/core/gc/array_copy.wast:41
+assert_invalid(
+ () => instantiate(`(module
+ (type $$a (array (mut i8)))
+ (type $$b (array (mut (ref $$a))))
+ (type $$c (array (mut (ref $$b))))
+
+ (func (export "array.copy-ref-invalid-1") (param $$1 (ref $$b)) (param $$2 (ref $$c))
+ (array.copy $$b $$c (local.get $$1) (i32.const 0) (local.get $$2) (i32.const 0) (i32.const 0))
+ )
+ )`),
+ `array types do not match`,
+);
+
+// ./test/core/gc/array_copy.wast:54
+let $0 = instantiate(`(module
+ (type $$arr8 (array i8))
+ (type $$arr8_mut (array (mut i8)))
+
+ (global $$g_arr8 (ref $$arr8) (array.new $$arr8 (i32.const 10) (i32.const 12)))
+ (global $$g_arr8_mut (mut (ref $$arr8_mut)) (array.new_default $$arr8_mut (i32.const 12)))
+
+ (data $$d1 "abcdefghijkl")
+
+ (func (export "array_get_nth") (param $$1 i32) (result i32)
+ (array.get_u $$arr8_mut (global.get $$g_arr8_mut) (local.get $$1))
+ )
+
+ (func (export "array_copy-null-left")
+ (array.copy $$arr8_mut $$arr8 (ref.null $$arr8_mut) (i32.const 0) (global.get $$g_arr8) (i32.const 0) (i32.const 0))
+ )
+
+ (func (export "array_copy-null-right")
+ (array.copy $$arr8_mut $$arr8 (global.get $$g_arr8_mut) (i32.const 0) (ref.null $$arr8) (i32.const 0) (i32.const 0))
+ )
+
+ (func (export "array_copy") (param $$1 i32) (param $$2 i32) (param $$3 i32)
+ (array.copy $$arr8_mut $$arr8 (global.get $$g_arr8_mut) (local.get $$1) (global.get $$g_arr8) (local.get $$2) (local.get $$3))
+ )
+
+ (func (export "array_copy_overlap_test-1")
+ (local $$1 (ref $$arr8_mut))
+ (array.new_data $$arr8_mut $$d1 (i32.const 0) (i32.const 12))
+ (local.set $$1)
+ (array.copy $$arr8_mut $$arr8_mut (local.get $$1) (i32.const 1) (local.get $$1) (i32.const 0) (i32.const 11))
+ (global.set $$g_arr8_mut (local.get $$1))
+ )
+
+ (func (export "array_copy_overlap_test-2")
+ (local $$1 (ref $$arr8_mut))
+ (array.new_data $$arr8_mut $$d1 (i32.const 0) (i32.const 12))
+ (local.set $$1)
+ (array.copy $$arr8_mut $$arr8_mut (local.get $$1) (i32.const 0) (local.get $$1) (i32.const 1) (i32.const 11))
+ (global.set $$g_arr8_mut (local.get $$1))
+ )
+)`);
+
+// ./test/core/gc/array_copy.wast:97
+assert_trap(() => invoke($0, `array_copy-null-left`, []), `null array reference`);
+
+// ./test/core/gc/array_copy.wast:98
+assert_trap(() => invoke($0, `array_copy-null-right`, []), `null array reference`);
+
+// ./test/core/gc/array_copy.wast:101
+assert_trap(() => invoke($0, `array_copy`, [13, 0, 0]), `out of bounds array access`);
+
+// ./test/core/gc/array_copy.wast:102
+assert_trap(() => invoke($0, `array_copy`, [0, 13, 0]), `out of bounds array access`);
+
+// ./test/core/gc/array_copy.wast:105
+assert_trap(() => invoke($0, `array_copy`, [0, 0, 13]), `out of bounds array access`);
+
+// ./test/core/gc/array_copy.wast:106
+assert_trap(() => invoke($0, `array_copy`, [0, 0, 13]), `out of bounds array access`);
+
+// ./test/core/gc/array_copy.wast:109
+assert_return(() => invoke($0, `array_copy`, [12, 0, 0]), []);
+
+// ./test/core/gc/array_copy.wast:110
+assert_return(() => invoke($0, `array_copy`, [0, 12, 0]), []);
+
+// ./test/core/gc/array_copy.wast:113
+assert_return(() => invoke($0, `array_get_nth`, [0]), [value("i32", 0)]);
+
+// ./test/core/gc/array_copy.wast:114
+assert_return(() => invoke($0, `array_get_nth`, [5]), [value("i32", 0)]);
+
+// ./test/core/gc/array_copy.wast:115
+assert_return(() => invoke($0, `array_get_nth`, [11]), [value("i32", 0)]);
+
+// ./test/core/gc/array_copy.wast:116
+assert_trap(() => invoke($0, `array_get_nth`, [12]), `out of bounds array access`);
+
+// ./test/core/gc/array_copy.wast:119
+assert_return(() => invoke($0, `array_copy`, [0, 0, 2]), []);
+
+// ./test/core/gc/array_copy.wast:120
+assert_return(() => invoke($0, `array_get_nth`, [0]), [value("i32", 10)]);
+
+// ./test/core/gc/array_copy.wast:121
+assert_return(() => invoke($0, `array_get_nth`, [1]), [value("i32", 10)]);
+
+// ./test/core/gc/array_copy.wast:122
+assert_return(() => invoke($0, `array_get_nth`, [2]), [value("i32", 0)]);
+
+// ./test/core/gc/array_copy.wast:125
+assert_return(() => invoke($0, `array_copy_overlap_test-1`, []), []);
+
+// ./test/core/gc/array_copy.wast:126
+assert_return(() => invoke($0, `array_get_nth`, [0]), [value("i32", 97)]);
+
+// ./test/core/gc/array_copy.wast:127
+assert_return(() => invoke($0, `array_get_nth`, [1]), [value("i32", 97)]);
+
+// ./test/core/gc/array_copy.wast:128
+assert_return(() => invoke($0, `array_get_nth`, [2]), [value("i32", 98)]);
+
+// ./test/core/gc/array_copy.wast:129
+assert_return(() => invoke($0, `array_get_nth`, [5]), [value("i32", 101)]);
+
+// ./test/core/gc/array_copy.wast:130
+assert_return(() => invoke($0, `array_get_nth`, [10]), [value("i32", 106)]);
+
+// ./test/core/gc/array_copy.wast:131
+assert_return(() => invoke($0, `array_get_nth`, [11]), [value("i32", 107)]);
+
+// ./test/core/gc/array_copy.wast:133
+assert_return(() => invoke($0, `array_copy_overlap_test-2`, []), []);
+
+// ./test/core/gc/array_copy.wast:134
+assert_return(() => invoke($0, `array_get_nth`, [0]), [value("i32", 98)]);
+
+// ./test/core/gc/array_copy.wast:135
+assert_return(() => invoke($0, `array_get_nth`, [1]), [value("i32", 99)]);
+
+// ./test/core/gc/array_copy.wast:136
+assert_return(() => invoke($0, `array_get_nth`, [5]), [value("i32", 103)]);
+
+// ./test/core/gc/array_copy.wast:137
+assert_return(() => invoke($0, `array_get_nth`, [9]), [value("i32", 107)]);
+
+// ./test/core/gc/array_copy.wast:138
+assert_return(() => invoke($0, `array_get_nth`, [10]), [value("i32", 108)]);
+
+// ./test/core/gc/array_copy.wast:139
+assert_return(() => invoke($0, `array_get_nth`, [11]), [value("i32", 108)]);
diff --git a/js/src/jit-test/tests/wasm/spec/gc/array_fill.wast.js b/js/src/jit-test/tests/wasm/spec/gc/array_fill.wast.js
new file mode 100644
index 0000000000..271b1690c4
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/spec/gc/array_fill.wast.js
@@ -0,0 +1,112 @@
+/* Copyright 2021 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ./test/core/gc/array_fill.wast
+
+// ./test/core/gc/array_fill.wast:5
+assert_invalid(
+ () => instantiate(`(module
+ (type $$a (array i8))
+
+ (func (export "array.fill-immutable") (param $$1 (ref $$a)) (param $$2 i32)
+ (array.fill $$a (local.get $$1) (i32.const 0) (local.get $$2) (i32.const 0))
+ )
+ )`),
+ `array is immutable`,
+);
+
+// ./test/core/gc/array_fill.wast:16
+assert_invalid(
+ () => instantiate(`(module
+ (type $$a (array (mut i8)))
+
+ (func (export "array.fill-invalid-1") (param $$1 (ref $$a)) (param $$2 funcref)
+ (array.fill $$a (local.get $$1) (i32.const 0) (local.get $$2) (i32.const 0))
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/gc/array_fill.wast:27
+assert_invalid(
+ () => instantiate(`(module
+ (type $$b (array (mut funcref)))
+
+ (func (export "array.fill-invalid-1") (param $$1 (ref $$b)) (param $$2 i32)
+ (array.fill $$b (local.get $$1) (i32.const 0) (local.get $$2) (i32.const 0))
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/gc/array_fill.wast:38
+let $0 = instantiate(`(module
+ (type $$arr8 (array i8))
+ (type $$arr8_mut (array (mut i8)))
+
+ (global $$g_arr8 (ref $$arr8) (array.new $$arr8 (i32.const 10) (i32.const 12)))
+ (global $$g_arr8_mut (mut (ref $$arr8_mut)) (array.new_default $$arr8_mut (i32.const 12)))
+
+ (func (export "array_get_nth") (param $$1 i32) (result i32)
+ (array.get_u $$arr8_mut (global.get $$g_arr8_mut) (local.get $$1))
+ )
+
+ (func (export "array_fill-null")
+ (array.fill $$arr8_mut (ref.null $$arr8_mut) (i32.const 0) (i32.const 0) (i32.const 0))
+ )
+
+ (func (export "array_fill") (param $$1 i32) (param $$2 i32) (param $$3 i32)
+ (array.fill $$arr8_mut (global.get $$g_arr8_mut) (local.get $$1) (local.get $$2) (local.get $$3))
+ )
+)`);
+
+// ./test/core/gc/array_fill.wast:59
+assert_trap(() => invoke($0, `array_fill-null`, []), `null array reference`);
+
+// ./test/core/gc/array_fill.wast:62
+assert_trap(() => invoke($0, `array_fill`, [13, 0, 0]), `out of bounds array access`);
+
+// ./test/core/gc/array_fill.wast:65
+assert_trap(() => invoke($0, `array_fill`, [0, 0, 13]), `out of bounds array access`);
+
+// ./test/core/gc/array_fill.wast:68
+assert_return(() => invoke($0, `array_fill`, [12, 0, 0]), []);
+
+// ./test/core/gc/array_fill.wast:71
+assert_return(() => invoke($0, `array_get_nth`, [0]), [value("i32", 0)]);
+
+// ./test/core/gc/array_fill.wast:72
+assert_return(() => invoke($0, `array_get_nth`, [5]), [value("i32", 0)]);
+
+// ./test/core/gc/array_fill.wast:73
+assert_return(() => invoke($0, `array_get_nth`, [11]), [value("i32", 0)]);
+
+// ./test/core/gc/array_fill.wast:74
+assert_trap(() => invoke($0, `array_get_nth`, [12]), `out of bounds array access`);
+
+// ./test/core/gc/array_fill.wast:77
+assert_return(() => invoke($0, `array_fill`, [2, 11, 2]), []);
+
+// ./test/core/gc/array_fill.wast:78
+assert_return(() => invoke($0, `array_get_nth`, [1]), [value("i32", 0)]);
+
+// ./test/core/gc/array_fill.wast:79
+assert_return(() => invoke($0, `array_get_nth`, [2]), [value("i32", 11)]);
+
+// ./test/core/gc/array_fill.wast:80
+assert_return(() => invoke($0, `array_get_nth`, [3]), [value("i32", 11)]);
+
+// ./test/core/gc/array_fill.wast:81
+assert_return(() => invoke($0, `array_get_nth`, [4]), [value("i32", 0)]);
diff --git a/js/src/jit-test/tests/wasm/spec/gc/binary-gc.wast.js b/js/src/jit-test/tests/wasm/spec/gc/binary-gc.wast.js
new file mode 100644
index 0000000000..e63be7b2fd
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/spec/gc/binary-gc.wast.js
@@ -0,0 +1,30 @@
+/* Copyright 2021 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ./test/core/gc/binary-gc.wast
+
+// ./test/core/gc/binary-gc.wast:1
+assert_malformed(
+ () => instantiate(`(module binary
+ "\\00asm" "\\01\\00\\00\\00"
+ "\\01" ;; Type section id
+ "\\04" ;; Type section length
+ "\\01" ;; Types vector length
+ "\\5e" ;; Array type, -0x22
+ "\\78" ;; Storage type: i8 or -0x08
+ "\\02" ;; Mutability, should be 0 or 1, but isn't
+ )`),
+ `malformed mutability`,
+);
diff --git a/js/src/jit-test/tests/wasm/spec/gc/br_if.wast.js b/js/src/jit-test/tests/wasm/spec/gc/br_if.wast.js
new file mode 100644
index 0000000000..511ee003fb
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/spec/gc/br_if.wast.js
@@ -0,0 +1,886 @@
+/* Copyright 2021 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ./test/core/br_if.wast
+
+// ./test/core/br_if.wast:3
+let $0 = instantiate(`(module
+ (func $$dummy)
+
+ (func (export "type-i32")
+ (block (drop (i32.ctz (br_if 0 (i32.const 0) (i32.const 1)))))
+ )
+ (func (export "type-i64")
+ (block (drop (i64.ctz (br_if 0 (i64.const 0) (i32.const 1)))))
+ )
+ (func (export "type-f32")
+ (block (drop (f32.neg (br_if 0 (f32.const 0) (i32.const 1)))))
+ )
+ (func (export "type-f64")
+ (block (drop (f64.neg (br_if 0 (f64.const 0) (i32.const 1)))))
+ )
+
+ (func (export "type-i32-value") (result i32)
+ (block (result i32) (i32.ctz (br_if 0 (i32.const 1) (i32.const 1))))
+ )
+ (func (export "type-i64-value") (result i64)
+ (block (result i64) (i64.ctz (br_if 0 (i64.const 2) (i32.const 1))))
+ )
+ (func (export "type-f32-value") (result f32)
+ (block (result f32) (f32.neg (br_if 0 (f32.const 3) (i32.const 1))))
+ )
+ (func (export "type-f64-value") (result f64)
+ (block (result f64) (f64.neg (br_if 0 (f64.const 4) (i32.const 1))))
+ )
+
+ (func (export "as-block-first") (param i32) (result i32)
+ (block (br_if 0 (local.get 0)) (return (i32.const 2))) (i32.const 3)
+ )
+ (func (export "as-block-mid") (param i32) (result i32)
+ (block (call $$dummy) (br_if 0 (local.get 0)) (return (i32.const 2)))
+ (i32.const 3)
+ )
+ (func (export "as-block-last") (param i32)
+ (block (call $$dummy) (call $$dummy) (br_if 0 (local.get 0)))
+ )
+ (func (export "as-block-first-value") (param i32) (result i32)
+ (block (result i32)
+ (drop (br_if 0 (i32.const 10) (local.get 0))) (return (i32.const 11))
+ )
+ )
+ (func (export "as-block-mid-value") (param i32) (result i32)
+ (block (result i32)
+ (call $$dummy)
+ (drop (br_if 0 (i32.const 20) (local.get 0)))
+ (return (i32.const 21))
+ )
+ )
+ (func (export "as-block-last-value") (param i32) (result i32)
+ (block (result i32)
+ (call $$dummy) (call $$dummy) (br_if 0 (i32.const 11) (local.get 0))
+ )
+ )
+
+ (func (export "as-loop-first") (param i32) (result i32)
+ (block (loop (br_if 1 (local.get 0)) (return (i32.const 2)))) (i32.const 3)
+ )
+ (func (export "as-loop-mid") (param i32) (result i32)
+ (block (loop (call $$dummy) (br_if 1 (local.get 0)) (return (i32.const 2))))
+ (i32.const 4)
+ )
+ (func (export "as-loop-last") (param i32)
+ (loop (call $$dummy) (br_if 1 (local.get 0)))
+ )
+
+ (func (export "as-br-value") (result i32)
+ (block (result i32) (br 0 (br_if 0 (i32.const 1) (i32.const 2))))
+ )
+
+ (func (export "as-br_if-cond")
+ (block (br_if 0 (br_if 0 (i32.const 1) (i32.const 1))))
+ )
+ (func (export "as-br_if-value") (result i32)
+ (block (result i32)
+ (drop (br_if 0 (br_if 0 (i32.const 1) (i32.const 2)) (i32.const 3)))
+ (i32.const 4)
+ )
+ )
+ (func (export "as-br_if-value-cond") (param i32) (result i32)
+ (block (result i32)
+ (drop (br_if 0 (i32.const 2) (br_if 0 (i32.const 1) (local.get 0))))
+ (i32.const 4)
+ )
+ )
+
+ (func (export "as-br_table-index")
+ (block (br_table 0 0 0 (br_if 0 (i32.const 1) (i32.const 2))))
+ )
+ (func (export "as-br_table-value") (result i32)
+ (block (result i32)
+ (br_table 0 0 0 (br_if 0 (i32.const 1) (i32.const 2)) (i32.const 3)) (i32.const 4)
+ )
+ )
+ (func (export "as-br_table-value-index") (result i32)
+ (block (result i32)
+ (br_table 0 0 (i32.const 2) (br_if 0 (i32.const 1) (i32.const 3))) (i32.const 4)
+ )
+ )
+ (func (export "as-return-value") (result i64)
+ (block (result i64) (return (br_if 0 (i64.const 1) (i32.const 2))))
+ )
+
+ (func (export "as-if-cond") (param i32) (result i32)
+ (block (result i32)
+ (if (result i32)
+ (br_if 0 (i32.const 1) (local.get 0))
+ (then (i32.const 2))
+ (else (i32.const 3))
+ )
+ )
+ )
+ (func (export "as-if-then") (param i32 i32)
+ (block
+ (if (local.get 0) (then (br_if 1 (local.get 1))) (else (call $$dummy)))
+ )
+ )
+ (func (export "as-if-else") (param i32 i32)
+ (block
+ (if (local.get 0) (then (call $$dummy)) (else (br_if 1 (local.get 1))))
+ )
+ )
+
+ (func (export "as-select-first") (param i32) (result i32)
+ (block (result i32)
+ (select (br_if 0 (i32.const 3) (i32.const 10)) (i32.const 2) (local.get 0))
+ )
+ )
+ (func (export "as-select-second") (param i32) (result i32)
+ (block (result i32)
+ (select (i32.const 1) (br_if 0 (i32.const 3) (i32.const 10)) (local.get 0))
+ )
+ )
+ (func (export "as-select-cond") (result i32)
+ (block (result i32)
+ (select (i32.const 1) (i32.const 2) (br_if 0 (i32.const 3) (i32.const 10)))
+ )
+ )
+
+ (func $$f (param i32 i32 i32) (result i32) (i32.const -1))
+ (func (export "as-call-first") (result i32)
+ (block (result i32)
+ (call $$f
+ (br_if 0 (i32.const 12) (i32.const 1)) (i32.const 2) (i32.const 3)
+ )
+ )
+ )
+ (func (export "as-call-mid") (result i32)
+ (block (result i32)
+ (call $$f
+ (i32.const 1) (br_if 0 (i32.const 13) (i32.const 1)) (i32.const 3)
+ )
+ )
+ )
+ (func (export "as-call-last") (result i32)
+ (block (result i32)
+ (call $$f
+ (i32.const 1) (i32.const 2) (br_if 0 (i32.const 14) (i32.const 1))
+ )
+ )
+ )
+
+ (func $$func (param i32 i32 i32) (result i32) (local.get 0))
+ (type $$check (func (param i32 i32 i32) (result i32)))
+ (table funcref (elem $$func))
+ (func (export "as-call_indirect-func") (result i32)
+ (block (result i32)
+ (call_indirect (type $$check)
+ (br_if 0 (i32.const 4) (i32.const 10))
+ (i32.const 1) (i32.const 2) (i32.const 0)
+ )
+ )
+ )
+
+ (func (export "as-call_indirect-first") (result i32)
+ (block (result i32)
+ (call_indirect (type $$check)
+ (i32.const 1) (br_if 0 (i32.const 4) (i32.const 10)) (i32.const 2) (i32.const 0)
+ )
+ )
+ )
+ (func (export "as-call_indirect-mid") (result i32)
+ (block (result i32)
+ (call_indirect (type $$check)
+ (i32.const 1) (i32.const 2) (br_if 0 (i32.const 4) (i32.const 10)) (i32.const 0)
+ )
+ )
+ )
+ (func (export "as-call_indirect-last") (result i32)
+ (block (result i32)
+ (call_indirect (type $$check)
+ (i32.const 1) (i32.const 2) (i32.const 3) (br_if 0 (i32.const 4) (i32.const 10))
+ )
+ )
+ )
+
+ (func (export "as-local.set-value") (param i32) (result i32)
+ (local i32)
+ (block (result i32)
+ (local.set 0 (br_if 0 (i32.const 17) (local.get 0)))
+ (i32.const -1)
+ )
+ )
+ (func (export "as-local.tee-value") (param i32) (result i32)
+ (block (result i32)
+ (local.tee 0 (br_if 0 (i32.const 1) (local.get 0)))
+ (return (i32.const -1))
+ )
+ )
+ (global $$a (mut i32) (i32.const 10))
+ (func (export "as-global.set-value") (param i32) (result i32)
+ (block (result i32)
+ (global.set $$a (br_if 0 (i32.const 1) (local.get 0)))
+ (return (i32.const -1))
+ )
+ )
+
+ (memory 1)
+ (func (export "as-load-address") (result i32)
+ (block (result i32) (i32.load (br_if 0 (i32.const 1) (i32.const 1))))
+ )
+ (func (export "as-loadN-address") (result i32)
+ (block (result i32) (i32.load8_s (br_if 0 (i32.const 30) (i32.const 1))))
+ )
+
+ (func (export "as-store-address") (result i32)
+ (block (result i32)
+ (i32.store (br_if 0 (i32.const 30) (i32.const 1)) (i32.const 7)) (i32.const -1)
+ )
+ )
+ (func (export "as-store-value") (result i32)
+ (block (result i32)
+ (i32.store (i32.const 2) (br_if 0 (i32.const 31) (i32.const 1))) (i32.const -1)
+ )
+ )
+
+ (func (export "as-storeN-address") (result i32)
+ (block (result i32)
+ (i32.store8 (br_if 0 (i32.const 32) (i32.const 1)) (i32.const 7)) (i32.const -1)
+ )
+ )
+ (func (export "as-storeN-value") (result i32)
+ (block (result i32)
+ (i32.store16 (i32.const 2) (br_if 0 (i32.const 33) (i32.const 1))) (i32.const -1)
+ )
+ )
+
+ (func (export "as-unary-operand") (result f64)
+ (block (result f64) (f64.neg (br_if 0 (f64.const 1.0) (i32.const 1))))
+ )
+ (func (export "as-binary-left") (result i32)
+ (block (result i32) (i32.add (br_if 0 (i32.const 1) (i32.const 1)) (i32.const 10)))
+ )
+ (func (export "as-binary-right") (result i32)
+ (block (result i32) (i32.sub (i32.const 10) (br_if 0 (i32.const 1) (i32.const 1))))
+ )
+ (func (export "as-test-operand") (result i32)
+ (block (result i32) (i32.eqz (br_if 0 (i32.const 0) (i32.const 1))))
+ )
+ (func (export "as-compare-left") (result i32)
+ (block (result i32) (i32.le_u (br_if 0 (i32.const 1) (i32.const 1)) (i32.const 10)))
+ )
+ (func (export "as-compare-right") (result i32)
+ (block (result i32) (i32.ne (i32.const 10) (br_if 0 (i32.const 1) (i32.const 42))))
+ )
+
+ (func (export "as-memory.grow-size") (result i32)
+ (block (result i32) (memory.grow (br_if 0 (i32.const 1) (i32.const 1))))
+ )
+
+ (func (export "nested-block-value") (param i32) (result i32)
+ (i32.add
+ (i32.const 1)
+ (block (result i32)
+ (drop (i32.const 2))
+ (i32.add
+ (i32.const 4)
+ (block (result i32)
+ (drop (br_if 1 (i32.const 8) (local.get 0)))
+ (i32.const 16)
+ )
+ )
+ )
+ )
+ )
+
+ (func (export "nested-br-value") (param i32) (result i32)
+ (i32.add
+ (i32.const 1)
+ (block (result i32)
+ (drop (i32.const 2))
+ (br 0
+ (block (result i32)
+ (drop (br_if 1 (i32.const 8) (local.get 0))) (i32.const 4)
+ )
+ )
+ (i32.const 16)
+ )
+ )
+ )
+
+ (func (export "nested-br_if-value") (param i32) (result i32)
+ (i32.add
+ (i32.const 1)
+ (block (result i32)
+ (drop (i32.const 2))
+ (drop (br_if 0
+ (block (result i32)
+ (drop (br_if 1 (i32.const 8) (local.get 0))) (i32.const 4)
+ )
+ (i32.const 1)
+ ))
+ (i32.const 16)
+ )
+ )
+ )
+
+ (func (export "nested-br_if-value-cond") (param i32) (result i32)
+ (i32.add
+ (i32.const 1)
+ (block (result i32)
+ (drop (i32.const 2))
+ (drop (br_if 0
+ (i32.const 4)
+ (block (result i32)
+ (drop (br_if 1 (i32.const 8) (local.get 0))) (i32.const 1)
+ )
+ ))
+ (i32.const 16)
+ )
+ )
+ )
+
+ (func (export "nested-br_table-value") (param i32) (result i32)
+ (i32.add
+ (i32.const 1)
+ (block (result i32)
+ (drop (i32.const 2))
+ (br_table 0
+ (block (result i32)
+ (drop (br_if 1 (i32.const 8) (local.get 0))) (i32.const 4)
+ )
+ (i32.const 1)
+ )
+ (i32.const 16)
+ )
+ )
+ )
+
+ (func (export "nested-br_table-value-index") (param i32) (result i32)
+ (i32.add
+ (i32.const 1)
+ (block (result i32)
+ (drop (i32.const 2))
+ (br_table 0
+ (i32.const 4)
+ (block (result i32)
+ (drop (br_if 1 (i32.const 8) (local.get 0))) (i32.const 1)
+ )
+ )
+ (i32.const 16)
+ )
+ )
+ )
+
+)`);
+
+// ./test/core/br_if.wast:372
+assert_return(() => invoke($0, `type-i32`, []), []);
+
+// ./test/core/br_if.wast:373
+assert_return(() => invoke($0, `type-i64`, []), []);
+
+// ./test/core/br_if.wast:374
+assert_return(() => invoke($0, `type-f32`, []), []);
+
+// ./test/core/br_if.wast:375
+assert_return(() => invoke($0, `type-f64`, []), []);
+
+// ./test/core/br_if.wast:377
+assert_return(() => invoke($0, `type-i32-value`, []), [value("i32", 1)]);
+
+// ./test/core/br_if.wast:378
+assert_return(() => invoke($0, `type-i64-value`, []), [value("i64", 2n)]);
+
+// ./test/core/br_if.wast:379
+assert_return(() => invoke($0, `type-f32-value`, []), [value("f32", 3)]);
+
+// ./test/core/br_if.wast:380
+assert_return(() => invoke($0, `type-f64-value`, []), [value("f64", 4)]);
+
+// ./test/core/br_if.wast:382
+assert_return(() => invoke($0, `as-block-first`, [0]), [value("i32", 2)]);
+
+// ./test/core/br_if.wast:383
+assert_return(() => invoke($0, `as-block-first`, [1]), [value("i32", 3)]);
+
+// ./test/core/br_if.wast:384
+assert_return(() => invoke($0, `as-block-mid`, [0]), [value("i32", 2)]);
+
+// ./test/core/br_if.wast:385
+assert_return(() => invoke($0, `as-block-mid`, [1]), [value("i32", 3)]);
+
+// ./test/core/br_if.wast:386
+assert_return(() => invoke($0, `as-block-last`, [0]), []);
+
+// ./test/core/br_if.wast:387
+assert_return(() => invoke($0, `as-block-last`, [1]), []);
+
+// ./test/core/br_if.wast:389
+assert_return(() => invoke($0, `as-block-first-value`, [0]), [value("i32", 11)]);
+
+// ./test/core/br_if.wast:390
+assert_return(() => invoke($0, `as-block-first-value`, [1]), [value("i32", 10)]);
+
+// ./test/core/br_if.wast:391
+assert_return(() => invoke($0, `as-block-mid-value`, [0]), [value("i32", 21)]);
+
+// ./test/core/br_if.wast:392
+assert_return(() => invoke($0, `as-block-mid-value`, [1]), [value("i32", 20)]);
+
+// ./test/core/br_if.wast:393
+assert_return(() => invoke($0, `as-block-last-value`, [0]), [value("i32", 11)]);
+
+// ./test/core/br_if.wast:394
+assert_return(() => invoke($0, `as-block-last-value`, [1]), [value("i32", 11)]);
+
+// ./test/core/br_if.wast:396
+assert_return(() => invoke($0, `as-loop-first`, [0]), [value("i32", 2)]);
+
+// ./test/core/br_if.wast:397
+assert_return(() => invoke($0, `as-loop-first`, [1]), [value("i32", 3)]);
+
+// ./test/core/br_if.wast:398
+assert_return(() => invoke($0, `as-loop-mid`, [0]), [value("i32", 2)]);
+
+// ./test/core/br_if.wast:399
+assert_return(() => invoke($0, `as-loop-mid`, [1]), [value("i32", 4)]);
+
+// ./test/core/br_if.wast:400
+assert_return(() => invoke($0, `as-loop-last`, [0]), []);
+
+// ./test/core/br_if.wast:401
+assert_return(() => invoke($0, `as-loop-last`, [1]), []);
+
+// ./test/core/br_if.wast:403
+assert_return(() => invoke($0, `as-br-value`, []), [value("i32", 1)]);
+
+// ./test/core/br_if.wast:405
+assert_return(() => invoke($0, `as-br_if-cond`, []), []);
+
+// ./test/core/br_if.wast:406
+assert_return(() => invoke($0, `as-br_if-value`, []), [value("i32", 1)]);
+
+// ./test/core/br_if.wast:407
+assert_return(() => invoke($0, `as-br_if-value-cond`, [0]), [value("i32", 2)]);
+
+// ./test/core/br_if.wast:408
+assert_return(() => invoke($0, `as-br_if-value-cond`, [1]), [value("i32", 1)]);
+
+// ./test/core/br_if.wast:410
+assert_return(() => invoke($0, `as-br_table-index`, []), []);
+
+// ./test/core/br_if.wast:411
+assert_return(() => invoke($0, `as-br_table-value`, []), [value("i32", 1)]);
+
+// ./test/core/br_if.wast:412
+assert_return(() => invoke($0, `as-br_table-value-index`, []), [value("i32", 1)]);
+
+// ./test/core/br_if.wast:414
+assert_return(() => invoke($0, `as-return-value`, []), [value("i64", 1n)]);
+
+// ./test/core/br_if.wast:416
+assert_return(() => invoke($0, `as-if-cond`, [0]), [value("i32", 2)]);
+
+// ./test/core/br_if.wast:417
+assert_return(() => invoke($0, `as-if-cond`, [1]), [value("i32", 1)]);
+
+// ./test/core/br_if.wast:418
+assert_return(() => invoke($0, `as-if-then`, [0, 0]), []);
+
+// ./test/core/br_if.wast:419
+assert_return(() => invoke($0, `as-if-then`, [4, 0]), []);
+
+// ./test/core/br_if.wast:420
+assert_return(() => invoke($0, `as-if-then`, [0, 1]), []);
+
+// ./test/core/br_if.wast:421
+assert_return(() => invoke($0, `as-if-then`, [4, 1]), []);
+
+// ./test/core/br_if.wast:422
+assert_return(() => invoke($0, `as-if-else`, [0, 0]), []);
+
+// ./test/core/br_if.wast:423
+assert_return(() => invoke($0, `as-if-else`, [3, 0]), []);
+
+// ./test/core/br_if.wast:424
+assert_return(() => invoke($0, `as-if-else`, [0, 1]), []);
+
+// ./test/core/br_if.wast:425
+assert_return(() => invoke($0, `as-if-else`, [3, 1]), []);
+
+// ./test/core/br_if.wast:427
+assert_return(() => invoke($0, `as-select-first`, [0]), [value("i32", 3)]);
+
+// ./test/core/br_if.wast:428
+assert_return(() => invoke($0, `as-select-first`, [1]), [value("i32", 3)]);
+
+// ./test/core/br_if.wast:429
+assert_return(() => invoke($0, `as-select-second`, [0]), [value("i32", 3)]);
+
+// ./test/core/br_if.wast:430
+assert_return(() => invoke($0, `as-select-second`, [1]), [value("i32", 3)]);
+
+// ./test/core/br_if.wast:431
+assert_return(() => invoke($0, `as-select-cond`, []), [value("i32", 3)]);
+
+// ./test/core/br_if.wast:433
+assert_return(() => invoke($0, `as-call-first`, []), [value("i32", 12)]);
+
+// ./test/core/br_if.wast:434
+assert_return(() => invoke($0, `as-call-mid`, []), [value("i32", 13)]);
+
+// ./test/core/br_if.wast:435
+assert_return(() => invoke($0, `as-call-last`, []), [value("i32", 14)]);
+
+// ./test/core/br_if.wast:437
+assert_return(() => invoke($0, `as-call_indirect-func`, []), [value("i32", 4)]);
+
+// ./test/core/br_if.wast:438
+assert_return(() => invoke($0, `as-call_indirect-first`, []), [value("i32", 4)]);
+
+// ./test/core/br_if.wast:439
+assert_return(() => invoke($0, `as-call_indirect-mid`, []), [value("i32", 4)]);
+
+// ./test/core/br_if.wast:440
+assert_return(() => invoke($0, `as-call_indirect-last`, []), [value("i32", 4)]);
+
+// ./test/core/br_if.wast:442
+assert_return(() => invoke($0, `as-local.set-value`, [0]), [value("i32", -1)]);
+
+// ./test/core/br_if.wast:443
+assert_return(() => invoke($0, `as-local.set-value`, [1]), [value("i32", 17)]);
+
+// ./test/core/br_if.wast:445
+assert_return(() => invoke($0, `as-local.tee-value`, [0]), [value("i32", -1)]);
+
+// ./test/core/br_if.wast:446
+assert_return(() => invoke($0, `as-local.tee-value`, [1]), [value("i32", 1)]);
+
+// ./test/core/br_if.wast:448
+assert_return(() => invoke($0, `as-global.set-value`, [0]), [value("i32", -1)]);
+
+// ./test/core/br_if.wast:449
+assert_return(() => invoke($0, `as-global.set-value`, [1]), [value("i32", 1)]);
+
+// ./test/core/br_if.wast:451
+assert_return(() => invoke($0, `as-load-address`, []), [value("i32", 1)]);
+
+// ./test/core/br_if.wast:452
+assert_return(() => invoke($0, `as-loadN-address`, []), [value("i32", 30)]);
+
+// ./test/core/br_if.wast:454
+assert_return(() => invoke($0, `as-store-address`, []), [value("i32", 30)]);
+
+// ./test/core/br_if.wast:455
+assert_return(() => invoke($0, `as-store-value`, []), [value("i32", 31)]);
+
+// ./test/core/br_if.wast:456
+assert_return(() => invoke($0, `as-storeN-address`, []), [value("i32", 32)]);
+
+// ./test/core/br_if.wast:457
+assert_return(() => invoke($0, `as-storeN-value`, []), [value("i32", 33)]);
+
+// ./test/core/br_if.wast:459
+assert_return(() => invoke($0, `as-unary-operand`, []), [value("f64", 1)]);
+
+// ./test/core/br_if.wast:460
+assert_return(() => invoke($0, `as-binary-left`, []), [value("i32", 1)]);
+
+// ./test/core/br_if.wast:461
+assert_return(() => invoke($0, `as-binary-right`, []), [value("i32", 1)]);
+
+// ./test/core/br_if.wast:462
+assert_return(() => invoke($0, `as-test-operand`, []), [value("i32", 0)]);
+
+// ./test/core/br_if.wast:463
+assert_return(() => invoke($0, `as-compare-left`, []), [value("i32", 1)]);
+
+// ./test/core/br_if.wast:464
+assert_return(() => invoke($0, `as-compare-right`, []), [value("i32", 1)]);
+
+// ./test/core/br_if.wast:465
+assert_return(() => invoke($0, `as-memory.grow-size`, []), [value("i32", 1)]);
+
+// ./test/core/br_if.wast:467
+assert_return(() => invoke($0, `nested-block-value`, [0]), [value("i32", 21)]);
+
+// ./test/core/br_if.wast:468
+assert_return(() => invoke($0, `nested-block-value`, [1]), [value("i32", 9)]);
+
+// ./test/core/br_if.wast:469
+assert_return(() => invoke($0, `nested-br-value`, [0]), [value("i32", 5)]);
+
+// ./test/core/br_if.wast:470
+assert_return(() => invoke($0, `nested-br-value`, [1]), [value("i32", 9)]);
+
+// ./test/core/br_if.wast:471
+assert_return(() => invoke($0, `nested-br_if-value`, [0]), [value("i32", 5)]);
+
+// ./test/core/br_if.wast:472
+assert_return(() => invoke($0, `nested-br_if-value`, [1]), [value("i32", 9)]);
+
+// ./test/core/br_if.wast:473
+assert_return(() => invoke($0, `nested-br_if-value-cond`, [0]), [value("i32", 5)]);
+
+// ./test/core/br_if.wast:474
+assert_return(() => invoke($0, `nested-br_if-value-cond`, [1]), [value("i32", 9)]);
+
+// ./test/core/br_if.wast:475
+assert_return(() => invoke($0, `nested-br_table-value`, [0]), [value("i32", 5)]);
+
+// ./test/core/br_if.wast:476
+assert_return(() => invoke($0, `nested-br_table-value`, [1]), [value("i32", 9)]);
+
+// ./test/core/br_if.wast:477
+assert_return(() => invoke($0, `nested-br_table-value-index`, [0]), [value("i32", 5)]);
+
+// ./test/core/br_if.wast:478
+assert_return(() => invoke($0, `nested-br_table-value-index`, [1]), [value("i32", 9)]);
+
+// ./test/core/br_if.wast:480
+assert_invalid(
+ () => instantiate(`(module (func $$type-false-i32 (block (i32.ctz (br_if 0 (i32.const 0))))))`),
+ `type mismatch`,
+);
+
+// ./test/core/br_if.wast:484
+assert_invalid(
+ () => instantiate(`(module (func $$type-false-i64 (block (i64.ctz (br_if 0 (i32.const 0))))))`),
+ `type mismatch`,
+);
+
+// ./test/core/br_if.wast:488
+assert_invalid(
+ () => instantiate(`(module (func $$type-false-f32 (block (f32.neg (br_if 0 (i32.const 0))))))`),
+ `type mismatch`,
+);
+
+// ./test/core/br_if.wast:492
+assert_invalid(
+ () => instantiate(`(module (func $$type-false-f64 (block (f64.neg (br_if 0 (i32.const 0))))))`),
+ `type mismatch`,
+);
+
+// ./test/core/br_if.wast:497
+assert_invalid(
+ () => instantiate(`(module (func $$type-true-i32 (block (i32.ctz (br_if 0 (i32.const 1))))))`),
+ `type mismatch`,
+);
+
+// ./test/core/br_if.wast:501
+assert_invalid(
+ () => instantiate(`(module (func $$type-true-i64 (block (i64.ctz (br_if 0 (i64.const 1))))))`),
+ `type mismatch`,
+);
+
+// ./test/core/br_if.wast:505
+assert_invalid(
+ () => instantiate(`(module (func $$type-true-f32 (block (f32.neg (br_if 0 (f32.const 1))))))`),
+ `type mismatch`,
+);
+
+// ./test/core/br_if.wast:509
+assert_invalid(
+ () => instantiate(`(module (func $$type-true-f64 (block (f64.neg (br_if 0 (i64.const 1))))))`),
+ `type mismatch`,
+);
+
+// ./test/core/br_if.wast:514
+assert_invalid(
+ () => instantiate(`(module (func $$type-false-arg-void-vs-num (result i32)
+ (block (result i32) (br_if 0 (i32.const 0)) (i32.const 1))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/br_if.wast:520
+assert_invalid(
+ () => instantiate(`(module (func $$type-true-arg-void-vs-num (result i32)
+ (block (result i32) (br_if 0 (i32.const 1)) (i32.const 1))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/br_if.wast:526
+assert_invalid(
+ () => instantiate(`(module (func $$type-false-arg-num-vs-void
+ (block (br_if 0 (i32.const 0) (i32.const 0)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/br_if.wast:532
+assert_invalid(
+ () => instantiate(`(module (func $$type-true-arg-num-vs-void
+ (block (br_if 0 (i32.const 0) (i32.const 1)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/br_if.wast:539
+assert_invalid(
+ () => instantiate(`(module (func $$type-false-arg-void-vs-num (result i32)
+ (block (result i32) (br_if 0 (nop) (i32.const 0)) (i32.const 1))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/br_if.wast:545
+assert_invalid(
+ () => instantiate(`(module (func $$type-true-arg-void-vs-num (result i32)
+ (block (result i32) (br_if 0 (nop) (i32.const 1)) (i32.const 1))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/br_if.wast:551
+assert_invalid(
+ () => instantiate(`(module (func $$type-false-arg-num-vs-num (result i32)
+ (block (result i32)
+ (drop (br_if 0 (i64.const 1) (i32.const 0))) (i32.const 1)
+ )
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/br_if.wast:559
+assert_invalid(
+ () => instantiate(`(module (func $$type-true-arg-num-vs-num (result i32)
+ (block (result i32)
+ (drop (br_if 0 (i64.const 1) (i32.const 0))) (i32.const 1)
+ )
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/br_if.wast:568
+assert_invalid(
+ () => instantiate(`(module (func $$type-cond-empty-vs-i32
+ (block (br_if 0))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/br_if.wast:574
+assert_invalid(
+ () => instantiate(`(module (func $$type-cond-void-vs-i32
+ (block (br_if 0 (nop)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/br_if.wast:580
+assert_invalid(
+ () => instantiate(`(module (func $$type-cond-num-vs-i32
+ (block (br_if 0 (i64.const 0)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/br_if.wast:586
+assert_invalid(
+ () => instantiate(`(module (func $$type-arg-cond-void-vs-i32 (result i32)
+ (block (result i32) (br_if 0 (i32.const 0) (nop)) (i32.const 1))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/br_if.wast:592
+assert_invalid(
+ () => instantiate(`(module (func $$type-arg-void-vs-num-nested (result i32)
+ (block (result i32) (i32.const 0) (block (br_if 1 (i32.const 1))))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/br_if.wast:598
+assert_invalid(
+ () => instantiate(`(module (func $$type-arg-cond-num-vs-i32 (result i32)
+ (block (result i32) (br_if 0 (i32.const 0) (i64.const 0)) (i32.const 1))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/br_if.wast:605
+assert_invalid(
+ () => instantiate(`(module
+ (func $$type-1st-cond-empty-in-then
+ (block
+ (i32.const 0) (i32.const 0)
+ (if (result i32) (then (br_if 0)))
+ )
+ (i32.eqz) (drop)
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/br_if.wast:617
+assert_invalid(
+ () => instantiate(`(module
+ (func $$type-2nd-cond-empty-in-then
+ (block
+ (i32.const 0) (i32.const 0)
+ (if (result i32) (then (br_if 0 (i32.const 1))))
+ )
+ (i32.eqz) (drop)
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/br_if.wast:629
+assert_invalid(
+ () => instantiate(`(module
+ (func $$type-1st-cond-empty-in-return
+ (block (result i32)
+ (return (br_if 0))
+ )
+ (i32.eqz) (drop)
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/br_if.wast:640
+assert_invalid(
+ () => instantiate(`(module
+ (func $$type-2nd-cond-empty-in-return
+ (block (result i32)
+ (return (br_if 0 (i32.const 1)))
+ )
+ (i32.eqz) (drop)
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/br_if.wast:653
+assert_invalid(
+ () => instantiate(`(module (func $$unbound-label (br_if 1 (i32.const 1))))`),
+ `unknown label`,
+);
+
+// ./test/core/br_if.wast:657
+assert_invalid(
+ () => instantiate(`(module (func $$unbound-nested-label (block (block (br_if 5 (i32.const 1))))))`),
+ `unknown label`,
+);
+
+// ./test/core/br_if.wast:661
+assert_invalid(
+ () => instantiate(`(module (func $$large-label (br_if 0x10000001 (i32.const 1))))`),
+ `unknown label`,
+);
diff --git a/js/src/jit-test/tests/wasm/spec/gc/br_on_cast.wast.js b/js/src/jit-test/tests/wasm/spec/gc/br_on_cast.wast.js
new file mode 100644
index 0000000000..23ea05818a
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/spec/gc/br_on_cast.wast.js
@@ -0,0 +1,337 @@
+/* Copyright 2021 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ./test/core/gc/br_on_cast.wast
+
+// ./test/core/gc/br_on_cast.wast:3
+let $0 = instantiate(`(module
+ (type $$ft (func (result i32)))
+ (type $$st (struct (field i16)))
+ (type $$at (array i8))
+
+ (table 10 anyref)
+
+ (elem declare func $$f)
+ (func $$f (result i32) (i32.const 9))
+
+ (func (export "init") (param $$x externref)
+ (table.set (i32.const 0) (ref.null any))
+ (table.set (i32.const 1) (ref.i31 (i32.const 7)))
+ (table.set (i32.const 2) (struct.new $$st (i32.const 6)))
+ (table.set (i32.const 3) (array.new $$at (i32.const 5) (i32.const 3)))
+ (table.set (i32.const 4) (any.convert_extern (local.get $$x)))
+ )
+
+ (func (export "br_on_null") (param $$i i32) (result i32)
+ (block $$l
+ (br_on_null $$l (table.get (local.get $$i)))
+ (return (i32.const -1))
+ )
+ (i32.const 0)
+ )
+ (func (export "br_on_i31") (param $$i i32) (result i32)
+ (block $$l (result (ref i31))
+ (br_on_cast $$l anyref (ref i31) (table.get (local.get $$i)))
+ (return (i32.const -1))
+ )
+ (i31.get_u)
+ )
+ (func (export "br_on_struct") (param $$i i32) (result i32)
+ (block $$l (result (ref struct))
+ (br_on_cast $$l anyref (ref struct) (table.get (local.get $$i)))
+ (return (i32.const -1))
+ )
+ (block $$l2 (param structref) (result (ref $$st))
+ (block $$l3 (param structref) (result (ref $$at))
+ (br_on_cast $$l2 structref (ref $$st))
+ (br_on_cast $$l3 anyref (ref $$at))
+ (return (i32.const -2))
+ )
+ (return (array.get_u $$at (i32.const 0)))
+ )
+ (struct.get_s $$st 0)
+ )
+ (func (export "br_on_array") (param $$i i32) (result i32)
+ (block $$l (result (ref array))
+ (br_on_cast $$l anyref (ref array) (table.get (local.get $$i)))
+ (return (i32.const -1))
+ )
+ (array.len)
+ )
+
+ (func (export "null-diff") (param $$i i32) (result i32)
+ (block $$l (result (ref null struct))
+ (block (result (ref any))
+ (br_on_cast $$l (ref null any) (ref null struct) (table.get (local.get $$i)))
+ )
+ (return (i32.const 0))
+ )
+ (return (i32.const 1))
+ )
+)`);
+
+// ./test/core/gc/br_on_cast.wast:69
+invoke($0, `init`, [externref(0)]);
+
+// ./test/core/gc/br_on_cast.wast:71
+assert_return(() => invoke($0, `br_on_null`, [0]), [value("i32", 0)]);
+
+// ./test/core/gc/br_on_cast.wast:72
+assert_return(() => invoke($0, `br_on_null`, [1]), [value("i32", -1)]);
+
+// ./test/core/gc/br_on_cast.wast:73
+assert_return(() => invoke($0, `br_on_null`, [2]), [value("i32", -1)]);
+
+// ./test/core/gc/br_on_cast.wast:74
+assert_return(() => invoke($0, `br_on_null`, [3]), [value("i32", -1)]);
+
+// ./test/core/gc/br_on_cast.wast:75
+assert_return(() => invoke($0, `br_on_null`, [4]), [value("i32", -1)]);
+
+// ./test/core/gc/br_on_cast.wast:77
+assert_return(() => invoke($0, `br_on_i31`, [0]), [value("i32", -1)]);
+
+// ./test/core/gc/br_on_cast.wast:78
+assert_return(() => invoke($0, `br_on_i31`, [1]), [value("i32", 7)]);
+
+// ./test/core/gc/br_on_cast.wast:79
+assert_return(() => invoke($0, `br_on_i31`, [2]), [value("i32", -1)]);
+
+// ./test/core/gc/br_on_cast.wast:80
+assert_return(() => invoke($0, `br_on_i31`, [3]), [value("i32", -1)]);
+
+// ./test/core/gc/br_on_cast.wast:81
+assert_return(() => invoke($0, `br_on_i31`, [4]), [value("i32", -1)]);
+
+// ./test/core/gc/br_on_cast.wast:83
+assert_return(() => invoke($0, `br_on_struct`, [0]), [value("i32", -1)]);
+
+// ./test/core/gc/br_on_cast.wast:84
+assert_return(() => invoke($0, `br_on_struct`, [1]), [value("i32", -1)]);
+
+// ./test/core/gc/br_on_cast.wast:85
+assert_return(() => invoke($0, `br_on_struct`, [2]), [value("i32", 6)]);
+
+// ./test/core/gc/br_on_cast.wast:86
+assert_return(() => invoke($0, `br_on_struct`, [3]), [value("i32", -1)]);
+
+// ./test/core/gc/br_on_cast.wast:87
+assert_return(() => invoke($0, `br_on_struct`, [4]), [value("i32", -1)]);
+
+// ./test/core/gc/br_on_cast.wast:89
+assert_return(() => invoke($0, `br_on_array`, [0]), [value("i32", -1)]);
+
+// ./test/core/gc/br_on_cast.wast:90
+assert_return(() => invoke($0, `br_on_array`, [1]), [value("i32", -1)]);
+
+// ./test/core/gc/br_on_cast.wast:91
+assert_return(() => invoke($0, `br_on_array`, [2]), [value("i32", -1)]);
+
+// ./test/core/gc/br_on_cast.wast:92
+assert_return(() => invoke($0, `br_on_array`, [3]), [value("i32", 3)]);
+
+// ./test/core/gc/br_on_cast.wast:93
+assert_return(() => invoke($0, `br_on_array`, [4]), [value("i32", -1)]);
+
+// ./test/core/gc/br_on_cast.wast:95
+assert_return(() => invoke($0, `null-diff`, [0]), [value("i32", 1)]);
+
+// ./test/core/gc/br_on_cast.wast:96
+assert_return(() => invoke($0, `null-diff`, [1]), [value("i32", 0)]);
+
+// ./test/core/gc/br_on_cast.wast:97
+assert_return(() => invoke($0, `null-diff`, [2]), [value("i32", 1)]);
+
+// ./test/core/gc/br_on_cast.wast:98
+assert_return(() => invoke($0, `null-diff`, [3]), [value("i32", 0)]);
+
+// ./test/core/gc/br_on_cast.wast:99
+assert_return(() => invoke($0, `null-diff`, [4]), [value("i32", 0)]);
+
+// ./test/core/gc/br_on_cast.wast:104
+let $1 = instantiate(`(module
+ (type $$t0 (sub (struct)))
+ (type $$t1 (sub $$t0 (struct (field i32))))
+ (type $$t1' (sub $$t0 (struct (field i32))))
+ (type $$t2 (sub $$t1 (struct (field i32 i32))))
+ (type $$t2' (sub $$t1' (struct (field i32 i32))))
+ (type $$t3 (sub $$t0 (struct (field i32 i32))))
+ (type $$t0' (sub $$t0 (struct)))
+ (type $$t4 (sub $$t0' (struct (field i32 i32))))
+
+ (table 20 structref)
+
+ (func $$init
+ (table.set (i32.const 0) (struct.new_default $$t0))
+ (table.set (i32.const 10) (struct.new_default $$t0'))
+ (table.set (i32.const 1) (struct.new_default $$t1))
+ (table.set (i32.const 11) (struct.new_default $$t1'))
+ (table.set (i32.const 2) (struct.new_default $$t2))
+ (table.set (i32.const 12) (struct.new_default $$t2'))
+ (table.set (i32.const 3) (struct.new_default $$t3))
+ (table.set (i32.const 4) (struct.new_default $$t4))
+ )
+
+ (func (export "test-sub")
+ (call $$init)
+ (block $$l (result structref)
+ ;; must succeed
+ (drop (block (result structref) (br_on_cast 0 structref (ref $$t0) (ref.null struct))))
+ (drop (block (result structref) (br_on_cast 0 structref (ref $$t0) (table.get (i32.const 0)))))
+ (drop (block (result structref) (br_on_cast 0 structref (ref $$t0) (table.get (i32.const 1)))))
+ (drop (block (result structref) (br_on_cast 0 structref (ref $$t0) (table.get (i32.const 2)))))
+ (drop (block (result structref) (br_on_cast 0 structref (ref $$t0) (table.get (i32.const 3)))))
+ (drop (block (result structref) (br_on_cast 0 structref (ref $$t0) (table.get (i32.const 4)))))
+
+ (drop (block (result structref) (br_on_cast 0 structref (ref $$t1) (ref.null struct))))
+ (drop (block (result structref) (br_on_cast 0 structref (ref $$t1) (table.get (i32.const 1)))))
+ (drop (block (result structref) (br_on_cast 0 structref (ref $$t1) (table.get (i32.const 2)))))
+
+ (drop (block (result structref) (br_on_cast 0 structref (ref $$t2) (ref.null struct))))
+ (drop (block (result structref) (br_on_cast 0 structref (ref $$t2) (table.get (i32.const 2)))))
+
+ (drop (block (result structref) (br_on_cast 0 structref (ref $$t3) (ref.null struct))))
+ (drop (block (result structref) (br_on_cast 0 structref (ref $$t3) (table.get (i32.const 3)))))
+
+ (drop (block (result structref) (br_on_cast 0 structref (ref $$t4) (ref.null struct))))
+ (drop (block (result structref) (br_on_cast 0 structref (ref $$t4) (table.get (i32.const 4)))))
+
+ ;; must not succeed
+ (br_on_cast $$l anyref (ref $$t1) (table.get (i32.const 0)))
+ (br_on_cast $$l anyref (ref $$t1) (table.get (i32.const 3)))
+ (br_on_cast $$l anyref (ref $$t1) (table.get (i32.const 4)))
+
+ (br_on_cast $$l anyref (ref $$t2) (table.get (i32.const 0)))
+ (br_on_cast $$l anyref (ref $$t2) (table.get (i32.const 1)))
+ (br_on_cast $$l anyref (ref $$t2) (table.get (i32.const 3)))
+ (br_on_cast $$l anyref (ref $$t2) (table.get (i32.const 4)))
+
+ (br_on_cast $$l anyref (ref $$t3) (table.get (i32.const 0)))
+ (br_on_cast $$l anyref (ref $$t3) (table.get (i32.const 1)))
+ (br_on_cast $$l anyref (ref $$t3) (table.get (i32.const 2)))
+ (br_on_cast $$l anyref (ref $$t3) (table.get (i32.const 4)))
+
+ (br_on_cast $$l anyref (ref $$t4) (table.get (i32.const 0)))
+ (br_on_cast $$l anyref (ref $$t4) (table.get (i32.const 1)))
+ (br_on_cast $$l anyref (ref $$t4) (table.get (i32.const 2)))
+ (br_on_cast $$l anyref (ref $$t4) (table.get (i32.const 3)))
+
+ (return)
+ )
+ (unreachable)
+ )
+
+ (func (export "test-canon")
+ (call $$init)
+ (block $$l
+ (drop (block (result structref) (br_on_cast 0 structref (ref $$t0') (table.get (i32.const 0)))))
+ (drop (block (result structref) (br_on_cast 0 structref (ref $$t0') (table.get (i32.const 1)))))
+ (drop (block (result structref) (br_on_cast 0 structref (ref $$t0') (table.get (i32.const 2)))))
+ (drop (block (result structref) (br_on_cast 0 structref (ref $$t0') (table.get (i32.const 3)))))
+ (drop (block (result structref) (br_on_cast 0 structref (ref $$t0') (table.get (i32.const 4)))))
+
+ (drop (block (result structref) (br_on_cast 0 structref (ref $$t0) (table.get (i32.const 10)))))
+ (drop (block (result structref) (br_on_cast 0 structref (ref $$t0) (table.get (i32.const 11)))))
+ (drop (block (result structref) (br_on_cast 0 structref (ref $$t0) (table.get (i32.const 12)))))
+
+ (drop (block (result structref) (br_on_cast 0 structref (ref $$t1') (table.get (i32.const 1)))))
+ (drop (block (result structref) (br_on_cast 0 structref (ref $$t1') (table.get (i32.const 2)))))
+
+ (drop (block (result structref) (br_on_cast 0 structref (ref $$t1) (table.get (i32.const 11)))))
+ (drop (block (result structref) (br_on_cast 0 structref (ref $$t1) (table.get (i32.const 12)))))
+
+ (drop (block (result structref) (br_on_cast 0 structref (ref $$t2') (table.get (i32.const 2)))))
+
+ (drop (block (result structref) (br_on_cast 0 structref (ref $$t2) (table.get (i32.const 12)))))
+
+ (return)
+ )
+ (unreachable)
+ )
+)`);
+
+// ./test/core/gc/br_on_cast.wast:205
+invoke($1, `test-sub`, []);
+
+// ./test/core/gc/br_on_cast.wast:206
+invoke($1, `test-canon`, []);
+
+// ./test/core/gc/br_on_cast.wast:211
+let $2 = instantiate(`(module
+ (type $$t (struct))
+
+ (func (param (ref any)) (result (ref $$t))
+ (block (result (ref any)) (br_on_cast 1 (ref any) (ref $$t) (local.get 0))) (unreachable)
+ )
+ (func (param (ref null any)) (result (ref $$t))
+ (block (result (ref null any)) (br_on_cast 1 (ref null any) (ref $$t) (local.get 0))) (unreachable)
+ )
+ (func (param (ref null any)) (result (ref null $$t))
+ (block (result (ref null any)) (br_on_cast 1 (ref null any) (ref null $$t) (local.get 0))) (unreachable)
+ )
+)`);
+
+// ./test/core/gc/br_on_cast.wast:225
+assert_invalid(
+ () => instantiate(`(module
+ (type $$t (struct))
+ (func (param (ref any)) (result (ref $$t))
+ (block (result (ref any)) (br_on_cast 1 (ref null any) (ref null $$t) (local.get 0))) (unreachable)
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/gc/br_on_cast.wast:234
+assert_invalid(
+ () => instantiate(`(module
+ (type $$t (struct))
+ (func (param (ref any)) (result (ref null $$t))
+ (block (result (ref any)) (br_on_cast 1 (ref any) (ref null $$t) (local.get 0))) (unreachable)
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/gc/br_on_cast.wast:243
+assert_invalid(
+ () => instantiate(`(module
+ (type $$t (struct))
+ (func (param (ref null any)) (result (ref $$t))
+ (block (result (ref any)) (br_on_cast 1 (ref null any) (ref $$t) (local.get 0))) (unreachable)
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/gc/br_on_cast.wast:252
+assert_invalid(
+ () => instantiate(`(module
+ (func (result anyref)
+ (br_on_cast 0 eqref anyref (unreachable))
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/gc/br_on_cast.wast:260
+assert_invalid(
+ () => instantiate(`(module
+ (func (result anyref)
+ (br_on_cast 0 structref arrayref (unreachable))
+ )
+ )`),
+ `type mismatch`,
+);
diff --git a/js/src/jit-test/tests/wasm/spec/gc/br_on_cast_fail.wast.js b/js/src/jit-test/tests/wasm/spec/gc/br_on_cast_fail.wast.js
new file mode 100644
index 0000000000..4d402f2803
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/spec/gc/br_on_cast_fail.wast.js
@@ -0,0 +1,352 @@
+/* Copyright 2021 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ./test/core/gc/br_on_cast_fail.wast
+
+// ./test/core/gc/br_on_cast_fail.wast:3
+let $0 = instantiate(`(module
+ (type $$ft (func (result i32)))
+ (type $$st (struct (field i16)))
+ (type $$at (array i8))
+
+ (table 10 anyref)
+
+ (elem declare func $$f)
+ (func $$f (result i32) (i32.const 9))
+
+ (func (export "init") (param $$x externref)
+ (table.set (i32.const 0) (ref.null any))
+ (table.set (i32.const 1) (ref.i31 (i32.const 7)))
+ (table.set (i32.const 2) (struct.new $$st (i32.const 6)))
+ (table.set (i32.const 3) (array.new $$at (i32.const 5) (i32.const 3)))
+ (table.set (i32.const 4) (any.convert_extern (local.get $$x)))
+ )
+
+ (func (export "br_on_non_null") (param $$i i32) (result i32)
+ (block $$l (result (ref any))
+ (br_on_non_null $$l (table.get (local.get $$i)))
+ (return (i32.const 0))
+ )
+ (return (i32.const -1))
+ )
+ (func (export "br_on_non_i31") (param $$i i32) (result i32)
+ (block $$l (result anyref)
+ (br_on_cast_fail $$l anyref (ref i31) (table.get (local.get $$i)))
+ (return (i31.get_u))
+ )
+ (return (i32.const -1))
+ )
+ (func (export "br_on_non_struct") (param $$i i32) (result i32)
+ (block $$l (result anyref)
+ (br_on_cast_fail $$l anyref (ref struct) (table.get (local.get $$i)))
+ (block $$l2 (param structref) (result (ref $$st))
+ (block $$l3 (param structref) (result (ref $$at))
+ (br_on_cast $$l2 structref (ref $$st))
+ (br_on_cast $$l3 anyref (ref $$at))
+ (return (i32.const -2))
+ )
+ (return (array.get_u $$at (i32.const 0)))
+ )
+ (return (struct.get_s $$st 0))
+ )
+ (return (i32.const -1))
+ )
+ (func (export "br_on_non_array") (param $$i i32) (result i32)
+ (block $$l (result anyref)
+ (br_on_cast_fail $$l anyref (ref array) (table.get (local.get $$i)))
+ (return (array.len))
+ )
+ (return (i32.const -1))
+ )
+
+ (func (export "null-diff") (param $$i i32) (result i32)
+ (block $$l (result (ref any))
+ (block (result (ref null struct))
+ (br_on_cast_fail $$l (ref null any) (ref null struct) (table.get (local.get $$i)))
+ )
+ (return (i32.const 1))
+ )
+ (return (i32.const 0))
+ )
+)`);
+
+// ./test/core/gc/br_on_cast_fail.wast:69
+invoke($0, `init`, [externref(0)]);
+
+// ./test/core/gc/br_on_cast_fail.wast:71
+assert_return(() => invoke($0, `br_on_non_null`, [0]), [value("i32", 0)]);
+
+// ./test/core/gc/br_on_cast_fail.wast:72
+assert_return(() => invoke($0, `br_on_non_null`, [1]), [value("i32", -1)]);
+
+// ./test/core/gc/br_on_cast_fail.wast:73
+assert_return(() => invoke($0, `br_on_non_null`, [2]), [value("i32", -1)]);
+
+// ./test/core/gc/br_on_cast_fail.wast:74
+assert_return(() => invoke($0, `br_on_non_null`, [3]), [value("i32", -1)]);
+
+// ./test/core/gc/br_on_cast_fail.wast:75
+assert_return(() => invoke($0, `br_on_non_null`, [4]), [value("i32", -1)]);
+
+// ./test/core/gc/br_on_cast_fail.wast:77
+assert_return(() => invoke($0, `br_on_non_i31`, [0]), [value("i32", -1)]);
+
+// ./test/core/gc/br_on_cast_fail.wast:78
+assert_return(() => invoke($0, `br_on_non_i31`, [1]), [value("i32", 7)]);
+
+// ./test/core/gc/br_on_cast_fail.wast:79
+assert_return(() => invoke($0, `br_on_non_i31`, [2]), [value("i32", -1)]);
+
+// ./test/core/gc/br_on_cast_fail.wast:80
+assert_return(() => invoke($0, `br_on_non_i31`, [3]), [value("i32", -1)]);
+
+// ./test/core/gc/br_on_cast_fail.wast:81
+assert_return(() => invoke($0, `br_on_non_i31`, [4]), [value("i32", -1)]);
+
+// ./test/core/gc/br_on_cast_fail.wast:83
+assert_return(() => invoke($0, `br_on_non_struct`, [0]), [value("i32", -1)]);
+
+// ./test/core/gc/br_on_cast_fail.wast:84
+assert_return(() => invoke($0, `br_on_non_struct`, [1]), [value("i32", -1)]);
+
+// ./test/core/gc/br_on_cast_fail.wast:85
+assert_return(() => invoke($0, `br_on_non_struct`, [2]), [value("i32", 6)]);
+
+// ./test/core/gc/br_on_cast_fail.wast:86
+assert_return(() => invoke($0, `br_on_non_struct`, [3]), [value("i32", -1)]);
+
+// ./test/core/gc/br_on_cast_fail.wast:87
+assert_return(() => invoke($0, `br_on_non_struct`, [4]), [value("i32", -1)]);
+
+// ./test/core/gc/br_on_cast_fail.wast:89
+assert_return(() => invoke($0, `br_on_non_array`, [0]), [value("i32", -1)]);
+
+// ./test/core/gc/br_on_cast_fail.wast:90
+assert_return(() => invoke($0, `br_on_non_array`, [1]), [value("i32", -1)]);
+
+// ./test/core/gc/br_on_cast_fail.wast:91
+assert_return(() => invoke($0, `br_on_non_array`, [2]), [value("i32", -1)]);
+
+// ./test/core/gc/br_on_cast_fail.wast:92
+assert_return(() => invoke($0, `br_on_non_array`, [3]), [value("i32", 3)]);
+
+// ./test/core/gc/br_on_cast_fail.wast:93
+assert_return(() => invoke($0, `br_on_non_array`, [4]), [value("i32", -1)]);
+
+// ./test/core/gc/br_on_cast_fail.wast:95
+assert_return(() => invoke($0, `null-diff`, [0]), [value("i32", 1)]);
+
+// ./test/core/gc/br_on_cast_fail.wast:96
+assert_return(() => invoke($0, `null-diff`, [1]), [value("i32", 0)]);
+
+// ./test/core/gc/br_on_cast_fail.wast:97
+assert_return(() => invoke($0, `null-diff`, [2]), [value("i32", 1)]);
+
+// ./test/core/gc/br_on_cast_fail.wast:98
+assert_return(() => invoke($0, `null-diff`, [3]), [value("i32", 0)]);
+
+// ./test/core/gc/br_on_cast_fail.wast:99
+assert_return(() => invoke($0, `null-diff`, [4]), [value("i32", 0)]);
+
+// ./test/core/gc/br_on_cast_fail.wast:104
+let $1 = instantiate(`(module
+ (type $$t0 (sub (struct)))
+ (type $$t1 (sub $$t0 (struct (field i32))))
+ (type $$t1' (sub $$t0 (struct (field i32))))
+ (type $$t2 (sub $$t1 (struct (field i32 i32))))
+ (type $$t2' (sub $$t1' (struct (field i32 i32))))
+ (type $$t3 (sub $$t0 (struct (field i32 i32))))
+ (type $$t0' (sub $$t0 (struct)))
+ (type $$t4 (sub $$t0' (struct (field i32 i32))))
+
+ (table 20 structref)
+
+ (func $$init
+ (table.set (i32.const 0) (struct.new_default $$t0))
+ (table.set (i32.const 10) (struct.new_default $$t0))
+ (table.set (i32.const 1) (struct.new_default $$t1))
+ (table.set (i32.const 11) (struct.new_default $$t1'))
+ (table.set (i32.const 2) (struct.new_default $$t2))
+ (table.set (i32.const 12) (struct.new_default $$t2'))
+ (table.set (i32.const 3) (struct.new_default $$t3 ))
+ (table.set (i32.const 4) (struct.new_default $$t4))
+ )
+
+ (func (export "test-sub")
+ (call $$init)
+ (block $$l (result structref)
+ ;; must not succeed
+ (br_on_cast_fail $$l structref (ref null $$t0) (ref.null struct))
+ (br_on_cast_fail $$l structref (ref null $$t0) (table.get (i32.const 0)))
+ (br_on_cast_fail $$l structref (ref null $$t0) (table.get (i32.const 1)))
+ (br_on_cast_fail $$l structref (ref null $$t0) (table.get (i32.const 2)))
+ (br_on_cast_fail $$l structref (ref null $$t0) (table.get (i32.const 3)))
+ (br_on_cast_fail $$l structref (ref null $$t0) (table.get (i32.const 4)))
+ (br_on_cast_fail $$l structref (ref $$t0) (table.get (i32.const 0)))
+ (br_on_cast_fail $$l structref (ref $$t0) (table.get (i32.const 1)))
+ (br_on_cast_fail $$l structref (ref $$t0) (table.get (i32.const 2)))
+ (br_on_cast_fail $$l structref (ref $$t0) (table.get (i32.const 3)))
+ (br_on_cast_fail $$l structref (ref $$t0) (table.get (i32.const 4)))
+
+ (br_on_cast_fail $$l structref (ref null $$t1) (ref.null struct))
+ (br_on_cast_fail $$l structref (ref null $$t1) (table.get (i32.const 1)))
+ (br_on_cast_fail $$l structref (ref null $$t1) (table.get (i32.const 2)))
+ (br_on_cast_fail $$l structref (ref $$t1) (table.get (i32.const 1)))
+ (br_on_cast_fail $$l structref (ref $$t1) (table.get (i32.const 2)))
+
+ (br_on_cast_fail $$l structref (ref null $$t2) (ref.null struct))
+ (br_on_cast_fail $$l structref (ref null $$t2) (table.get (i32.const 2)))
+ (br_on_cast_fail $$l structref (ref $$t2) (table.get (i32.const 2)))
+
+ (br_on_cast_fail $$l structref (ref null $$t3) (ref.null struct))
+ (br_on_cast_fail $$l structref (ref null $$t3) (table.get (i32.const 3)))
+ (br_on_cast_fail $$l structref (ref $$t3) (table.get (i32.const 3)))
+
+ (br_on_cast_fail $$l structref (ref null $$t4) (ref.null struct))
+ (br_on_cast_fail $$l structref (ref null $$t4) (table.get (i32.const 4)))
+ (br_on_cast_fail $$l structref (ref $$t4) (table.get (i32.const 4)))
+
+ ;; must succeed
+ (drop (block (result structref) (br_on_cast_fail 0 structref (ref $$t0) (ref.null struct))))
+
+ (drop (block (result structref) (br_on_cast_fail 0 structref (ref $$t1) (ref.null struct))))
+ (drop (block (result structref) (br_on_cast_fail 0 structref (ref $$t1) (table.get (i32.const 0)))))
+ (drop (block (result structref) (br_on_cast_fail 0 structref (ref $$t1) (table.get (i32.const 3)))))
+ (drop (block (result structref) (br_on_cast_fail 0 structref (ref $$t1) (table.get (i32.const 4)))))
+
+ (drop (block (result structref) (br_on_cast_fail 0 structref (ref $$t2) (ref.null struct))))
+ (drop (block (result structref) (br_on_cast_fail 0 structref (ref $$t2) (table.get (i32.const 0)))))
+ (drop (block (result structref) (br_on_cast_fail 0 structref (ref $$t2) (table.get (i32.const 1)))))
+ (drop (block (result structref) (br_on_cast_fail 0 structref (ref $$t2) (table.get (i32.const 3)))))
+ (drop (block (result structref) (br_on_cast_fail 0 structref (ref $$t2) (table.get (i32.const 4)))))
+
+ (drop (block (result structref) (br_on_cast_fail 0 structref (ref $$t3) (ref.null struct))))
+ (drop (block (result structref) (br_on_cast_fail 0 structref (ref $$t3) (table.get (i32.const 0)))))
+ (drop (block (result structref) (br_on_cast_fail 0 structref (ref $$t3) (table.get (i32.const 1)))))
+ (drop (block (result structref) (br_on_cast_fail 0 structref (ref $$t3) (table.get (i32.const 2)))))
+ (drop (block (result structref) (br_on_cast_fail 0 structref (ref $$t3) (table.get (i32.const 4)))))
+
+ (drop (block (result structref) (br_on_cast_fail 0 structref (ref $$t4) (ref.null struct))))
+ (drop (block (result structref) (br_on_cast_fail 0 structref (ref $$t4) (table.get (i32.const 0)))))
+ (drop (block (result structref) (br_on_cast_fail 0 structref (ref $$t4) (table.get (i32.const 1)))))
+ (drop (block (result structref) (br_on_cast_fail 0 structref (ref $$t4) (table.get (i32.const 2)))))
+ (drop (block (result structref) (br_on_cast_fail 0 structref (ref $$t4) (table.get (i32.const 3)))))
+
+ (return)
+ )
+ (unreachable)
+ )
+
+ (func (export "test-canon")
+ (call $$init)
+ (block $$l (result structref)
+ (br_on_cast_fail $$l structref (ref $$t0) (table.get (i32.const 0)))
+ (br_on_cast_fail $$l structref (ref $$t0) (table.get (i32.const 1)))
+ (br_on_cast_fail $$l structref (ref $$t0) (table.get (i32.const 2)))
+ (br_on_cast_fail $$l structref (ref $$t0) (table.get (i32.const 3)))
+ (br_on_cast_fail $$l structref (ref $$t0) (table.get (i32.const 4)))
+ (br_on_cast_fail $$l structref (ref $$t0) (table.get (i32.const 10)))
+ (br_on_cast_fail $$l structref (ref $$t0) (table.get (i32.const 11)))
+ (br_on_cast_fail $$l structref (ref $$t0) (table.get (i32.const 12)))
+
+ (br_on_cast_fail $$l structref (ref $$t1') (table.get (i32.const 1)))
+ (br_on_cast_fail $$l structref (ref $$t1') (table.get (i32.const 2)))
+
+ (br_on_cast_fail $$l structref (ref $$t1) (table.get (i32.const 11)))
+ (br_on_cast_fail $$l structref (ref $$t1) (table.get (i32.const 12)))
+
+ (br_on_cast_fail $$l structref (ref $$t2') (table.get (i32.const 2)))
+
+ (br_on_cast_fail $$l structref (ref $$t2) (table.get (i32.const 12)))
+
+ (return)
+ )
+ (unreachable)
+ )
+)`);
+
+// ./test/core/gc/br_on_cast_fail.wast:220
+invoke($1, `test-sub`, []);
+
+// ./test/core/gc/br_on_cast_fail.wast:221
+invoke($1, `test-canon`, []);
+
+// ./test/core/gc/br_on_cast_fail.wast:226
+let $2 = instantiate(`(module
+ (type $$t (struct))
+
+ (func (param (ref any)) (result (ref any))
+ (block (result (ref $$t)) (br_on_cast_fail 1 (ref any) (ref $$t) (local.get 0)))
+ )
+ (func (param (ref null any)) (result (ref null any))
+ (block (result (ref $$t)) (br_on_cast_fail 1 (ref null any) (ref $$t) (local.get 0)))
+ )
+ (func (param (ref null any)) (result (ref null any))
+ (block (result (ref null $$t)) (br_on_cast_fail 1 (ref null any) (ref null $$t) (local.get 0)))
+ )
+)`);
+
+// ./test/core/gc/br_on_cast_fail.wast:240
+assert_invalid(
+ () => instantiate(`(module
+ (type $$t (struct))
+ (func (param (ref any)) (result (ref any))
+ (block (result (ref $$t)) (br_on_cast_fail 1 (ref null any) (ref null $$t) (local.get 0)))
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/gc/br_on_cast_fail.wast:249
+assert_invalid(
+ () => instantiate(`(module
+ (type $$t (struct))
+ (func (param (ref any)) (result (ref any))
+ (block (result (ref null $$t)) (br_on_cast_fail 1 (ref any) (ref null $$t) (local.get 0))) (ref.as_non_null)
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/gc/br_on_cast_fail.wast:258
+assert_invalid(
+ () => instantiate(`(module
+ (type $$t (struct))
+ (func (param (ref null any)) (result (ref any))
+ (block (result (ref $$t)) (br_on_cast_fail 1 (ref null any) (ref $$t) (local.get 0)))
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/gc/br_on_cast_fail.wast:267
+assert_invalid(
+ () => instantiate(`(module
+ (func (result anyref)
+ (br_on_cast_fail 0 eqref anyref (unreachable))
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/gc/br_on_cast_fail.wast:275
+assert_invalid(
+ () => instantiate(`(module
+ (func (result anyref)
+ (br_on_cast_fail 0 structref arrayref (unreachable))
+ )
+ )`),
+ `type mismatch`,
+);
diff --git a/js/src/jit-test/tests/wasm/spec/gc/comments.wast.js b/js/src/jit-test/tests/wasm/spec/gc/comments.wast.js
new file mode 100644
index 0000000000..32a78a1e3c
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/spec/gc/comments.wast.js
@@ -0,0 +1,51 @@
+/* Copyright 2021 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ./test/core/comments.wast
+
+// ./test/core/comments.wast:10:0
+let $0 = instantiate(`(module;;comment
+)`);
+
+// ./test/core/comments.wast:57:11
+let $1 = instantiate(`(module(;comment;)
+(;comment;))`);
+
+// ./test/core/comments.wast:67
+let $2 = instantiate(`(module
+ (;comment(;nested(;further;)nested;)comment;)
+)`);
+
+// ./test/core/comments.wast:76
+let $3 = instantiate(`(module
+ (;comment;;comment(;nested;)comment;)
+)`);
+
+// ./test/core/comments.wast:83:8
+let $4 = instantiate(`(func (export "f1") (result i32) (i32.const 1) ;; comment
+ (return (i32.const 2))
+ ) (func (export "f2") (result i32) (i32.const 1) ;; comment (return (i32.const 2))
+ ) (func (export "f3") (result i32) (i32.const 1) ;; comment
+ (return (i32.const 2))
+ ) `);
+
+// ./test/core/comments.wast:104
+assert_return(() => invoke($4, `f1`, []), [value("i32", 2)]);
+
+// ./test/core/comments.wast:105
+assert_return(() => invoke($4, `f2`, []), [value("i32", 2)]);
+
+// ./test/core/comments.wast:106
+assert_return(() => invoke($4, `f3`, []), [value("i32", 2)]);
diff --git a/js/src/jit-test/tests/wasm/spec/gc/directives.txt b/js/src/jit-test/tests/wasm/spec/gc/directives.txt
new file mode 100644
index 0000000000..c071d8b980
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/spec/gc/directives.txt
@@ -0,0 +1 @@
+|jit-test| test-also=--wasm-compiler=optimizing; test-also=--wasm-compiler=baseline; test-also=--wasm-test-serialization; test-also=--test-wasm-await-tier2; test-also=--disable-wasm-huge-memory; skip-variant-if: --disable-wasm-huge-memory, !wasmHugeMemorySupported(); local-include:harness/harness.js; --wasm-gc; skip-if: !wasmGcEnabled() \ No newline at end of file
diff --git a/js/src/jit-test/tests/wasm/spec/gc/extern.wast.js b/js/src/jit-test/tests/wasm/spec/gc/extern.wast.js
new file mode 100644
index 0000000000..d292e157da
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/spec/gc/extern.wast.js
@@ -0,0 +1,101 @@
+/* Copyright 2021 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ./test/core/gc/extern.wast
+
+// ./test/core/gc/extern.wast:1
+let $0 = instantiate(`(module
+ (type $$ft (func))
+ (type $$st (struct))
+ (type $$at (array i8))
+
+ (table 10 anyref)
+
+ (elem declare func $$f)
+ (func $$f)
+
+ (func (export "init") (param $$x externref)
+ (table.set (i32.const 0) (ref.null any))
+ (table.set (i32.const 1) (ref.i31 (i32.const 7)))
+ (table.set (i32.const 2) (struct.new_default $$st))
+ (table.set (i32.const 3) (array.new_default $$at (i32.const 0)))
+ (table.set (i32.const 4) (any.convert_extern (local.get $$x)))
+ )
+
+ (func (export "internalize") (param externref) (result anyref)
+ (any.convert_extern (local.get 0))
+ )
+ (func (export "externalize") (param anyref) (result externref)
+ (extern.convert_any (local.get 0))
+ )
+
+ (func (export "externalize-i") (param i32) (result externref)
+ (extern.convert_any (table.get (local.get 0)))
+ )
+ (func (export "externalize-ii") (param i32) (result anyref)
+ (any.convert_extern (extern.convert_any (table.get (local.get 0))))
+ )
+)`);
+
+// ./test/core/gc/extern.wast:34
+invoke($0, `init`, [externref(0)]);
+
+// ./test/core/gc/extern.wast:36
+assert_return(() => invoke($0, `internalize`, [externref(1)]), [new HostRefResult(1)]);
+
+// ./test/core/gc/extern.wast:37
+assert_return(() => invoke($0, `internalize`, [null]), [value('anyref', null)]);
+
+// ./test/core/gc/extern.wast:39
+assert_return(() => invoke($0, `externalize`, [hostref(2)]), [new ExternRefResult(2)]);
+
+// ./test/core/gc/extern.wast:40
+assert_return(() => invoke($0, `externalize`, [null]), [value('externref', null)]);
+
+// ./test/core/gc/extern.wast:42
+assert_return(() => invoke($0, `externalize-i`, [0]), [value('externref', null)]);
+
+// ./test/core/gc/extern.wast:43
+assert_return(() => invoke($0, `externalize-i`, [1]), [new RefWithType('externref')]);
+
+// ./test/core/gc/extern.wast:44
+assert_return(() => invoke($0, `externalize-i`, [2]), [new RefWithType('externref')]);
+
+// ./test/core/gc/extern.wast:45
+assert_return(() => invoke($0, `externalize-i`, [3]), [new RefWithType('externref')]);
+
+// ./test/core/gc/extern.wast:46
+assert_return(() => invoke($0, `externalize-i`, [4]), [new RefWithType('externref')]);
+
+// ./test/core/gc/extern.wast:47
+assert_return(() => invoke($0, `externalize-i`, [5]), [value('externref', null)]);
+
+// ./test/core/gc/extern.wast:49
+assert_return(() => invoke($0, `externalize-ii`, [0]), [value('anyref', null)]);
+
+// ./test/core/gc/extern.wast:50
+assert_return(() => invoke($0, `externalize-ii`, [1]), [new RefWithType('i31ref')]);
+
+// ./test/core/gc/extern.wast:51
+assert_return(() => invoke($0, `externalize-ii`, [2]), [new RefWithType('structref')]);
+
+// ./test/core/gc/extern.wast:52
+assert_return(() => invoke($0, `externalize-ii`, [3]), [new RefWithType('arrayref')]);
+
+// ./test/core/gc/extern.wast:53
+assert_return(() => invoke($0, `externalize-ii`, [4]), [new HostRefResult(0)]);
+
+// ./test/core/gc/extern.wast:54
+assert_return(() => invoke($0, `externalize-ii`, [5]), [value('anyref', null)]);
diff --git a/js/src/jit-test/tests/wasm/spec/gc/float_literals.wast.js b/js/src/jit-test/tests/wasm/spec/gc/float_literals.wast.js
new file mode 100644
index 0000000000..c352ebec75
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/spec/gc/float_literals.wast.js
@@ -0,0 +1,776 @@
+/* Copyright 2021 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ./test/core/float_literals.wast
+
+// ./test/core/float_literals.wast:3
+let $0 = instantiate(`(module
+ ;; f32 special values
+ (func (export "f32.nan") (result i32) (i32.reinterpret_f32 (f32.const nan)))
+ (func (export "f32.positive_nan") (result i32) (i32.reinterpret_f32 (f32.const +nan)))
+ (func (export "f32.negative_nan") (result i32) (i32.reinterpret_f32 (f32.const -nan)))
+ (func (export "f32.plain_nan") (result i32) (i32.reinterpret_f32 (f32.const nan:0x400000)))
+ (func (export "f32.informally_known_as_plain_snan") (result i32) (i32.reinterpret_f32 (f32.const nan:0x200000)))
+ (func (export "f32.all_ones_nan") (result i32) (i32.reinterpret_f32 (f32.const -nan:0x7fffff)))
+ (func (export "f32.misc_nan") (result i32) (i32.reinterpret_f32 (f32.const nan:0x012345)))
+ (func (export "f32.misc_positive_nan") (result i32) (i32.reinterpret_f32 (f32.const +nan:0x304050)))
+ (func (export "f32.misc_negative_nan") (result i32) (i32.reinterpret_f32 (f32.const -nan:0x2abcde)))
+ (func (export "f32.infinity") (result i32) (i32.reinterpret_f32 (f32.const inf)))
+ (func (export "f32.positive_infinity") (result i32) (i32.reinterpret_f32 (f32.const +inf)))
+ (func (export "f32.negative_infinity") (result i32) (i32.reinterpret_f32 (f32.const -inf)))
+
+ ;; f32 numbers
+ (func (export "f32.zero") (result i32) (i32.reinterpret_f32 (f32.const 0x0.0p0)))
+ (func (export "f32.positive_zero") (result i32) (i32.reinterpret_f32 (f32.const +0x0.0p0)))
+ (func (export "f32.negative_zero") (result i32) (i32.reinterpret_f32 (f32.const -0x0.0p0)))
+ (func (export "f32.misc") (result i32) (i32.reinterpret_f32 (f32.const 0x1.921fb6p+2)))
+ (func (export "f32.min_positive") (result i32) (i32.reinterpret_f32 (f32.const 0x1p-149)))
+ (func (export "f32.min_normal") (result i32) (i32.reinterpret_f32 (f32.const 0x1p-126)))
+ (func (export "f32.max_finite") (result i32) (i32.reinterpret_f32 (f32.const 0x1.fffffep+127)))
+ (func (export "f32.max_subnormal") (result i32) (i32.reinterpret_f32 (f32.const 0x1.fffffcp-127)))
+ (func (export "f32.trailing_dot") (result i32) (i32.reinterpret_f32 (f32.const 0x1.p10)))
+
+ ;; f32 in decimal format
+ (func (export "f32_dec.zero") (result i32) (i32.reinterpret_f32 (f32.const 0.0e0)))
+ (func (export "f32_dec.positive_zero") (result i32) (i32.reinterpret_f32 (f32.const +0.0e0)))
+ (func (export "f32_dec.negative_zero") (result i32) (i32.reinterpret_f32 (f32.const -0.0e0)))
+ (func (export "f32_dec.misc") (result i32) (i32.reinterpret_f32 (f32.const 6.28318548202514648)))
+ (func (export "f32_dec.min_positive") (result i32) (i32.reinterpret_f32 (f32.const 1.4013e-45)))
+ (func (export "f32_dec.min_normal") (result i32) (i32.reinterpret_f32 (f32.const 1.1754944e-38)))
+ (func (export "f32_dec.max_subnormal") (result i32) (i32.reinterpret_f32 (f32.const 1.1754942e-38)))
+ (func (export "f32_dec.max_finite") (result i32) (i32.reinterpret_f32 (f32.const 3.4028234e+38)))
+ (func (export "f32_dec.trailing_dot") (result i32) (i32.reinterpret_f32 (f32.const 1.e10)))
+
+ ;; https://twitter.com/Archivd/status/994637336506912768
+ (func (export "f32_dec.root_beer_float") (result i32) (i32.reinterpret_f32 (f32.const 1.000000119)))
+
+ ;; f64 special values
+ (func (export "f64.nan") (result i64) (i64.reinterpret_f64 (f64.const nan)))
+ (func (export "f64.positive_nan") (result i64) (i64.reinterpret_f64 (f64.const +nan)))
+ (func (export "f64.negative_nan") (result i64) (i64.reinterpret_f64 (f64.const -nan)))
+ (func (export "f64.plain_nan") (result i64) (i64.reinterpret_f64 (f64.const nan:0x8000000000000)))
+ (func (export "f64.informally_known_as_plain_snan") (result i64) (i64.reinterpret_f64 (f64.const nan:0x4000000000000)))
+ (func (export "f64.all_ones_nan") (result i64) (i64.reinterpret_f64 (f64.const -nan:0xfffffffffffff)))
+ (func (export "f64.misc_nan") (result i64) (i64.reinterpret_f64 (f64.const nan:0x0123456789abc)))
+ (func (export "f64.misc_positive_nan") (result i64) (i64.reinterpret_f64 (f64.const +nan:0x3040506070809)))
+ (func (export "f64.misc_negative_nan") (result i64) (i64.reinterpret_f64 (f64.const -nan:0x2abcdef012345)))
+ (func (export "f64.infinity") (result i64) (i64.reinterpret_f64 (f64.const inf)))
+ (func (export "f64.positive_infinity") (result i64) (i64.reinterpret_f64 (f64.const +inf)))
+ (func (export "f64.negative_infinity") (result i64) (i64.reinterpret_f64 (f64.const -inf)))
+
+ ;; f64 numbers
+ (func (export "f64.zero") (result i64) (i64.reinterpret_f64 (f64.const 0x0.0p0)))
+ (func (export "f64.positive_zero") (result i64) (i64.reinterpret_f64 (f64.const +0x0.0p0)))
+ (func (export "f64.negative_zero") (result i64) (i64.reinterpret_f64 (f64.const -0x0.0p0)))
+ (func (export "f64.misc") (result i64) (i64.reinterpret_f64 (f64.const 0x1.921fb54442d18p+2)))
+ (func (export "f64.min_positive") (result i64) (i64.reinterpret_f64 (f64.const 0x0.0000000000001p-1022)))
+ (func (export "f64.min_normal") (result i64) (i64.reinterpret_f64 (f64.const 0x1p-1022)))
+ (func (export "f64.max_subnormal") (result i64) (i64.reinterpret_f64 (f64.const 0x0.fffffffffffffp-1022)))
+ (func (export "f64.max_finite") (result i64) (i64.reinterpret_f64 (f64.const 0x1.fffffffffffffp+1023)))
+ (func (export "f64.trailing_dot") (result i64) (i64.reinterpret_f64 (f64.const 0x1.p100)))
+
+ ;; f64 numbers in decimal format
+ (func (export "f64_dec.zero") (result i64) (i64.reinterpret_f64 (f64.const 0.0e0)))
+ (func (export "f64_dec.positive_zero") (result i64) (i64.reinterpret_f64 (f64.const +0.0e0)))
+ (func (export "f64_dec.negative_zero") (result i64) (i64.reinterpret_f64 (f64.const -0.0e0)))
+ (func (export "f64_dec.misc") (result i64) (i64.reinterpret_f64 (f64.const 6.28318530717958623)))
+ (func (export "f64_dec.min_positive") (result i64) (i64.reinterpret_f64 (f64.const 4.94066e-324)))
+ (func (export "f64_dec.min_normal") (result i64) (i64.reinterpret_f64 (f64.const 2.2250738585072012e-308)))
+ (func (export "f64_dec.max_subnormal") (result i64) (i64.reinterpret_f64 (f64.const 2.2250738585072011e-308)))
+ (func (export "f64_dec.max_finite") (result i64) (i64.reinterpret_f64 (f64.const 1.7976931348623157e+308)))
+ (func (export "f64_dec.trailing_dot") (result i64) (i64.reinterpret_f64 (f64.const 1.e100)))
+
+ ;; https://twitter.com/Archivd/status/994637336506912768
+ (func (export "f64_dec.root_beer_float") (result i64) (i64.reinterpret_f64 (f64.const 1.000000119)))
+
+ (func (export "f32-dec-sep1") (result f32) (f32.const 1_000_000))
+ (func (export "f32-dec-sep2") (result f32) (f32.const 1_0_0_0))
+ (func (export "f32-dec-sep3") (result f32) (f32.const 100_3.141_592))
+ (func (export "f32-dec-sep4") (result f32) (f32.const 99e+1_3))
+ (func (export "f32-dec-sep5") (result f32) (f32.const 122_000.11_3_54E0_2_3))
+ (func (export "f32-hex-sep1") (result f32) (f32.const 0xa_0f_00_99))
+ (func (export "f32-hex-sep2") (result f32) (f32.const 0x1_a_A_0_f))
+ (func (export "f32-hex-sep3") (result f32) (f32.const 0xa0_ff.f141_a59a))
+ (func (export "f32-hex-sep4") (result f32) (f32.const 0xf0P+1_3))
+ (func (export "f32-hex-sep5") (result f32) (f32.const 0x2a_f00a.1f_3_eep2_3))
+
+ (func (export "f64-dec-sep1") (result f64) (f64.const 1_000_000))
+ (func (export "f64-dec-sep2") (result f64) (f64.const 1_0_0_0))
+ (func (export "f64-dec-sep3") (result f64) (f64.const 100_3.141_592))
+ (func (export "f64-dec-sep4") (result f64) (f64.const 99e-1_23))
+ (func (export "f64-dec-sep5") (result f64) (f64.const 122_000.11_3_54e0_2_3))
+ (func (export "f64-hex-sep1") (result f64) (f64.const 0xa_f00f_0000_9999))
+ (func (export "f64-hex-sep2") (result f64) (f64.const 0x1_a_A_0_f))
+ (func (export "f64-hex-sep3") (result f64) (f64.const 0xa0_ff.f141_a59a))
+ (func (export "f64-hex-sep4") (result f64) (f64.const 0xf0P+1_3))
+ (func (export "f64-hex-sep5") (result f64) (f64.const 0x2a_f00a.1f_3_eep2_3))
+)`);
+
+// ./test/core/float_literals.wast:105
+assert_return(() => invoke($0, `f32.nan`, []), [value("i32", 2143289344)]);
+
+// ./test/core/float_literals.wast:106
+assert_return(() => invoke($0, `f32.positive_nan`, []), [value("i32", 2143289344)]);
+
+// ./test/core/float_literals.wast:107
+assert_return(() => invoke($0, `f32.negative_nan`, []), [value("i32", -4194304)]);
+
+// ./test/core/float_literals.wast:108
+assert_return(() => invoke($0, `f32.plain_nan`, []), [value("i32", 2143289344)]);
+
+// ./test/core/float_literals.wast:109
+assert_return(() => invoke($0, `f32.informally_known_as_plain_snan`, []), [value("i32", 2141192192)]);
+
+// ./test/core/float_literals.wast:110
+assert_return(() => invoke($0, `f32.all_ones_nan`, []), [value("i32", -1)]);
+
+// ./test/core/float_literals.wast:111
+assert_return(() => invoke($0, `f32.misc_nan`, []), [value("i32", 2139169605)]);
+
+// ./test/core/float_literals.wast:112
+assert_return(() => invoke($0, `f32.misc_positive_nan`, []), [value("i32", 2142257232)]);
+
+// ./test/core/float_literals.wast:113
+assert_return(() => invoke($0, `f32.misc_negative_nan`, []), [value("i32", -5587746)]);
+
+// ./test/core/float_literals.wast:114
+assert_return(() => invoke($0, `f32.infinity`, []), [value("i32", 2139095040)]);
+
+// ./test/core/float_literals.wast:115
+assert_return(() => invoke($0, `f32.positive_infinity`, []), [value("i32", 2139095040)]);
+
+// ./test/core/float_literals.wast:116
+assert_return(() => invoke($0, `f32.negative_infinity`, []), [value("i32", -8388608)]);
+
+// ./test/core/float_literals.wast:117
+assert_return(() => invoke($0, `f32.zero`, []), [value("i32", 0)]);
+
+// ./test/core/float_literals.wast:118
+assert_return(() => invoke($0, `f32.positive_zero`, []), [value("i32", 0)]);
+
+// ./test/core/float_literals.wast:119
+assert_return(() => invoke($0, `f32.negative_zero`, []), [value("i32", -2147483648)]);
+
+// ./test/core/float_literals.wast:120
+assert_return(() => invoke($0, `f32.misc`, []), [value("i32", 1086918619)]);
+
+// ./test/core/float_literals.wast:121
+assert_return(() => invoke($0, `f32.min_positive`, []), [value("i32", 1)]);
+
+// ./test/core/float_literals.wast:122
+assert_return(() => invoke($0, `f32.min_normal`, []), [value("i32", 8388608)]);
+
+// ./test/core/float_literals.wast:123
+assert_return(() => invoke($0, `f32.max_subnormal`, []), [value("i32", 8388607)]);
+
+// ./test/core/float_literals.wast:124
+assert_return(() => invoke($0, `f32.max_finite`, []), [value("i32", 2139095039)]);
+
+// ./test/core/float_literals.wast:125
+assert_return(() => invoke($0, `f32.trailing_dot`, []), [value("i32", 1149239296)]);
+
+// ./test/core/float_literals.wast:126
+assert_return(() => invoke($0, `f32_dec.zero`, []), [value("i32", 0)]);
+
+// ./test/core/float_literals.wast:127
+assert_return(() => invoke($0, `f32_dec.positive_zero`, []), [value("i32", 0)]);
+
+// ./test/core/float_literals.wast:128
+assert_return(() => invoke($0, `f32_dec.negative_zero`, []), [value("i32", -2147483648)]);
+
+// ./test/core/float_literals.wast:129
+assert_return(() => invoke($0, `f32_dec.misc`, []), [value("i32", 1086918619)]);
+
+// ./test/core/float_literals.wast:130
+assert_return(() => invoke($0, `f32_dec.min_positive`, []), [value("i32", 1)]);
+
+// ./test/core/float_literals.wast:131
+assert_return(() => invoke($0, `f32_dec.min_normal`, []), [value("i32", 8388608)]);
+
+// ./test/core/float_literals.wast:132
+assert_return(() => invoke($0, `f32_dec.max_subnormal`, []), [value("i32", 8388607)]);
+
+// ./test/core/float_literals.wast:133
+assert_return(() => invoke($0, `f32_dec.max_finite`, []), [value("i32", 2139095039)]);
+
+// ./test/core/float_literals.wast:134
+assert_return(() => invoke($0, `f32_dec.trailing_dot`, []), [value("i32", 1343554297)]);
+
+// ./test/core/float_literals.wast:135
+assert_return(() => invoke($0, `f32_dec.root_beer_float`, []), [value("i32", 1065353217)]);
+
+// ./test/core/float_literals.wast:137
+assert_return(() => invoke($0, `f64.nan`, []), [value("i64", 9221120237041090560n)]);
+
+// ./test/core/float_literals.wast:138
+assert_return(() => invoke($0, `f64.positive_nan`, []), [value("i64", 9221120237041090560n)]);
+
+// ./test/core/float_literals.wast:139
+assert_return(() => invoke($0, `f64.negative_nan`, []), [value("i64", -2251799813685248n)]);
+
+// ./test/core/float_literals.wast:140
+assert_return(() => invoke($0, `f64.plain_nan`, []), [value("i64", 9221120237041090560n)]);
+
+// ./test/core/float_literals.wast:141
+assert_return(
+ () => invoke($0, `f64.informally_known_as_plain_snan`, []),
+ [value("i64", 9219994337134247936n)],
+);
+
+// ./test/core/float_literals.wast:142
+assert_return(() => invoke($0, `f64.all_ones_nan`, []), [value("i64", -1n)]);
+
+// ./test/core/float_literals.wast:143
+assert_return(() => invoke($0, `f64.misc_nan`, []), [value("i64", 9218888453225749180n)]);
+
+// ./test/core/float_literals.wast:144
+assert_return(() => invoke($0, `f64.misc_positive_nan`, []), [value("i64", 9219717281780008969n)]);
+
+// ./test/core/float_literals.wast:145
+assert_return(() => invoke($0, `f64.misc_negative_nan`, []), [value("i64", -3751748707474619n)]);
+
+// ./test/core/float_literals.wast:146
+assert_return(() => invoke($0, `f64.infinity`, []), [value("i64", 9218868437227405312n)]);
+
+// ./test/core/float_literals.wast:147
+assert_return(() => invoke($0, `f64.positive_infinity`, []), [value("i64", 9218868437227405312n)]);
+
+// ./test/core/float_literals.wast:148
+assert_return(() => invoke($0, `f64.negative_infinity`, []), [value("i64", -4503599627370496n)]);
+
+// ./test/core/float_literals.wast:149
+assert_return(() => invoke($0, `f64.zero`, []), [value("i64", 0n)]);
+
+// ./test/core/float_literals.wast:150
+assert_return(() => invoke($0, `f64.positive_zero`, []), [value("i64", 0n)]);
+
+// ./test/core/float_literals.wast:151
+assert_return(() => invoke($0, `f64.negative_zero`, []), [value("i64", -9223372036854775808n)]);
+
+// ./test/core/float_literals.wast:152
+assert_return(() => invoke($0, `f64.misc`, []), [value("i64", 4618760256179416344n)]);
+
+// ./test/core/float_literals.wast:153
+assert_return(() => invoke($0, `f64.min_positive`, []), [value("i64", 1n)]);
+
+// ./test/core/float_literals.wast:154
+assert_return(() => invoke($0, `f64.min_normal`, []), [value("i64", 4503599627370496n)]);
+
+// ./test/core/float_literals.wast:155
+assert_return(() => invoke($0, `f64.max_subnormal`, []), [value("i64", 4503599627370495n)]);
+
+// ./test/core/float_literals.wast:156
+assert_return(() => invoke($0, `f64.max_finite`, []), [value("i64", 9218868437227405311n)]);
+
+// ./test/core/float_literals.wast:157
+assert_return(() => invoke($0, `f64.trailing_dot`, []), [value("i64", 5057542381537067008n)]);
+
+// ./test/core/float_literals.wast:158
+assert_return(() => invoke($0, `f64_dec.zero`, []), [value("i64", 0n)]);
+
+// ./test/core/float_literals.wast:159
+assert_return(() => invoke($0, `f64_dec.positive_zero`, []), [value("i64", 0n)]);
+
+// ./test/core/float_literals.wast:160
+assert_return(() => invoke($0, `f64_dec.negative_zero`, []), [value("i64", -9223372036854775808n)]);
+
+// ./test/core/float_literals.wast:161
+assert_return(() => invoke($0, `f64_dec.misc`, []), [value("i64", 4618760256179416344n)]);
+
+// ./test/core/float_literals.wast:162
+assert_return(() => invoke($0, `f64_dec.min_positive`, []), [value("i64", 1n)]);
+
+// ./test/core/float_literals.wast:163
+assert_return(() => invoke($0, `f64_dec.min_normal`, []), [value("i64", 4503599627370496n)]);
+
+// ./test/core/float_literals.wast:164
+assert_return(() => invoke($0, `f64_dec.max_subnormal`, []), [value("i64", 4503599627370495n)]);
+
+// ./test/core/float_literals.wast:165
+assert_return(() => invoke($0, `f64_dec.max_finite`, []), [value("i64", 9218868437227405311n)]);
+
+// ./test/core/float_literals.wast:166
+assert_return(() => invoke($0, `f64_dec.trailing_dot`, []), [value("i64", 6103021453049119613n)]);
+
+// ./test/core/float_literals.wast:167
+assert_return(() => invoke($0, `f64_dec.root_beer_float`, []), [value("i64", 4607182419335945764n)]);
+
+// ./test/core/float_literals.wast:169
+assert_return(() => invoke($0, `f32-dec-sep1`, []), [value("f32", 1000000)]);
+
+// ./test/core/float_literals.wast:170
+assert_return(() => invoke($0, `f32-dec-sep2`, []), [value("f32", 1000)]);
+
+// ./test/core/float_literals.wast:171
+assert_return(() => invoke($0, `f32-dec-sep3`, []), [value("f32", 1003.1416)]);
+
+// ./test/core/float_literals.wast:172
+assert_return(() => invoke($0, `f32-dec-sep4`, []), [value("f32", 990000000000000)]);
+
+// ./test/core/float_literals.wast:173
+assert_return(() => invoke($0, `f32-dec-sep5`, []), [value("f32", 12200012000000000000000000000)]);
+
+// ./test/core/float_literals.wast:174
+assert_return(() => invoke($0, `f32-hex-sep1`, []), [value("f32", 168755360)]);
+
+// ./test/core/float_literals.wast:175
+assert_return(() => invoke($0, `f32-hex-sep2`, []), [value("f32", 109071)]);
+
+// ./test/core/float_literals.wast:176
+assert_return(() => invoke($0, `f32-hex-sep3`, []), [value("f32", 41215.94)]);
+
+// ./test/core/float_literals.wast:177
+assert_return(() => invoke($0, `f32-hex-sep4`, []), [value("f32", 1966080)]);
+
+// ./test/core/float_literals.wast:178
+assert_return(() => invoke($0, `f32-hex-sep5`, []), [value("f32", 23605224000000)]);
+
+// ./test/core/float_literals.wast:180
+assert_return(() => invoke($0, `f64-dec-sep1`, []), [value("f64", 1000000)]);
+
+// ./test/core/float_literals.wast:181
+assert_return(() => invoke($0, `f64-dec-sep2`, []), [value("f64", 1000)]);
+
+// ./test/core/float_literals.wast:182
+assert_return(() => invoke($0, `f64-dec-sep3`, []), [value("f64", 1003.141592)]);
+
+// ./test/core/float_literals.wast:183
+assert_return(
+ () => invoke($0, `f64-dec-sep4`, []),
+ [
+ value("f64", 0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000099),
+ ],
+);
+
+// ./test/core/float_literals.wast:184
+assert_return(() => invoke($0, `f64-dec-sep5`, []), [value("f64", 12200011354000000000000000000)]);
+
+// ./test/core/float_literals.wast:185
+assert_return(() => invoke($0, `f64-hex-sep1`, []), [value("f64", 3078696982321561)]);
+
+// ./test/core/float_literals.wast:186
+assert_return(() => invoke($0, `f64-hex-sep2`, []), [value("f64", 109071)]);
+
+// ./test/core/float_literals.wast:187
+assert_return(() => invoke($0, `f64-hex-sep3`, []), [value("f64", 41215.94240794191)]);
+
+// ./test/core/float_literals.wast:188
+assert_return(() => invoke($0, `f64-hex-sep4`, []), [value("f64", 1966080)]);
+
+// ./test/core/float_literals.wast:189
+assert_return(() => invoke($0, `f64-hex-sep5`, []), [value("f64", 23605225168752)]);
+
+// ./test/core/float_literals.wast:192
+let $1 = instantiate(`(module binary
+ ;; (func (export "4294967249") (result f64) (f64.const 4294967249))
+ "\\00\\61\\73\\6d\\01\\00\\00\\00\\01\\85\\80\\80\\80\\00\\01\\60"
+ "\\00\\01\\7c\\03\\82\\80\\80\\80\\00\\01\\00\\07\\8e\\80\\80\\80"
+ "\\00\\01\\0a\\34\\32\\39\\34\\39\\36\\37\\32\\34\\39\\00\\00\\0a"
+ "\\91\\80\\80\\80\\00\\01\\8b\\80\\80\\80\\00\\00\\44\\00\\00\\20"
+ "\\fa\\ff\\ff\\ef\\41\\0b"
+)`);
+
+// ./test/core/float_literals.wast:201
+assert_return(() => invoke($1, `4294967249`, []), [value("f64", 4294967249)]);
+
+// ./test/core/float_literals.wast:203
+assert_malformed(() => instantiate(`(global f32 (f32.const _100)) `), `unknown operator`);
+
+// ./test/core/float_literals.wast:207
+assert_malformed(() => instantiate(`(global f32 (f32.const +_100)) `), `unknown operator`);
+
+// ./test/core/float_literals.wast:211
+assert_malformed(() => instantiate(`(global f32 (f32.const -_100)) `), `unknown operator`);
+
+// ./test/core/float_literals.wast:215
+assert_malformed(() => instantiate(`(global f32 (f32.const 99_)) `), `unknown operator`);
+
+// ./test/core/float_literals.wast:219
+assert_malformed(
+ () => instantiate(`(global f32 (f32.const 1__000)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:223
+assert_malformed(() => instantiate(`(global f32 (f32.const _1.0)) `), `unknown operator`);
+
+// ./test/core/float_literals.wast:227
+assert_malformed(() => instantiate(`(global f32 (f32.const 1.0_)) `), `unknown operator`);
+
+// ./test/core/float_literals.wast:231
+assert_malformed(() => instantiate(`(global f32 (f32.const 1_.0)) `), `unknown operator`);
+
+// ./test/core/float_literals.wast:235
+assert_malformed(() => instantiate(`(global f32 (f32.const 1._0)) `), `unknown operator`);
+
+// ./test/core/float_literals.wast:239
+assert_malformed(() => instantiate(`(global f32 (f32.const _1e1)) `), `unknown operator`);
+
+// ./test/core/float_literals.wast:243
+assert_malformed(() => instantiate(`(global f32 (f32.const 1e1_)) `), `unknown operator`);
+
+// ./test/core/float_literals.wast:247
+assert_malformed(() => instantiate(`(global f32 (f32.const 1_e1)) `), `unknown operator`);
+
+// ./test/core/float_literals.wast:251
+assert_malformed(() => instantiate(`(global f32 (f32.const 1e_1)) `), `unknown operator`);
+
+// ./test/core/float_literals.wast:255
+assert_malformed(
+ () => instantiate(`(global f32 (f32.const _1.0e1)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:259
+assert_malformed(
+ () => instantiate(`(global f32 (f32.const 1.0e1_)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:263
+assert_malformed(
+ () => instantiate(`(global f32 (f32.const 1.0_e1)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:267
+assert_malformed(
+ () => instantiate(`(global f32 (f32.const 1.0e_1)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:271
+assert_malformed(
+ () => instantiate(`(global f32 (f32.const 1.0e+_1)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:275
+assert_malformed(
+ () => instantiate(`(global f32 (f32.const 1.0e_+1)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:279
+assert_malformed(
+ () => instantiate(`(global f32 (f32.const _0x100)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:283
+assert_malformed(
+ () => instantiate(`(global f32 (f32.const 0_x100)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:287
+assert_malformed(
+ () => instantiate(`(global f32 (f32.const 0x_100)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:291
+assert_malformed(() => instantiate(`(global f32 (f32.const 0x00_)) `), `unknown operator`);
+
+// ./test/core/float_literals.wast:295
+assert_malformed(
+ () => instantiate(`(global f32 (f32.const 0xff__ffff)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:299
+assert_malformed(
+ () => instantiate(`(global f32 (f32.const 0x_1.0)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:303
+assert_malformed(
+ () => instantiate(`(global f32 (f32.const 0x1.0_)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:307
+assert_malformed(
+ () => instantiate(`(global f32 (f32.const 0x1_.0)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:311
+assert_malformed(
+ () => instantiate(`(global f32 (f32.const 0x1._0)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:315
+assert_malformed(
+ () => instantiate(`(global f32 (f32.const 0x_1p1)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:319
+assert_malformed(
+ () => instantiate(`(global f32 (f32.const 0x1p1_)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:323
+assert_malformed(
+ () => instantiate(`(global f32 (f32.const 0x1_p1)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:327
+assert_malformed(
+ () => instantiate(`(global f32 (f32.const 0x1p_1)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:331
+assert_malformed(
+ () => instantiate(`(global f32 (f32.const 0x_1.0p1)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:335
+assert_malformed(
+ () => instantiate(`(global f32 (f32.const 0x1.0p1_)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:339
+assert_malformed(
+ () => instantiate(`(global f32 (f32.const 0x1.0_p1)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:343
+assert_malformed(
+ () => instantiate(`(global f32 (f32.const 0x1.0p_1)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:347
+assert_malformed(
+ () => instantiate(`(global f32 (f32.const 0x1.0p+_1)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:351
+assert_malformed(
+ () => instantiate(`(global f32 (f32.const 0x1.0p_+1)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:355
+assert_malformed(
+ () => instantiate(`(global f32 (f32.const nan:0x80_0000)) `),
+ `constant out of range`,
+);
+
+// ./test/core/float_literals.wast:360
+assert_malformed(() => instantiate(`(global f64 (f64.const _100)) `), `unknown operator`);
+
+// ./test/core/float_literals.wast:364
+assert_malformed(() => instantiate(`(global f64 (f64.const +_100)) `), `unknown operator`);
+
+// ./test/core/float_literals.wast:368
+assert_malformed(() => instantiate(`(global f64 (f64.const -_100)) `), `unknown operator`);
+
+// ./test/core/float_literals.wast:372
+assert_malformed(() => instantiate(`(global f64 (f64.const 99_)) `), `unknown operator`);
+
+// ./test/core/float_literals.wast:376
+assert_malformed(
+ () => instantiate(`(global f64 (f64.const 1__000)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:380
+assert_malformed(() => instantiate(`(global f64 (f64.const _1.0)) `), `unknown operator`);
+
+// ./test/core/float_literals.wast:384
+assert_malformed(() => instantiate(`(global f64 (f64.const 1.0_)) `), `unknown operator`);
+
+// ./test/core/float_literals.wast:388
+assert_malformed(() => instantiate(`(global f64 (f64.const 1_.0)) `), `unknown operator`);
+
+// ./test/core/float_literals.wast:392
+assert_malformed(() => instantiate(`(global f64 (f64.const 1._0)) `), `unknown operator`);
+
+// ./test/core/float_literals.wast:396
+assert_malformed(() => instantiate(`(global f64 (f64.const _1e1)) `), `unknown operator`);
+
+// ./test/core/float_literals.wast:400
+assert_malformed(() => instantiate(`(global f64 (f64.const 1e1_)) `), `unknown operator`);
+
+// ./test/core/float_literals.wast:404
+assert_malformed(() => instantiate(`(global f64 (f64.const 1_e1)) `), `unknown operator`);
+
+// ./test/core/float_literals.wast:408
+assert_malformed(() => instantiate(`(global f64 (f64.const 1e_1)) `), `unknown operator`);
+
+// ./test/core/float_literals.wast:412
+assert_malformed(
+ () => instantiate(`(global f64 (f64.const _1.0e1)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:416
+assert_malformed(
+ () => instantiate(`(global f64 (f64.const 1.0e1_)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:420
+assert_malformed(
+ () => instantiate(`(global f64 (f64.const 1.0_e1)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:424
+assert_malformed(
+ () => instantiate(`(global f64 (f64.const 1.0e_1)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:428
+assert_malformed(
+ () => instantiate(`(global f64 (f64.const 1.0e+_1)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:432
+assert_malformed(
+ () => instantiate(`(global f64 (f64.const 1.0e_+1)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:436
+assert_malformed(
+ () => instantiate(`(global f64 (f64.const _0x100)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:440
+assert_malformed(
+ () => instantiate(`(global f64 (f64.const 0_x100)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:444
+assert_malformed(
+ () => instantiate(`(global f64 (f64.const 0x_100)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:448
+assert_malformed(() => instantiate(`(global f64 (f64.const 0x00_)) `), `unknown operator`);
+
+// ./test/core/float_literals.wast:452
+assert_malformed(
+ () => instantiate(`(global f64 (f64.const 0xff__ffff)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:456
+assert_malformed(
+ () => instantiate(`(global f64 (f64.const 0x_1.0)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:460
+assert_malformed(
+ () => instantiate(`(global f64 (f64.const 0x1.0_)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:464
+assert_malformed(
+ () => instantiate(`(global f64 (f64.const 0x1_.0)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:468
+assert_malformed(
+ () => instantiate(`(global f64 (f64.const 0x1._0)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:472
+assert_malformed(
+ () => instantiate(`(global f64 (f64.const 0x_1p1)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:476
+assert_malformed(
+ () => instantiate(`(global f64 (f64.const 0x1p1_)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:480
+assert_malformed(
+ () => instantiate(`(global f64 (f64.const 0x1_p1)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:484
+assert_malformed(
+ () => instantiate(`(global f64 (f64.const 0x1p_1)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:488
+assert_malformed(
+ () => instantiate(`(global f64 (f64.const 0x_1.0p1)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:492
+assert_malformed(
+ () => instantiate(`(global f64 (f64.const 0x1.0p1_)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:496
+assert_malformed(
+ () => instantiate(`(global f64 (f64.const 0x1.0_p1)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:500
+assert_malformed(
+ () => instantiate(`(global f64 (f64.const 0x1.0p_1)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:504
+assert_malformed(
+ () => instantiate(`(global f64 (f64.const 0x1.0p+_1)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:508
+assert_malformed(
+ () => instantiate(`(global f64 (f64.const 0x1.0p_+1)) `),
+ `unknown operator`,
+);
+
+// ./test/core/float_literals.wast:512
+assert_malformed(
+ () => instantiate(`(global f64 (f64.const nan:0x10_0000_0000_0000)) `),
+ `constant out of range`,
+);
diff --git a/js/src/jit-test/tests/wasm/spec/gc/global.wast.js b/js/src/jit-test/tests/wasm/spec/gc/global.wast.js
new file mode 100644
index 0000000000..21ace9e66d
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/spec/gc/global.wast.js
@@ -0,0 +1,869 @@
+/* Copyright 2021 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ./test/core/global.wast
+
+// ./test/core/global.wast:3
+let $0 = instantiate(`(module
+ (global (import "spectest" "global_i32") i32)
+ (global (import "spectest" "global_i64") i64)
+
+ (global $$a i32 (i32.const -2))
+ (global (;3;) f32 (f32.const -3))
+ (global (;4;) f64 (f64.const -4))
+ (global $$b i64 (i64.const -5))
+
+ (global $$x (mut i32) (i32.const -12))
+ (global (;7;) (mut f32) (f32.const -13))
+ (global (;8;) (mut f64) (f64.const -14))
+ (global $$y (mut i64) (i64.const -15))
+
+ (global $$z1 i32 (global.get 0))
+ (global $$z2 i64 (global.get 1))
+
+ (global $$r externref (ref.null extern))
+ (global $$mr (mut externref) (ref.null extern))
+ (global funcref (ref.null func))
+
+ (func (export "get-a") (result i32) (global.get $$a))
+ (func (export "get-b") (result i64) (global.get $$b))
+ (func (export "get-r") (result externref) (global.get $$r))
+ (func (export "get-mr") (result externref) (global.get $$mr))
+ (func (export "get-x") (result i32) (global.get $$x))
+ (func (export "get-y") (result i64) (global.get $$y))
+ (func (export "get-z1") (result i32) (global.get $$z1))
+ (func (export "get-z2") (result i64) (global.get $$z2))
+ (func (export "set-x") (param i32) (global.set $$x (local.get 0)))
+ (func (export "set-y") (param i64) (global.set $$y (local.get 0)))
+ (func (export "set-mr") (param externref) (global.set $$mr (local.get 0)))
+
+ (func (export "get-3") (result f32) (global.get 3))
+ (func (export "get-4") (result f64) (global.get 4))
+ (func (export "get-7") (result f32) (global.get 7))
+ (func (export "get-8") (result f64) (global.get 8))
+ (func (export "set-7") (param f32) (global.set 7 (local.get 0)))
+ (func (export "set-8") (param f64) (global.set 8 (local.get 0)))
+
+ ;; As the argument of control constructs and instructions
+
+ (memory 1)
+
+ (func $$dummy)
+
+ (func (export "as-select-first") (result i32)
+ (select (global.get $$x) (i32.const 2) (i32.const 3))
+ )
+ (func (export "as-select-mid") (result i32)
+ (select (i32.const 2) (global.get $$x) (i32.const 3))
+ )
+ (func (export "as-select-last") (result i32)
+ (select (i32.const 2) (i32.const 3) (global.get $$x))
+ )
+
+ (func (export "as-loop-first") (result i32)
+ (loop (result i32)
+ (global.get $$x) (call $$dummy) (call $$dummy)
+ )
+ )
+ (func (export "as-loop-mid") (result i32)
+ (loop (result i32)
+ (call $$dummy) (global.get $$x) (call $$dummy)
+ )
+ )
+ (func (export "as-loop-last") (result i32)
+ (loop (result i32)
+ (call $$dummy) (call $$dummy) (global.get $$x)
+ )
+ )
+
+ (func (export "as-if-condition") (result i32)
+ (if (result i32) (global.get $$x)
+ (then (call $$dummy) (i32.const 2))
+ (else (call $$dummy) (i32.const 3))
+ )
+ )
+ (func (export "as-if-then") (result i32)
+ (if (result i32) (i32.const 1)
+ (then (global.get $$x)) (else (i32.const 2))
+ )
+ )
+ (func (export "as-if-else") (result i32)
+ (if (result i32) (i32.const 0)
+ (then (i32.const 2)) (else (global.get $$x))
+ )
+ )
+
+ (func (export "as-br_if-first") (result i32)
+ (block (result i32)
+ (br_if 0 (global.get $$x) (i32.const 2))
+ (return (i32.const 3))
+ )
+ )
+ (func (export "as-br_if-last") (result i32)
+ (block (result i32)
+ (br_if 0 (i32.const 2) (global.get $$x))
+ (return (i32.const 3))
+ )
+ )
+
+ (func (export "as-br_table-first") (result i32)
+ (block (result i32)
+ (global.get $$x) (i32.const 2) (br_table 0 0)
+ )
+ )
+ (func (export "as-br_table-last") (result i32)
+ (block (result i32)
+ (i32.const 2) (global.get $$x) (br_table 0 0)
+ )
+ )
+
+ (func $$func (param i32 i32) (result i32) (local.get 0))
+ (type $$check (func (param i32 i32) (result i32)))
+ (table funcref (elem $$func))
+ (func (export "as-call_indirect-first") (result i32)
+ (block (result i32)
+ (call_indirect (type $$check)
+ (global.get $$x) (i32.const 2) (i32.const 0)
+ )
+ )
+ )
+ (func (export "as-call_indirect-mid") (result i32)
+ (block (result i32)
+ (call_indirect (type $$check)
+ (i32.const 2) (global.get $$x) (i32.const 0)
+ )
+ )
+ )
+ (func (export "as-call_indirect-last") (result i32)
+ (block (result i32)
+ (call_indirect (type $$check)
+ (i32.const 2) (i32.const 0) (global.get $$x)
+ )
+ )
+ )
+
+ (func (export "as-store-first")
+ (global.get $$x) (i32.const 1) (i32.store)
+ )
+ (func (export "as-store-last")
+ (i32.const 0) (global.get $$x) (i32.store)
+ )
+ (func (export "as-load-operand") (result i32)
+ (i32.load (global.get $$x))
+ )
+ (func (export "as-memory.grow-value") (result i32)
+ (memory.grow (global.get $$x))
+ )
+
+ (func $$f (param i32) (result i32) (local.get 0))
+ (func (export "as-call-value") (result i32)
+ (call $$f (global.get $$x))
+ )
+
+ (func (export "as-return-value") (result i32)
+ (global.get $$x) (return)
+ )
+ (func (export "as-drop-operand")
+ (drop (global.get $$x))
+ )
+ (func (export "as-br-value") (result i32)
+ (block (result i32) (br 0 (global.get $$x)))
+ )
+
+ (func (export "as-local.set-value") (param i32) (result i32)
+ (local.set 0 (global.get $$x))
+ (local.get 0)
+ )
+ (func (export "as-local.tee-value") (param i32) (result i32)
+ (local.tee 0 (global.get $$x))
+ )
+ (func (export "as-global.set-value") (result i32)
+ (global.set $$x (global.get $$x))
+ (global.get $$x)
+ )
+
+ (func (export "as-unary-operand") (result i32)
+ (i32.eqz (global.get $$x))
+ )
+ (func (export "as-binary-operand") (result i32)
+ (i32.mul
+ (global.get $$x) (global.get $$x)
+ )
+ )
+ (func (export "as-compare-operand") (result i32)
+ (i32.gt_u
+ (global.get 0) (i32.const 1)
+ )
+ )
+)`);
+
+// ./test/core/global.wast:196
+assert_return(() => invoke($0, `get-a`, []), [value("i32", -2)]);
+
+// ./test/core/global.wast:197
+assert_return(() => invoke($0, `get-b`, []), [value("i64", -5n)]);
+
+// ./test/core/global.wast:198
+assert_return(() => invoke($0, `get-r`, []), [value('externref', null)]);
+
+// ./test/core/global.wast:199
+assert_return(() => invoke($0, `get-mr`, []), [value('externref', null)]);
+
+// ./test/core/global.wast:200
+assert_return(() => invoke($0, `get-x`, []), [value("i32", -12)]);
+
+// ./test/core/global.wast:201
+assert_return(() => invoke($0, `get-y`, []), [value("i64", -15n)]);
+
+// ./test/core/global.wast:202
+assert_return(() => invoke($0, `get-z1`, []), [value("i32", 666)]);
+
+// ./test/core/global.wast:203
+assert_return(() => invoke($0, `get-z2`, []), [value("i64", 666n)]);
+
+// ./test/core/global.wast:205
+assert_return(() => invoke($0, `get-3`, []), [value("f32", -3)]);
+
+// ./test/core/global.wast:206
+assert_return(() => invoke($0, `get-4`, []), [value("f64", -4)]);
+
+// ./test/core/global.wast:207
+assert_return(() => invoke($0, `get-7`, []), [value("f32", -13)]);
+
+// ./test/core/global.wast:208
+assert_return(() => invoke($0, `get-8`, []), [value("f64", -14)]);
+
+// ./test/core/global.wast:210
+assert_return(() => invoke($0, `set-x`, [6]), []);
+
+// ./test/core/global.wast:211
+assert_return(() => invoke($0, `set-y`, [7n]), []);
+
+// ./test/core/global.wast:213
+assert_return(() => invoke($0, `set-7`, [value("f32", 8)]), []);
+
+// ./test/core/global.wast:214
+assert_return(() => invoke($0, `set-8`, [value("f64", 9)]), []);
+
+// ./test/core/global.wast:216
+assert_return(() => invoke($0, `get-x`, []), [value("i32", 6)]);
+
+// ./test/core/global.wast:217
+assert_return(() => invoke($0, `get-y`, []), [value("i64", 7n)]);
+
+// ./test/core/global.wast:218
+assert_return(() => invoke($0, `get-7`, []), [value("f32", 8)]);
+
+// ./test/core/global.wast:219
+assert_return(() => invoke($0, `get-8`, []), [value("f64", 9)]);
+
+// ./test/core/global.wast:221
+assert_return(() => invoke($0, `set-7`, [value("f32", 8)]), []);
+
+// ./test/core/global.wast:222
+assert_return(() => invoke($0, `set-8`, [value("f64", 9)]), []);
+
+// ./test/core/global.wast:223
+assert_return(() => invoke($0, `set-mr`, [externref(10)]), []);
+
+// ./test/core/global.wast:225
+assert_return(() => invoke($0, `get-x`, []), [value("i32", 6)]);
+
+// ./test/core/global.wast:226
+assert_return(() => invoke($0, `get-y`, []), [value("i64", 7n)]);
+
+// ./test/core/global.wast:227
+assert_return(() => invoke($0, `get-7`, []), [value("f32", 8)]);
+
+// ./test/core/global.wast:228
+assert_return(() => invoke($0, `get-8`, []), [value("f64", 9)]);
+
+// ./test/core/global.wast:229
+assert_return(() => invoke($0, `get-mr`, []), [new ExternRefResult(10)]);
+
+// ./test/core/global.wast:231
+assert_return(() => invoke($0, `as-select-first`, []), [value("i32", 6)]);
+
+// ./test/core/global.wast:232
+assert_return(() => invoke($0, `as-select-mid`, []), [value("i32", 2)]);
+
+// ./test/core/global.wast:233
+assert_return(() => invoke($0, `as-select-last`, []), [value("i32", 2)]);
+
+// ./test/core/global.wast:235
+assert_return(() => invoke($0, `as-loop-first`, []), [value("i32", 6)]);
+
+// ./test/core/global.wast:236
+assert_return(() => invoke($0, `as-loop-mid`, []), [value("i32", 6)]);
+
+// ./test/core/global.wast:237
+assert_return(() => invoke($0, `as-loop-last`, []), [value("i32", 6)]);
+
+// ./test/core/global.wast:239
+assert_return(() => invoke($0, `as-if-condition`, []), [value("i32", 2)]);
+
+// ./test/core/global.wast:240
+assert_return(() => invoke($0, `as-if-then`, []), [value("i32", 6)]);
+
+// ./test/core/global.wast:241
+assert_return(() => invoke($0, `as-if-else`, []), [value("i32", 6)]);
+
+// ./test/core/global.wast:243
+assert_return(() => invoke($0, `as-br_if-first`, []), [value("i32", 6)]);
+
+// ./test/core/global.wast:244
+assert_return(() => invoke($0, `as-br_if-last`, []), [value("i32", 2)]);
+
+// ./test/core/global.wast:246
+assert_return(() => invoke($0, `as-br_table-first`, []), [value("i32", 6)]);
+
+// ./test/core/global.wast:247
+assert_return(() => invoke($0, `as-br_table-last`, []), [value("i32", 2)]);
+
+// ./test/core/global.wast:249
+assert_return(() => invoke($0, `as-call_indirect-first`, []), [value("i32", 6)]);
+
+// ./test/core/global.wast:250
+assert_return(() => invoke($0, `as-call_indirect-mid`, []), [value("i32", 2)]);
+
+// ./test/core/global.wast:251
+assert_trap(() => invoke($0, `as-call_indirect-last`, []), `undefined element`);
+
+// ./test/core/global.wast:253
+assert_return(() => invoke($0, `as-store-first`, []), []);
+
+// ./test/core/global.wast:254
+assert_return(() => invoke($0, `as-store-last`, []), []);
+
+// ./test/core/global.wast:255
+assert_return(() => invoke($0, `as-load-operand`, []), [value("i32", 1)]);
+
+// ./test/core/global.wast:256
+assert_return(() => invoke($0, `as-memory.grow-value`, []), [value("i32", 1)]);
+
+// ./test/core/global.wast:258
+assert_return(() => invoke($0, `as-call-value`, []), [value("i32", 6)]);
+
+// ./test/core/global.wast:260
+assert_return(() => invoke($0, `as-return-value`, []), [value("i32", 6)]);
+
+// ./test/core/global.wast:261
+assert_return(() => invoke($0, `as-drop-operand`, []), []);
+
+// ./test/core/global.wast:262
+assert_return(() => invoke($0, `as-br-value`, []), [value("i32", 6)]);
+
+// ./test/core/global.wast:264
+assert_return(() => invoke($0, `as-local.set-value`, [1]), [value("i32", 6)]);
+
+// ./test/core/global.wast:265
+assert_return(() => invoke($0, `as-local.tee-value`, [1]), [value("i32", 6)]);
+
+// ./test/core/global.wast:266
+assert_return(() => invoke($0, `as-global.set-value`, []), [value("i32", 6)]);
+
+// ./test/core/global.wast:268
+assert_return(() => invoke($0, `as-unary-operand`, []), [value("i32", 0)]);
+
+// ./test/core/global.wast:269
+assert_return(() => invoke($0, `as-binary-operand`, []), [value("i32", 36)]);
+
+// ./test/core/global.wast:270
+assert_return(() => invoke($0, `as-compare-operand`, []), [value("i32", 1)]);
+
+// ./test/core/global.wast:272
+assert_invalid(
+ () => instantiate(`(module (global f32 (f32.const 0)) (func (global.set 0 (f32.const 1))))`),
+ `immutable global`,
+);
+
+// ./test/core/global.wast:277
+assert_invalid(
+ () => instantiate(`(module (import "spectest" "global_i32" (global i32)) (func (global.set 0 (i32.const 1))))`),
+ `immutable global`,
+);
+
+// ./test/core/global.wast:283
+let $1 = instantiate(`(module (global (mut f32) (f32.const 0)) (export "a" (global 0)))`);
+
+// ./test/core/global.wast:284
+let $2 = instantiate(`(module (global (export "a") (mut f32) (f32.const 0)))`);
+
+// ./test/core/global.wast:286
+assert_invalid(
+ () => instantiate(`(module (global f32 (f32.neg (f32.const 0))))`),
+ `constant expression required`,
+);
+
+// ./test/core/global.wast:291
+assert_invalid(
+ () => instantiate(`(module (global f32 (local.get 0)))`),
+ `constant expression required`,
+);
+
+// ./test/core/global.wast:296
+assert_invalid(
+ () => instantiate(`(module (global f32 (f32.neg (f32.const 1))))`),
+ `constant expression required`,
+);
+
+// ./test/core/global.wast:301
+assert_invalid(
+ () => instantiate(`(module (global i32 (i32.const 0) (nop)))`),
+ `constant expression required`,
+);
+
+// ./test/core/global.wast:306
+assert_invalid(
+ () => instantiate(`(module (global i32 (i32.ctz (i32.const 0))))`),
+ `constant expression required`,
+);
+
+// ./test/core/global.wast:311
+assert_invalid(
+ () => instantiate(`(module (global i32 (nop)))`),
+ `constant expression required`,
+);
+
+// ./test/core/global.wast:316
+assert_invalid(() => instantiate(`(module (global i32 (f32.const 0)))`), `type mismatch`);
+
+// ./test/core/global.wast:321
+assert_invalid(
+ () => instantiate(`(module (global i32 (i32.const 0) (i32.const 0)))`),
+ `type mismatch`,
+);
+
+// ./test/core/global.wast:326
+assert_invalid(
+ () => instantiate(`(module (global i32 (;empty instruction sequence;)))`),
+ `type mismatch`,
+);
+
+// ./test/core/global.wast:331
+assert_invalid(
+ () => instantiate(`(module (global (import "" "") externref) (global funcref (global.get 0)))`),
+ `type mismatch`,
+);
+
+// ./test/core/global.wast:336
+assert_invalid(
+ () => instantiate(`(module (global (import "test" "global-i32") i32) (global i32 (global.get 0) (global.get 0)))`),
+ `type mismatch`,
+);
+
+// ./test/core/global.wast:341
+assert_invalid(
+ () => instantiate(`(module (global (import "test" "global-i32") i32) (global i32 (i32.const 0) (global.get 0)))`),
+ `type mismatch`,
+);
+
+// ./test/core/global.wast:346
+assert_invalid(
+ () => instantiate(`(module (global i32 (global.get 0)))`),
+ `unknown global`,
+);
+
+// ./test/core/global.wast:351
+assert_invalid(
+ () => instantiate(`(module (global i32 (global.get 1)) (global i32 (i32.const 0)))`),
+ `unknown global`,
+);
+
+// ./test/core/global.wast:356
+assert_invalid(
+ () => instantiate(`(module (global (import "test" "global-i32") i32) (global i32 (global.get 2)))`),
+ `unknown global`,
+);
+
+// ./test/core/global.wast:361
+let $3 = instantiate(`(module (global i32 (i32.const 0)) (global i32 (global.get 0)))`);
+
+// ./test/core/global.wast:362
+let $4 = instantiate(`(module (global $$g i32 (i32.const 0)) (global i32 (global.get $$g)))`);
+
+// ./test/core/global.wast:364
+assert_invalid(
+ () => instantiate(`(module (global (import "test" "global-mut-i32") (mut i32)) (global i32 (global.get 0)))`),
+ `constant expression required`,
+);
+
+// ./test/core/global.wast:369
+let $5 = instantiate(`(module
+ (import "spectest" "global_i32" (global i32))
+)`);
+
+// ./test/core/global.wast:372
+assert_malformed(
+ () => instantiate(`(module binary
+ "\\00asm" "\\01\\00\\00\\00"
+ "\\02\\98\\80\\80\\80\\00" ;; import section
+ "\\01" ;; length 1
+ "\\08\\73\\70\\65\\63\\74\\65\\73\\74" ;; "spectest"
+ "\\0a\\67\\6c\\6f\\62\\61\\6c\\5f\\69\\33\\32" ;; "global_i32"
+ "\\03" ;; GlobalImport
+ "\\7f" ;; i32
+ "\\02" ;; malformed mutability
+ )`),
+ `malformed mutability`,
+);
+
+// ./test/core/global.wast:385
+assert_malformed(
+ () => instantiate(`(module binary
+ "\\00asm" "\\01\\00\\00\\00"
+ "\\02\\98\\80\\80\\80\\00" ;; import section
+ "\\01" ;; length 1
+ "\\08\\73\\70\\65\\63\\74\\65\\73\\74" ;; "spectest"
+ "\\0a\\67\\6c\\6f\\62\\61\\6c\\5f\\69\\33\\32" ;; "global_i32"
+ "\\03" ;; GlobalImport
+ "\\7f" ;; i32
+ "\\ff" ;; malformed mutability
+ )`),
+ `malformed mutability`,
+);
+
+// ./test/core/global.wast:399
+let $6 = instantiate(`(module
+ (global i32 (i32.const 0))
+)`);
+
+// ./test/core/global.wast:402
+assert_malformed(
+ () => instantiate(`(module binary
+ "\\00asm" "\\01\\00\\00\\00"
+ "\\06\\86\\80\\80\\80\\00" ;; global section
+ "\\01" ;; length 1
+ "\\7f" ;; i32
+ "\\02" ;; malformed mutability
+ "\\41\\00" ;; i32.const 0
+ "\\0b" ;; end
+ )`),
+ `malformed mutability`,
+);
+
+// ./test/core/global.wast:414
+assert_malformed(
+ () => instantiate(`(module binary
+ "\\00asm" "\\01\\00\\00\\00"
+ "\\06\\86\\80\\80\\80\\00" ;; global section
+ "\\01" ;; length 1
+ "\\7f" ;; i32
+ "\\ff" ;; malformed mutability
+ "\\41\\00" ;; i32.const 0
+ "\\0b" ;; end
+ )`),
+ `malformed mutability`,
+);
+
+// ./test/core/global.wast:428
+assert_invalid(
+ () => instantiate(`(module (func (result i32) (global.get 0)))`),
+ `unknown global`,
+);
+
+// ./test/core/global.wast:433
+assert_invalid(
+ () => instantiate(`(module
+ (global i32 (i32.const 0))
+ (func (result i32) (global.get 1))
+ )`),
+ `unknown global`,
+);
+
+// ./test/core/global.wast:441
+assert_invalid(
+ () => instantiate(`(module
+ (import "spectest" "global_i32" (global i32))
+ (func (result i32) (global.get 1))
+ )`),
+ `unknown global`,
+);
+
+// ./test/core/global.wast:449
+assert_invalid(
+ () => instantiate(`(module
+ (import "spectest" "global_i32" (global i32))
+ (global i32 (i32.const 0))
+ (func (result i32) (global.get 2))
+ )`),
+ `unknown global`,
+);
+
+// ./test/core/global.wast:459
+assert_invalid(
+ () => instantiate(`(module (func (i32.const 0) (global.set 0)))`),
+ `unknown global`,
+);
+
+// ./test/core/global.wast:464
+assert_invalid(
+ () => instantiate(`(module
+ (global i32 (i32.const 0))
+ (func (i32.const 0) (global.set 1))
+ )`),
+ `unknown global`,
+);
+
+// ./test/core/global.wast:472
+assert_invalid(
+ () => instantiate(`(module
+ (import "spectest" "global_i32" (global i32))
+ (func (i32.const 0) (global.set 1))
+ )`),
+ `unknown global`,
+);
+
+// ./test/core/global.wast:480
+assert_invalid(
+ () => instantiate(`(module
+ (import "spectest" "global_i32" (global i32))
+ (global i32 (i32.const 0))
+ (func (i32.const 0) (global.set 2))
+ )`),
+ `unknown global`,
+);
+
+// ./test/core/global.wast:490
+assert_invalid(
+ () => instantiate(`(module
+ (global $$x (mut i32) (i32.const 0))
+ (func $$type-global.set-value-empty
+ (global.set $$x)
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/global.wast:499
+assert_invalid(
+ () => instantiate(`(module
+ (global $$x (mut i32) (i32.const 0))
+ (func $$type-global.set-value-empty-in-block
+ (i32.const 0)
+ (block (global.set $$x))
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/global.wast:509
+assert_invalid(
+ () => instantiate(`(module
+ (global $$x (mut i32) (i32.const 0))
+ (func $$type-global.set-value-empty-in-loop
+ (i32.const 0)
+ (loop (global.set $$x))
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/global.wast:519
+assert_invalid(
+ () => instantiate(`(module
+ (global $$x (mut i32) (i32.const 0))
+ (func $$type-global.set-value-empty-in-then
+ (i32.const 0) (i32.const 0)
+ (if (then (global.set $$x)))
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/global.wast:529
+assert_invalid(
+ () => instantiate(`(module
+ (global $$x (mut i32) (i32.const 0))
+ (func $$type-global.set-value-empty-in-else
+ (i32.const 0) (i32.const 0)
+ (if (result i32) (then (i32.const 0)) (else (global.set $$x)))
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/global.wast:539
+assert_invalid(
+ () => instantiate(`(module
+ (global $$x (mut i32) (i32.const 0))
+ (func $$type-global.set-value-empty-in-br
+ (i32.const 0)
+ (block (br 0 (global.set $$x)))
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/global.wast:549
+assert_invalid(
+ () => instantiate(`(module
+ (global $$x (mut i32) (i32.const 0))
+ (func $$type-global.set-value-empty-in-br_if
+ (i32.const 0)
+ (block (br_if 0 (global.set $$x)))
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/global.wast:559
+assert_invalid(
+ () => instantiate(`(module
+ (global $$x (mut i32) (i32.const 0))
+ (func $$type-global.set-value-empty-in-br_table
+ (i32.const 0)
+ (block (br_table 0 (global.set $$x)))
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/global.wast:569
+assert_invalid(
+ () => instantiate(`(module
+ (global $$x (mut i32) (i32.const 0))
+ (func $$type-global.set-value-empty-in-return
+ (return (global.set $$x))
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/global.wast:578
+assert_invalid(
+ () => instantiate(`(module
+ (global $$x (mut i32) (i32.const 0))
+ (func $$type-global.set-value-empty-in-select
+ (select (global.set $$x) (i32.const 1) (i32.const 2))
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/global.wast:587
+assert_invalid(
+ () => instantiate(`(module
+ (global $$x (mut i32) (i32.const 0))
+ (func $$type-global.set-value-empty-in-call
+ (call 1 (global.set $$x))
+ )
+ (func (param i32) (result i32) (local.get 0))
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/global.wast:597
+assert_invalid(
+ () => instantiate(`(module
+ (global $$x (mut i32) (i32.const 0))
+ (func $$f (param i32) (result i32) (local.get 0))
+ (type $$sig (func (param i32) (result i32)))
+ (table funcref (elem $$f))
+ (func $$type-global.set-value-empty-in-call_indirect
+ (block (result i32)
+ (call_indirect (type $$sig)
+ (global.set $$x) (i32.const 0)
+ )
+ )
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/global.wast:617
+let $7 = instantiate(`(module
+ (global (export "g") i32 (i32.const 4))
+)`);
+
+// ./test/core/global.wast:620
+register($7, `G`);
+
+// ./test/core/global.wast:622
+let $8 = instantiate(`(module
+ (global $$g0 (import "G" "g") i32)
+ (global $$g1 i32 (i32.const 8))
+ (global $$g2 i32 (global.get $$g0))
+ (global $$g3 i32 (global.get $$g1))
+
+ (global $$gf funcref (ref.func $$f))
+ (func $$f)
+
+ (table $$t 10 funcref (ref.null func))
+ (elem (table $$t) (global.get $$g2) funcref (ref.func $$f))
+ (elem (table $$t) (global.get $$g3) funcref (global.get $$gf))
+
+ (memory $$m 1)
+ (data (global.get $$g2) "\\44\\44\\44\\44")
+ (data (global.get $$g3) "\\88\\88\\88\\88")
+
+ (func (export "get-elem") (param $$i i32) (result funcref)
+ (table.get $$t (local.get $$i))
+ )
+ (func (export "get-data") (param $$i i32) (result i32)
+ (i32.load (local.get $$i))
+ )
+)`);
+
+// ./test/core/global.wast:647
+assert_return(() => invoke($8, `get-elem`, [0]), [null]);
+
+// ./test/core/global.wast:648
+assert_return(() => invoke($8, `get-elem`, [4]), [new RefWithType('funcref')]);
+
+// ./test/core/global.wast:649
+assert_return(() => invoke($8, `get-elem`, [8]), [new RefWithType('funcref')]);
+
+// ./test/core/global.wast:651
+assert_return(() => invoke($8, `get-data`, [4]), [value("i32", 1145324612)]);
+
+// ./test/core/global.wast:652
+assert_return(() => invoke($8, `get-data`, [8]), [value("i32", -2004318072)]);
+
+// ./test/core/global.wast:654
+assert_invalid(
+ () => instantiate(`(module
+ (global $$g1 i32 (global.get $$g2))
+ (global $$g2 i32 (i32.const 0))
+ )`),
+ `unknown global`,
+);
+
+// ./test/core/global.wast:662
+assert_invalid(
+ () => instantiate(`(module
+ (global $$g funcref (ref.null func))
+ (table $$t 10 funcref (global.get $$g))
+ )`),
+ `unknown global`,
+);
+
+// ./test/core/global.wast:673
+assert_malformed(
+ () => instantiate(`(global $$foo i32 (i32.const 0)) (global $$foo i32 (i32.const 0)) `),
+ `duplicate global`,
+);
+
+// ./test/core/global.wast:680
+assert_malformed(
+ () => instantiate(`(import "" "" (global $$foo i32)) (global $$foo i32 (i32.const 0)) `),
+ `duplicate global`,
+);
+
+// ./test/core/global.wast:687
+assert_malformed(
+ () => instantiate(`(import "" "" (global $$foo i32)) (import "" "" (global $$foo i32)) `),
+ `duplicate global`,
+);
diff --git a/js/src/jit-test/tests/wasm/spec/gc/harness/directives.txt b/js/src/jit-test/tests/wasm/spec/gc/harness/directives.txt
new file mode 100644
index 0000000000..d41243abbb
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/spec/gc/harness/directives.txt
@@ -0,0 +1 @@
+|jit-test| skip-if: true \ No newline at end of file
diff --git a/js/src/jit-test/tests/wasm/spec/gc/harness/harness.js b/js/src/jit-test/tests/wasm/spec/gc/harness/harness.js
new file mode 100644
index 0000000000..a96781e8ed
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/spec/gc/harness/harness.js
@@ -0,0 +1,448 @@
+"use strict";
+
+/* Copyright 2021 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+if (!wasmIsSupported()) {
+ quit();
+}
+
+function bytes(type, bytes) {
+ var typedBuffer = new Uint8Array(bytes);
+ return wasmGlobalFromArrayBuffer(type, typedBuffer.buffer);
+}
+function value(type, value) {
+ return new WebAssembly.Global({
+ value: type,
+ mutable: false,
+ }, value);
+}
+
+function i8x16(elements) {
+ let typedBuffer = new Uint8Array(elements);
+ return wasmGlobalFromArrayBuffer("v128", typedBuffer.buffer);
+}
+function i16x8(elements) {
+ let typedBuffer = new Uint16Array(elements);
+ return wasmGlobalFromArrayBuffer("v128", typedBuffer.buffer);
+}
+function i32x4(elements) {
+ let typedBuffer = new Uint32Array(elements);
+ return wasmGlobalFromArrayBuffer("v128", typedBuffer.buffer);
+}
+function i64x2(elements) {
+ let typedBuffer = new BigUint64Array(elements);
+ return wasmGlobalFromArrayBuffer("v128", typedBuffer.buffer);
+}
+function f32x4(elements) {
+ let typedBuffer = new Float32Array(elements);
+ return wasmGlobalFromArrayBuffer("v128", typedBuffer.buffer);
+}
+function f64x2(elements) {
+ let typedBuffer = new Float64Array(elements);
+ return wasmGlobalFromArrayBuffer("v128", typedBuffer.buffer);
+}
+
+function either(...arr) {
+ return new EitherVariants(arr);
+}
+
+class F32x4Pattern {
+ constructor(x, y, z, w) {
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ this.w = w;
+ }
+}
+
+class F64x2Pattern {
+ constructor(x, y) {
+ this.x = x;
+ this.y = y;
+ }
+}
+
+class RefWithType {
+ constructor(type) {
+ this.type = type;
+ }
+
+ formatExpected() {
+ return `RefWithType(${this.type})`;
+ }
+
+ test(refGlobal) {
+ try {
+ new WebAssembly.Global({value: this.type}, refGlobal.value);
+ return true;
+ } catch (err) {
+ assertEq(err instanceof TypeError, true, `wrong type of error when creating global: ${err}`);
+ assertEq(!!err.message.match(/can only pass/), true, `wrong type of error when creating global: ${err}`);
+ return false;
+ }
+ }
+}
+
+// ref.extern values created by spec tests will be JS objects of the form
+// { [externsym]: <number> }. Other externref values are possible to observe
+// if extern.convert_any is used.
+let externsym = Symbol("externref");
+function externref(s) {
+ return { [externsym]: s };
+}
+function is_externref(x) {
+ return (x !== null && externsym in x) ? 1 : 0;
+}
+function is_funcref(x) {
+ return typeof x === "function" ? 1 : 0;
+}
+function eq_externref(x, y) {
+ return x === y ? 1 : 0;
+}
+function eq_funcref(x, y) {
+ return x === y ? 1 : 0;
+}
+
+class ExternRefResult {
+ constructor(n) {
+ this.n = n;
+ }
+
+ formatExpected() {
+ return `ref.extern ${this.n}`;
+ }
+
+ test(global) {
+ // the global's value can either be an externref or just a plain old JS number
+ let result = global.value;
+ if (typeof global.value === "object" && externsym in global.value) {
+ result = global.value[externsym];
+ }
+ return result === this.n;
+ }
+}
+
+// ref.host values created by spectests will be whatever the JS API does to
+// convert the given value to anyref. It should implicitly be like any.convert_extern.
+function hostref(v) {
+ if (!wasmGcEnabled()) {
+ throw new Error("ref.host only works when wasm GC is enabled");
+ }
+
+ const { internalizeNum } = new WebAssembly.Instance(
+ new WebAssembly.Module(wasmTextToBinary(`(module
+ (func (import "test" "coerce") (param i32) (result anyref))
+ (func (export "internalizeNum") (param i32) (result anyref)
+ (call 0 (local.get 0))
+ )
+ )`)),
+ { "test": { "coerce": x => x } },
+ ).exports;
+ return internalizeNum(v);
+}
+
+class HostRefResult {
+ constructor(n) {
+ this.n = n;
+ }
+
+ formatExpected() {
+ return `ref.host ${this.n}`;
+ }
+
+ test(externrefGlobal) {
+ assertEq(externsym in externrefGlobal.value, true, `HostRefResult only works with externref inputs`);
+ return externrefGlobal.value[externsym] === this.n;
+ }
+}
+
+let spectest = {
+ externref: externref,
+ is_externref: is_externref,
+ is_funcref: is_funcref,
+ eq_externref: eq_externref,
+ eq_funcref: eq_funcref,
+ print: console.log.bind(console),
+ print_i32: console.log.bind(console),
+ print_i32_f32: console.log.bind(console),
+ print_f64_f64: console.log.bind(console),
+ print_f32: console.log.bind(console),
+ print_f64: console.log.bind(console),
+ global_i32: 666,
+ global_i64: 666n,
+ global_f32: 666,
+ global_f64: 666,
+ table: new WebAssembly.Table({
+ initial: 10,
+ maximum: 20,
+ element: "anyfunc",
+ }),
+ memory: new WebAssembly.Memory({ initial: 1, maximum: 2 }),
+};
+
+let linkage = {
+ spectest,
+};
+
+function getInstance(instanceish) {
+ if (typeof instanceish === "string") {
+ assertEq(
+ instanceish in linkage,
+ true,
+ `'${instanceish}'' must be registered`,
+ );
+ return linkage[instanceish];
+ }
+ return instanceish;
+}
+
+function instantiate(source) {
+ let bytecode = wasmTextToBinary(source);
+ let module = new WebAssembly.Module(bytecode);
+ let instance = new WebAssembly.Instance(module, linkage);
+ return instance.exports;
+}
+
+function register(instanceish, name) {
+ linkage[name] = getInstance(instanceish);
+}
+
+function invoke(instanceish, field, params) {
+ let func = getInstance(instanceish)[field];
+ assertEq(func instanceof Function, true, "expected a function");
+ return wasmLosslessInvoke(func, ...params);
+}
+
+function get(instanceish, field) {
+ let global = getInstance(instanceish)[field];
+ assertEq(
+ global instanceof WebAssembly.Global,
+ true,
+ "expected a WebAssembly.Global",
+ );
+ return global;
+}
+
+function assert_trap(thunk, message) {
+ try {
+ thunk();
+ throw new Error("expected trap");
+ } catch (err) {
+ if (err instanceof WebAssembly.RuntimeError) {
+ return;
+ }
+ throw err;
+ }
+}
+
+let StackOverflow;
+try {
+ (function f() {
+ 1 + f();
+ })();
+} catch (e) {
+ StackOverflow = e.constructor;
+}
+function assert_exhaustion(thunk, message) {
+ try {
+ thunk();
+ assertEq("normal return", "exhaustion");
+ } catch (err) {
+ assertEq(
+ err instanceof StackOverflow,
+ true,
+ "expected exhaustion",
+ );
+ }
+}
+
+function assert_invalid(thunk, message) {
+ try {
+ thunk();
+ assertEq("valid module", "invalid module");
+ } catch (err) {
+ assertEq(
+ err instanceof WebAssembly.LinkError ||
+ err instanceof WebAssembly.CompileError,
+ true,
+ "expected an invalid module",
+ );
+ }
+}
+
+function assert_unlinkable(thunk, message) {
+ try {
+ thunk();
+ assertEq(true, false, "expected an unlinkable module");
+ } catch (err) {
+ assertEq(
+ err instanceof WebAssembly.LinkError ||
+ err instanceof WebAssembly.CompileError,
+ true,
+ "expected an unlinkable module",
+ );
+ }
+}
+
+function assert_malformed(thunk, message) {
+ try {
+ thunk();
+ assertEq("valid module", "malformed module");
+ } catch (err) {
+ assertEq(
+ err instanceof TypeError ||
+ err instanceof SyntaxError ||
+ err instanceof WebAssembly.CompileError ||
+ err instanceof WebAssembly.LinkError,
+ true,
+ `expected a malformed module`,
+ );
+ }
+}
+
+function assert_exception(thunk) {
+ let thrown = false;
+ try {
+ thunk();
+ } catch (err) {
+ thrown = true;
+ }
+ assertEq(thrown, true, "expected an exception to be thrown");
+}
+
+function assert_return(thunk, expected) {
+ let results = thunk();
+
+ if (results === undefined) {
+ results = [];
+ } else if (!Array.isArray(results)) {
+ results = [results];
+ }
+ if (!Array.isArray(expected)) {
+ expected = [expected];
+ }
+
+ if (!compareResults(results, expected)) {
+ let got = results.map((x) => formatResult(x)).join(", ");
+ let wanted = expected.map((x) => formatExpected(x)).join(", ");
+ assertEq(
+ `[${got}]`,
+ `[${wanted}]`,
+ );
+ assertEq(true, false, `${got} !== ${wanted}`);
+ }
+}
+
+function formatResult(result) {
+ if (typeof (result) === "object") {
+ return wasmGlobalToString(result);
+ } else {
+ return `${result}`;
+ }
+}
+
+function formatExpected(expected) {
+ if (
+ expected === `f32_canonical_nan` ||
+ expected === `f32_arithmetic_nan` ||
+ expected === `f64_canonical_nan` ||
+ expected === `f64_arithmetic_nan`
+ ) {
+ return expected;
+ } else if (expected instanceof F32x4Pattern) {
+ return `f32x4(${formatExpected(expected.x)}, ${
+ formatExpected(expected.y)
+ }, ${formatExpected(expected.z)}, ${formatExpected(expected.w)})`;
+ } else if (expected instanceof F64x2Pattern) {
+ return `f64x2(${formatExpected(expected.x)}, ${
+ formatExpected(expected.y)
+ })`;
+ } else if (expected instanceof EitherVariants) {
+ return expected.formatExpected();
+ } else if (expected instanceof RefWithType) {
+ return expected.formatExpected();
+ } else if (expected instanceof ExternRefResult) {
+ return expected.formatExpected();
+ } else if (expected instanceof HostRefResult) {
+ return expected.formatExpected();
+ } else if (typeof (expected) === "object") {
+ return wasmGlobalToString(expected);
+ } else {
+ throw new Error("unknown expected result");
+ }
+}
+
+class EitherVariants {
+ constructor(arr) {
+ this.arr = arr;
+ }
+ matches(v) {
+ return this.arr.some((e) => compareResult(v, e));
+ }
+ formatExpected() {
+ return `either(${this.arr.map(formatExpected).join(", ")})`;
+ }
+}
+
+function compareResults(results, expected) {
+ if (results.length !== expected.length) {
+ return false;
+ }
+ for (let i in results) {
+ if (expected[i] instanceof EitherVariants) {
+ return expected[i].matches(results[i]);
+ }
+ if (!compareResult(results[i], expected[i])) {
+ return false;
+ }
+ }
+ return true;
+}
+
+function compareResult(result, expected) {
+ if (
+ expected === `canonical_nan` ||
+ expected === `arithmetic_nan`
+ ) {
+ return wasmGlobalIsNaN(result, expected);
+ } else if (expected === null) {
+ return result.value === null;
+ } else if (expected instanceof F32x4Pattern) {
+ return compareResult(
+ wasmGlobalExtractLane(result, "f32x4", 0),
+ expected.x,
+ ) &&
+ compareResult(wasmGlobalExtractLane(result, "f32x4", 1), expected.y) &&
+ compareResult(wasmGlobalExtractLane(result, "f32x4", 2), expected.z) &&
+ compareResult(wasmGlobalExtractLane(result, "f32x4", 3), expected.w);
+ } else if (expected instanceof F64x2Pattern) {
+ return compareResult(
+ wasmGlobalExtractLane(result, "f64x2", 0),
+ expected.x,
+ ) &&
+ compareResult(wasmGlobalExtractLane(result, "f64x2", 1), expected.y);
+ } else if (expected instanceof RefWithType) {
+ return expected.test(result);
+ } else if (expected instanceof ExternRefResult) {
+ return expected.test(result);
+ } else if (expected instanceof HostRefResult) {
+ return expected.test(result);
+ } else if (typeof (expected) === "object") {
+ return wasmGlobalsEqual(result, expected);
+ } else {
+ throw new Error("unknown expected result");
+ }
+}
diff --git a/js/src/jit-test/tests/wasm/spec/gc/i31.wast.js b/js/src/jit-test/tests/wasm/spec/gc/i31.wast.js
new file mode 100644
index 0000000000..5799deefbf
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/spec/gc/i31.wast.js
@@ -0,0 +1,104 @@
+/* Copyright 2021 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ./test/core/gc/i31.wast
+
+// ./test/core/gc/i31.wast:1
+let $0 = instantiate(`(module
+ (func (export "new") (param $$i i32) (result (ref i31))
+ (ref.i31 (local.get $$i))
+ )
+
+ (func (export "get_u") (param $$i i32) (result i32)
+ (i31.get_u (ref.i31 (local.get $$i)))
+ )
+ (func (export "get_s") (param $$i i32) (result i32)
+ (i31.get_s (ref.i31 (local.get $$i)))
+ )
+
+ (func (export "get_u-null") (result i32)
+ (i31.get_u (ref.null i31))
+ )
+ (func (export "get_s-null") (result i32)
+ (i31.get_u (ref.null i31))
+ )
+
+ (global $$i (ref i31) (ref.i31 (i32.const 2)))
+ (global $$m (mut (ref i31)) (ref.i31 (i32.const 3)))
+ (func (export "get_globals") (result i32 i32)
+ (i31.get_u (global.get $$i))
+ (i31.get_u (global.get $$m))
+ )
+)`);
+
+// ./test/core/gc/i31.wast:28
+assert_return(() => invoke($0, `new`, [1]), [new RefWithType('i31ref')]);
+
+// ./test/core/gc/i31.wast:30
+assert_return(() => invoke($0, `get_u`, [0]), [value("i32", 0)]);
+
+// ./test/core/gc/i31.wast:31
+assert_return(() => invoke($0, `get_u`, [100]), [value("i32", 100)]);
+
+// ./test/core/gc/i31.wast:32
+assert_return(() => invoke($0, `get_u`, [-1]), [value("i32", 2147483647)]);
+
+// ./test/core/gc/i31.wast:33
+assert_return(() => invoke($0, `get_u`, [1073741823]), [value("i32", 1073741823)]);
+
+// ./test/core/gc/i31.wast:34
+assert_return(() => invoke($0, `get_u`, [1073741824]), [value("i32", 1073741824)]);
+
+// ./test/core/gc/i31.wast:35
+assert_return(() => invoke($0, `get_u`, [2147483647]), [value("i32", 2147483647)]);
+
+// ./test/core/gc/i31.wast:36
+assert_return(() => invoke($0, `get_u`, [-1431655766]), [value("i32", 715827882)]);
+
+// ./test/core/gc/i31.wast:37
+assert_return(() => invoke($0, `get_u`, [-894784854]), [value("i32", 1252698794)]);
+
+// ./test/core/gc/i31.wast:39
+assert_return(() => invoke($0, `get_s`, [0]), [value("i32", 0)]);
+
+// ./test/core/gc/i31.wast:40
+assert_return(() => invoke($0, `get_s`, [100]), [value("i32", 100)]);
+
+// ./test/core/gc/i31.wast:41
+assert_return(() => invoke($0, `get_s`, [-1]), [value("i32", -1)]);
+
+// ./test/core/gc/i31.wast:42
+assert_return(() => invoke($0, `get_s`, [1073741823]), [value("i32", 1073741823)]);
+
+// ./test/core/gc/i31.wast:43
+assert_return(() => invoke($0, `get_s`, [1073741824]), [value("i32", -1073741824)]);
+
+// ./test/core/gc/i31.wast:44
+assert_return(() => invoke($0, `get_s`, [2147483647]), [value("i32", -1)]);
+
+// ./test/core/gc/i31.wast:45
+assert_return(() => invoke($0, `get_s`, [-1431655766]), [value("i32", 715827882)]);
+
+// ./test/core/gc/i31.wast:46
+assert_return(() => invoke($0, `get_s`, [-894784854]), [value("i32", -894784854)]);
+
+// ./test/core/gc/i31.wast:48
+assert_trap(() => invoke($0, `get_u-null`, []), `null i31 reference`);
+
+// ./test/core/gc/i31.wast:49
+assert_trap(() => invoke($0, `get_s-null`, []), `null i31 reference`);
+
+// ./test/core/gc/i31.wast:51
+assert_return(() => invoke($0, `get_globals`, []), [value("i32", 2), value("i32", 3)]);
diff --git a/js/src/jit-test/tests/wasm/spec/gc/if.wast.js b/js/src/jit-test/tests/wasm/spec/gc/if.wast.js
new file mode 100644
index 0000000000..cc79fbf00f
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/spec/gc/if.wast.js
@@ -0,0 +1,1928 @@
+/* Copyright 2021 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ./test/core/if.wast
+
+// ./test/core/if.wast:3
+let $0 = instantiate(`(module
+ ;; Auxiliary definition
+ (memory 1)
+
+ (func $$dummy)
+
+ (func (export "empty") (param i32)
+ (if (local.get 0) (then))
+ (if (local.get 0) (then) (else))
+ (if $$l (local.get 0) (then))
+ (if $$l (local.get 0) (then) (else))
+ )
+
+ (func (export "singular") (param i32) (result i32)
+ (if (local.get 0) (then (nop)))
+ (if (local.get 0) (then (nop)) (else (nop)))
+ (if (result i32) (local.get 0) (then (i32.const 7)) (else (i32.const 8)))
+ )
+
+ (func (export "multi") (param i32) (result i32 i32)
+ (if (local.get 0) (then (call $$dummy) (call $$dummy) (call $$dummy)))
+ (if (local.get 0) (then) (else (call $$dummy) (call $$dummy) (call $$dummy)))
+ (if (result i32) (local.get 0)
+ (then (call $$dummy) (call $$dummy) (i32.const 8) (call $$dummy))
+ (else (call $$dummy) (call $$dummy) (i32.const 9) (call $$dummy))
+ )
+ (if (result i32 i64 i32) (local.get 0)
+ (then
+ (call $$dummy) (call $$dummy) (i32.const 1) (call $$dummy)
+ (call $$dummy) (call $$dummy) (i64.const 2) (call $$dummy)
+ (call $$dummy) (call $$dummy) (i32.const 3) (call $$dummy)
+ )
+ (else
+ (call $$dummy) (call $$dummy) (i32.const -1) (call $$dummy)
+ (call $$dummy) (call $$dummy) (i64.const -2) (call $$dummy)
+ (call $$dummy) (call $$dummy) (i32.const -3) (call $$dummy)
+ )
+ )
+ (drop) (drop)
+ )
+
+ (func (export "nested") (param i32 i32) (result i32)
+ (if (result i32) (local.get 0)
+ (then
+ (if (local.get 1) (then (call $$dummy) (block) (nop)))
+ (if (local.get 1) (then) (else (call $$dummy) (block) (nop)))
+ (if (result i32) (local.get 1)
+ (then (call $$dummy) (i32.const 9))
+ (else (call $$dummy) (i32.const 10))
+ )
+ )
+ (else
+ (if (local.get 1) (then (call $$dummy) (block) (nop)))
+ (if (local.get 1) (then) (else (call $$dummy) (block) (nop)))
+ (if (result i32) (local.get 1)
+ (then (call $$dummy) (i32.const 10))
+ (else (call $$dummy) (i32.const 11))
+ )
+ )
+ )
+ )
+
+ (func (export "as-select-first") (param i32) (result i32)
+ (select
+ (if (result i32) (local.get 0)
+ (then (call $$dummy) (i32.const 1))
+ (else (call $$dummy) (i32.const 0))
+ )
+ (i32.const 2) (i32.const 3)
+ )
+ )
+ (func (export "as-select-mid") (param i32) (result i32)
+ (select
+ (i32.const 2)
+ (if (result i32) (local.get 0)
+ (then (call $$dummy) (i32.const 1))
+ (else (call $$dummy) (i32.const 0))
+ )
+ (i32.const 3)
+ )
+ )
+ (func (export "as-select-last") (param i32) (result i32)
+ (select
+ (i32.const 2) (i32.const 3)
+ (if (result i32) (local.get 0)
+ (then (call $$dummy) (i32.const 1))
+ (else (call $$dummy) (i32.const 0))
+ )
+ )
+ )
+
+ (func (export "as-loop-first") (param i32) (result i32)
+ (loop (result i32)
+ (if (result i32) (local.get 0)
+ (then (call $$dummy) (i32.const 1))
+ (else (call $$dummy) (i32.const 0))
+ )
+ (call $$dummy) (call $$dummy)
+ )
+ )
+ (func (export "as-loop-mid") (param i32) (result i32)
+ (loop (result i32)
+ (call $$dummy)
+ (if (result i32) (local.get 0)
+ (then (call $$dummy) (i32.const 1))
+ (else (call $$dummy) (i32.const 0))
+ )
+ (call $$dummy)
+ )
+ )
+ (func (export "as-loop-last") (param i32) (result i32)
+ (loop (result i32)
+ (call $$dummy) (call $$dummy)
+ (if (result i32) (local.get 0)
+ (then (call $$dummy) (i32.const 1))
+ (else (call $$dummy) (i32.const 0))
+ )
+ )
+ )
+
+ (func (export "as-if-condition") (param i32) (result i32)
+ (if (result i32)
+ (if (result i32) (local.get 0)
+ (then (i32.const 1)) (else (i32.const 0))
+ )
+ (then (call $$dummy) (i32.const 2))
+ (else (call $$dummy) (i32.const 3))
+ )
+ )
+
+ (func (export "as-br_if-first") (param i32) (result i32)
+ (block (result i32)
+ (br_if 0
+ (if (result i32) (local.get 0)
+ (then (call $$dummy) (i32.const 1))
+ (else (call $$dummy) (i32.const 0))
+ )
+ (i32.const 2)
+ )
+ (return (i32.const 3))
+ )
+ )
+ (func (export "as-br_if-last") (param i32) (result i32)
+ (block (result i32)
+ (br_if 0
+ (i32.const 2)
+ (if (result i32) (local.get 0)
+ (then (call $$dummy) (i32.const 1))
+ (else (call $$dummy) (i32.const 0))
+ )
+ )
+ (return (i32.const 3))
+ )
+ )
+
+ (func (export "as-br_table-first") (param i32) (result i32)
+ (block (result i32)
+ (if (result i32) (local.get 0)
+ (then (call $$dummy) (i32.const 1))
+ (else (call $$dummy) (i32.const 0))
+ )
+ (i32.const 2)
+ (br_table 0 0)
+ )
+ )
+ (func (export "as-br_table-last") (param i32) (result i32)
+ (block (result i32)
+ (i32.const 2)
+ (if (result i32) (local.get 0)
+ (then (call $$dummy) (i32.const 1))
+ (else (call $$dummy) (i32.const 0))
+ )
+ (br_table 0 0)
+ )
+ )
+
+ (func $$func (param i32 i32) (result i32) (local.get 0))
+ (type $$check (func (param i32 i32) (result i32)))
+ (table funcref (elem $$func))
+ (func (export "as-call_indirect-first") (param i32) (result i32)
+ (block (result i32)
+ (call_indirect (type $$check)
+ (if (result i32) (local.get 0)
+ (then (call $$dummy) (i32.const 1))
+ (else (call $$dummy) (i32.const 0))
+ )
+ (i32.const 2) (i32.const 0)
+ )
+ )
+ )
+ (func (export "as-call_indirect-mid") (param i32) (result i32)
+ (block (result i32)
+ (call_indirect (type $$check)
+ (i32.const 2)
+ (if (result i32) (local.get 0)
+ (then (call $$dummy) (i32.const 1))
+ (else (call $$dummy) (i32.const 0))
+ )
+ (i32.const 0)
+ )
+ )
+ )
+ (func (export "as-call_indirect-last") (param i32) (result i32)
+ (block (result i32)
+ (call_indirect (type $$check)
+ (i32.const 2) (i32.const 0)
+ (if (result i32) (local.get 0)
+ (then (call $$dummy) (i32.const 1))
+ (else (call $$dummy) (i32.const 0))
+ )
+ )
+ )
+ )
+
+ (func (export "as-store-first") (param i32)
+ (if (result i32) (local.get 0)
+ (then (call $$dummy) (i32.const 1))
+ (else (call $$dummy) (i32.const 0))
+ )
+ (i32.const 2)
+ (i32.store)
+ )
+ (func (export "as-store-last") (param i32)
+ (i32.const 2)
+ (if (result i32) (local.get 0)
+ (then (call $$dummy) (i32.const 1))
+ (else (call $$dummy) (i32.const 0))
+ )
+ (i32.store)
+ )
+
+ (func (export "as-memory.grow-value") (param i32) (result i32)
+ (memory.grow
+ (if (result i32) (local.get 0)
+ (then (i32.const 1))
+ (else (i32.const 0))
+ )
+ )
+ )
+
+ (func $$f (param i32) (result i32) (local.get 0))
+
+ (func (export "as-call-value") (param i32) (result i32)
+ (call $$f
+ (if (result i32) (local.get 0)
+ (then (i32.const 1))
+ (else (i32.const 0))
+ )
+ )
+ )
+ (func (export "as-return-value") (param i32) (result i32)
+ (if (result i32) (local.get 0)
+ (then (i32.const 1))
+ (else (i32.const 0)))
+ (return)
+ )
+ (func (export "as-drop-operand") (param i32)
+ (drop
+ (if (result i32) (local.get 0)
+ (then (i32.const 1))
+ (else (i32.const 0))
+ )
+ )
+ )
+ (func (export "as-br-value") (param i32) (result i32)
+ (block (result i32)
+ (br 0
+ (if (result i32) (local.get 0)
+ (then (i32.const 1))
+ (else (i32.const 0))
+ )
+ )
+ )
+ )
+ (func (export "as-local.set-value") (param i32) (result i32)
+ (local i32)
+ (local.set 0
+ (if (result i32) (local.get 0)
+ (then (i32.const 1))
+ (else (i32.const 0))
+ )
+ )
+ (local.get 0)
+ )
+ (func (export "as-local.tee-value") (param i32) (result i32)
+ (local.tee 0
+ (if (result i32) (local.get 0)
+ (then (i32.const 1))
+ (else (i32.const 0))
+ )
+ )
+ )
+ (global $$a (mut i32) (i32.const 10))
+ (func (export "as-global.set-value") (param i32) (result i32)
+ (global.set $$a
+ (if (result i32) (local.get 0)
+ (then (i32.const 1))
+ (else (i32.const 0))
+ )
+ ) (global.get $$a)
+ )
+ (func (export "as-load-operand") (param i32) (result i32)
+ (i32.load
+ (if (result i32) (local.get 0)
+ (then (i32.const 11))
+ (else (i32.const 10))
+ )
+ )
+ )
+
+ (func (export "as-unary-operand") (param i32) (result i32)
+ (i32.ctz
+ (if (result i32) (local.get 0)
+ (then (call $$dummy) (i32.const 13))
+ (else (call $$dummy) (i32.const -13))
+ )
+ )
+ )
+ (func (export "as-binary-operand") (param i32 i32) (result i32)
+ (i32.mul
+ (if (result i32) (local.get 0)
+ (then (call $$dummy) (i32.const 3))
+ (else (call $$dummy) (i32.const -3))
+ )
+ (if (result i32) (local.get 1)
+ (then (call $$dummy) (i32.const 4))
+ (else (call $$dummy) (i32.const -5))
+ )
+ )
+ )
+ (func (export "as-test-operand") (param i32) (result i32)
+ (i32.eqz
+ (if (result i32) (local.get 0)
+ (then (call $$dummy) (i32.const 13))
+ (else (call $$dummy) (i32.const 0))
+ )
+ )
+ )
+ (func (export "as-compare-operand") (param i32 i32) (result i32)
+ (f32.gt
+ (if (result f32) (local.get 0)
+ (then (call $$dummy) (f32.const 3))
+ (else (call $$dummy) (f32.const -3))
+ )
+ (if (result f32) (local.get 1)
+ (then (call $$dummy) (f32.const 4))
+ (else (call $$dummy) (f32.const -4))
+ )
+ )
+ )
+ (func (export "as-binary-operands") (param i32) (result i32)
+ (i32.mul
+ (if (result i32 i32) (local.get 0)
+ (then (call $$dummy) (i32.const 3) (call $$dummy) (i32.const 4))
+ (else (call $$dummy) (i32.const 3) (call $$dummy) (i32.const -4))
+ )
+ )
+ )
+ (func (export "as-compare-operands") (param i32) (result i32)
+ (f32.gt
+ (if (result f32 f32) (local.get 0)
+ (then (call $$dummy) (f32.const 3) (call $$dummy) (f32.const 3))
+ (else (call $$dummy) (f32.const -2) (call $$dummy) (f32.const -3))
+ )
+ )
+ )
+ (func (export "as-mixed-operands") (param i32) (result i32)
+ (if (result i32 i32) (local.get 0)
+ (then (call $$dummy) (i32.const 3) (call $$dummy) (i32.const 4))
+ (else (call $$dummy) (i32.const -3) (call $$dummy) (i32.const -4))
+ )
+ (i32.const 5)
+ (i32.add)
+ (i32.mul)
+ )
+
+ (func (export "break-bare") (result i32)
+ (if (i32.const 1) (then (br 0) (unreachable)))
+ (if (i32.const 1) (then (br 0) (unreachable)) (else (unreachable)))
+ (if (i32.const 0) (then (unreachable)) (else (br 0) (unreachable)))
+ (if (i32.const 1) (then (br_if 0 (i32.const 1)) (unreachable)))
+ (if (i32.const 1) (then (br_if 0 (i32.const 1)) (unreachable)) (else (unreachable)))
+ (if (i32.const 0) (then (unreachable)) (else (br_if 0 (i32.const 1)) (unreachable)))
+ (if (i32.const 1) (then (br_table 0 (i32.const 0)) (unreachable)))
+ (if (i32.const 1) (then (br_table 0 (i32.const 0)) (unreachable)) (else (unreachable)))
+ (if (i32.const 0) (then (unreachable)) (else (br_table 0 (i32.const 0)) (unreachable)))
+ (i32.const 19)
+ )
+
+ (func (export "break-value") (param i32) (result i32)
+ (if (result i32) (local.get 0)
+ (then (br 0 (i32.const 18)) (i32.const 19))
+ (else (br 0 (i32.const 21)) (i32.const 20))
+ )
+ )
+ (func (export "break-multi-value") (param i32) (result i32 i32 i64)
+ (if (result i32 i32 i64) (local.get 0)
+ (then
+ (br 0 (i32.const 18) (i32.const -18) (i64.const 18))
+ (i32.const 19) (i32.const -19) (i64.const 19)
+ )
+ (else
+ (br 0 (i32.const -18) (i32.const 18) (i64.const -18))
+ (i32.const -19) (i32.const 19) (i64.const -19)
+ )
+ )
+ )
+
+ (func (export "param") (param i32) (result i32)
+ (i32.const 1)
+ (if (param i32) (result i32) (local.get 0)
+ (then (i32.const 2) (i32.add))
+ (else (i32.const -2) (i32.add))
+ )
+ )
+ (func (export "params") (param i32) (result i32)
+ (i32.const 1)
+ (i32.const 2)
+ (if (param i32 i32) (result i32) (local.get 0)
+ (then (i32.add))
+ (else (i32.sub))
+ )
+ )
+ (func (export "params-id") (param i32) (result i32)
+ (i32.const 1)
+ (i32.const 2)
+ (if (param i32 i32) (result i32 i32) (local.get 0) (then))
+ (i32.add)
+ )
+ (func (export "param-break") (param i32) (result i32)
+ (i32.const 1)
+ (if (param i32) (result i32) (local.get 0)
+ (then (i32.const 2) (i32.add) (br 0))
+ (else (i32.const -2) (i32.add) (br 0))
+ )
+ )
+ (func (export "params-break") (param i32) (result i32)
+ (i32.const 1)
+ (i32.const 2)
+ (if (param i32 i32) (result i32) (local.get 0)
+ (then (i32.add) (br 0))
+ (else (i32.sub) (br 0))
+ )
+ )
+ (func (export "params-id-break") (param i32) (result i32)
+ (i32.const 1)
+ (i32.const 2)
+ (if (param i32 i32) (result i32 i32) (local.get 0) (then (br 0)))
+ (i32.add)
+ )
+
+ (func (export "effects") (param i32) (result i32)
+ (local i32)
+ (if
+ (block (result i32) (local.set 1 (i32.const 1)) (local.get 0))
+ (then
+ (local.set 1 (i32.mul (local.get 1) (i32.const 3)))
+ (local.set 1 (i32.sub (local.get 1) (i32.const 5)))
+ (local.set 1 (i32.mul (local.get 1) (i32.const 7)))
+ (br 0)
+ (local.set 1 (i32.mul (local.get 1) (i32.const 100)))
+ )
+ (else
+ (local.set 1 (i32.mul (local.get 1) (i32.const 5)))
+ (local.set 1 (i32.sub (local.get 1) (i32.const 7)))
+ (local.set 1 (i32.mul (local.get 1) (i32.const 3)))
+ (br 0)
+ (local.set 1 (i32.mul (local.get 1) (i32.const 1000)))
+ )
+ )
+ (local.get 1)
+ )
+
+ ;; Examples
+
+ (func $$add64_u_with_carry (export "add64_u_with_carry")
+ (param $$i i64) (param $$j i64) (param $$c i32) (result i64 i32)
+ (local $$k i64)
+ (local.set $$k
+ (i64.add
+ (i64.add (local.get $$i) (local.get $$j))
+ (i64.extend_i32_u (local.get $$c))
+ )
+ )
+ (return (local.get $$k) (i64.lt_u (local.get $$k) (local.get $$i)))
+ )
+
+ (func $$add64_u_saturated (export "add64_u_saturated")
+ (param i64 i64) (result i64)
+ (call $$add64_u_with_carry (local.get 0) (local.get 1) (i32.const 0))
+ (if (param i64) (result i64)
+ (then (drop) (i64.const -1))
+ )
+ )
+
+ ;; Block signature syntax
+
+ (type $$block-sig-1 (func))
+ (type $$block-sig-2 (func (result i32)))
+ (type $$block-sig-3 (func (param $$x i32)))
+ (type $$block-sig-4 (func (param i32 f64 i32) (result i32 f64 i32)))
+
+ (func (export "type-use")
+ (if (type $$block-sig-1) (i32.const 1) (then))
+ (if (type $$block-sig-2) (i32.const 1)
+ (then (i32.const 0)) (else (i32.const 2))
+ )
+ (if (type $$block-sig-3) (i32.const 1) (then (drop)) (else (drop)))
+ (i32.const 0) (f64.const 0) (i32.const 0)
+ (if (type $$block-sig-4) (i32.const 1) (then))
+ (drop) (drop) (drop)
+ (if (type $$block-sig-2) (result i32) (i32.const 1)
+ (then (i32.const 0)) (else (i32.const 2))
+ )
+ (if (type $$block-sig-3) (param i32) (i32.const 1)
+ (then (drop)) (else (drop))
+ )
+ (i32.const 0) (f64.const 0) (i32.const 0)
+ (if (type $$block-sig-4)
+ (param i32) (param f64 i32) (result i32 f64) (result i32)
+ (i32.const 1) (then)
+ )
+ (drop) (drop) (drop)
+ )
+
+ ;; Atypical folded condition syntax
+
+ (func (export "atypical-condition")
+ i32.const 0
+ (if (then) (else))
+ (if (i32.const 1) (i32.eqz) (then) (else))
+ )
+)`);
+
+// ./test/core/if.wast:537
+assert_return(() => invoke($0, `empty`, [0]), []);
+
+// ./test/core/if.wast:538
+assert_return(() => invoke($0, `empty`, [1]), []);
+
+// ./test/core/if.wast:539
+assert_return(() => invoke($0, `empty`, [100]), []);
+
+// ./test/core/if.wast:540
+assert_return(() => invoke($0, `empty`, [-2]), []);
+
+// ./test/core/if.wast:542
+assert_return(() => invoke($0, `singular`, [0]), [value("i32", 8)]);
+
+// ./test/core/if.wast:543
+assert_return(() => invoke($0, `singular`, [1]), [value("i32", 7)]);
+
+// ./test/core/if.wast:544
+assert_return(() => invoke($0, `singular`, [10]), [value("i32", 7)]);
+
+// ./test/core/if.wast:545
+assert_return(() => invoke($0, `singular`, [-10]), [value("i32", 7)]);
+
+// ./test/core/if.wast:547
+assert_return(() => invoke($0, `multi`, [0]), [value("i32", 9), value("i32", -1)]);
+
+// ./test/core/if.wast:548
+assert_return(() => invoke($0, `multi`, [1]), [value("i32", 8), value("i32", 1)]);
+
+// ./test/core/if.wast:549
+assert_return(() => invoke($0, `multi`, [13]), [value("i32", 8), value("i32", 1)]);
+
+// ./test/core/if.wast:550
+assert_return(() => invoke($0, `multi`, [-5]), [value("i32", 8), value("i32", 1)]);
+
+// ./test/core/if.wast:552
+assert_return(() => invoke($0, `nested`, [0, 0]), [value("i32", 11)]);
+
+// ./test/core/if.wast:553
+assert_return(() => invoke($0, `nested`, [1, 0]), [value("i32", 10)]);
+
+// ./test/core/if.wast:554
+assert_return(() => invoke($0, `nested`, [0, 1]), [value("i32", 10)]);
+
+// ./test/core/if.wast:555
+assert_return(() => invoke($0, `nested`, [3, 2]), [value("i32", 9)]);
+
+// ./test/core/if.wast:556
+assert_return(() => invoke($0, `nested`, [0, -100]), [value("i32", 10)]);
+
+// ./test/core/if.wast:557
+assert_return(() => invoke($0, `nested`, [10, 10]), [value("i32", 9)]);
+
+// ./test/core/if.wast:558
+assert_return(() => invoke($0, `nested`, [0, -1]), [value("i32", 10)]);
+
+// ./test/core/if.wast:559
+assert_return(() => invoke($0, `nested`, [-111, -2]), [value("i32", 9)]);
+
+// ./test/core/if.wast:561
+assert_return(() => invoke($0, `as-select-first`, [0]), [value("i32", 0)]);
+
+// ./test/core/if.wast:562
+assert_return(() => invoke($0, `as-select-first`, [1]), [value("i32", 1)]);
+
+// ./test/core/if.wast:563
+assert_return(() => invoke($0, `as-select-mid`, [0]), [value("i32", 2)]);
+
+// ./test/core/if.wast:564
+assert_return(() => invoke($0, `as-select-mid`, [1]), [value("i32", 2)]);
+
+// ./test/core/if.wast:565
+assert_return(() => invoke($0, `as-select-last`, [0]), [value("i32", 3)]);
+
+// ./test/core/if.wast:566
+assert_return(() => invoke($0, `as-select-last`, [1]), [value("i32", 2)]);
+
+// ./test/core/if.wast:568
+assert_return(() => invoke($0, `as-loop-first`, [0]), [value("i32", 0)]);
+
+// ./test/core/if.wast:569
+assert_return(() => invoke($0, `as-loop-first`, [1]), [value("i32", 1)]);
+
+// ./test/core/if.wast:570
+assert_return(() => invoke($0, `as-loop-mid`, [0]), [value("i32", 0)]);
+
+// ./test/core/if.wast:571
+assert_return(() => invoke($0, `as-loop-mid`, [1]), [value("i32", 1)]);
+
+// ./test/core/if.wast:572
+assert_return(() => invoke($0, `as-loop-last`, [0]), [value("i32", 0)]);
+
+// ./test/core/if.wast:573
+assert_return(() => invoke($0, `as-loop-last`, [1]), [value("i32", 1)]);
+
+// ./test/core/if.wast:575
+assert_return(() => invoke($0, `as-if-condition`, [0]), [value("i32", 3)]);
+
+// ./test/core/if.wast:576
+assert_return(() => invoke($0, `as-if-condition`, [1]), [value("i32", 2)]);
+
+// ./test/core/if.wast:578
+assert_return(() => invoke($0, `as-br_if-first`, [0]), [value("i32", 0)]);
+
+// ./test/core/if.wast:579
+assert_return(() => invoke($0, `as-br_if-first`, [1]), [value("i32", 1)]);
+
+// ./test/core/if.wast:580
+assert_return(() => invoke($0, `as-br_if-last`, [0]), [value("i32", 3)]);
+
+// ./test/core/if.wast:581
+assert_return(() => invoke($0, `as-br_if-last`, [1]), [value("i32", 2)]);
+
+// ./test/core/if.wast:583
+assert_return(() => invoke($0, `as-br_table-first`, [0]), [value("i32", 0)]);
+
+// ./test/core/if.wast:584
+assert_return(() => invoke($0, `as-br_table-first`, [1]), [value("i32", 1)]);
+
+// ./test/core/if.wast:585
+assert_return(() => invoke($0, `as-br_table-last`, [0]), [value("i32", 2)]);
+
+// ./test/core/if.wast:586
+assert_return(() => invoke($0, `as-br_table-last`, [1]), [value("i32", 2)]);
+
+// ./test/core/if.wast:588
+assert_return(() => invoke($0, `as-call_indirect-first`, [0]), [value("i32", 0)]);
+
+// ./test/core/if.wast:589
+assert_return(() => invoke($0, `as-call_indirect-first`, [1]), [value("i32", 1)]);
+
+// ./test/core/if.wast:590
+assert_return(() => invoke($0, `as-call_indirect-mid`, [0]), [value("i32", 2)]);
+
+// ./test/core/if.wast:591
+assert_return(() => invoke($0, `as-call_indirect-mid`, [1]), [value("i32", 2)]);
+
+// ./test/core/if.wast:592
+assert_return(() => invoke($0, `as-call_indirect-last`, [0]), [value("i32", 2)]);
+
+// ./test/core/if.wast:593
+assert_trap(() => invoke($0, `as-call_indirect-last`, [1]), `undefined element`);
+
+// ./test/core/if.wast:595
+assert_return(() => invoke($0, `as-store-first`, [0]), []);
+
+// ./test/core/if.wast:596
+assert_return(() => invoke($0, `as-store-first`, [1]), []);
+
+// ./test/core/if.wast:597
+assert_return(() => invoke($0, `as-store-last`, [0]), []);
+
+// ./test/core/if.wast:598
+assert_return(() => invoke($0, `as-store-last`, [1]), []);
+
+// ./test/core/if.wast:600
+assert_return(() => invoke($0, `as-memory.grow-value`, [0]), [value("i32", 1)]);
+
+// ./test/core/if.wast:601
+assert_return(() => invoke($0, `as-memory.grow-value`, [1]), [value("i32", 1)]);
+
+// ./test/core/if.wast:603
+assert_return(() => invoke($0, `as-call-value`, [0]), [value("i32", 0)]);
+
+// ./test/core/if.wast:604
+assert_return(() => invoke($0, `as-call-value`, [1]), [value("i32", 1)]);
+
+// ./test/core/if.wast:606
+assert_return(() => invoke($0, `as-return-value`, [0]), [value("i32", 0)]);
+
+// ./test/core/if.wast:607
+assert_return(() => invoke($0, `as-return-value`, [1]), [value("i32", 1)]);
+
+// ./test/core/if.wast:609
+assert_return(() => invoke($0, `as-drop-operand`, [0]), []);
+
+// ./test/core/if.wast:610
+assert_return(() => invoke($0, `as-drop-operand`, [1]), []);
+
+// ./test/core/if.wast:612
+assert_return(() => invoke($0, `as-br-value`, [0]), [value("i32", 0)]);
+
+// ./test/core/if.wast:613
+assert_return(() => invoke($0, `as-br-value`, [1]), [value("i32", 1)]);
+
+// ./test/core/if.wast:615
+assert_return(() => invoke($0, `as-local.set-value`, [0]), [value("i32", 0)]);
+
+// ./test/core/if.wast:616
+assert_return(() => invoke($0, `as-local.set-value`, [1]), [value("i32", 1)]);
+
+// ./test/core/if.wast:618
+assert_return(() => invoke($0, `as-local.tee-value`, [0]), [value("i32", 0)]);
+
+// ./test/core/if.wast:619
+assert_return(() => invoke($0, `as-local.tee-value`, [1]), [value("i32", 1)]);
+
+// ./test/core/if.wast:621
+assert_return(() => invoke($0, `as-global.set-value`, [0]), [value("i32", 0)]);
+
+// ./test/core/if.wast:622
+assert_return(() => invoke($0, `as-global.set-value`, [1]), [value("i32", 1)]);
+
+// ./test/core/if.wast:624
+assert_return(() => invoke($0, `as-load-operand`, [0]), [value("i32", 0)]);
+
+// ./test/core/if.wast:625
+assert_return(() => invoke($0, `as-load-operand`, [1]), [value("i32", 0)]);
+
+// ./test/core/if.wast:627
+assert_return(() => invoke($0, `as-unary-operand`, [0]), [value("i32", 0)]);
+
+// ./test/core/if.wast:628
+assert_return(() => invoke($0, `as-unary-operand`, [1]), [value("i32", 0)]);
+
+// ./test/core/if.wast:629
+assert_return(() => invoke($0, `as-unary-operand`, [-1]), [value("i32", 0)]);
+
+// ./test/core/if.wast:631
+assert_return(() => invoke($0, `as-binary-operand`, [0, 0]), [value("i32", 15)]);
+
+// ./test/core/if.wast:632
+assert_return(() => invoke($0, `as-binary-operand`, [0, 1]), [value("i32", -12)]);
+
+// ./test/core/if.wast:633
+assert_return(() => invoke($0, `as-binary-operand`, [1, 0]), [value("i32", -15)]);
+
+// ./test/core/if.wast:634
+assert_return(() => invoke($0, `as-binary-operand`, [1, 1]), [value("i32", 12)]);
+
+// ./test/core/if.wast:636
+assert_return(() => invoke($0, `as-test-operand`, [0]), [value("i32", 1)]);
+
+// ./test/core/if.wast:637
+assert_return(() => invoke($0, `as-test-operand`, [1]), [value("i32", 0)]);
+
+// ./test/core/if.wast:639
+assert_return(() => invoke($0, `as-compare-operand`, [0, 0]), [value("i32", 1)]);
+
+// ./test/core/if.wast:640
+assert_return(() => invoke($0, `as-compare-operand`, [0, 1]), [value("i32", 0)]);
+
+// ./test/core/if.wast:641
+assert_return(() => invoke($0, `as-compare-operand`, [1, 0]), [value("i32", 1)]);
+
+// ./test/core/if.wast:642
+assert_return(() => invoke($0, `as-compare-operand`, [1, 1]), [value("i32", 0)]);
+
+// ./test/core/if.wast:644
+assert_return(() => invoke($0, `as-binary-operands`, [0]), [value("i32", -12)]);
+
+// ./test/core/if.wast:645
+assert_return(() => invoke($0, `as-binary-operands`, [1]), [value("i32", 12)]);
+
+// ./test/core/if.wast:647
+assert_return(() => invoke($0, `as-compare-operands`, [0]), [value("i32", 1)]);
+
+// ./test/core/if.wast:648
+assert_return(() => invoke($0, `as-compare-operands`, [1]), [value("i32", 0)]);
+
+// ./test/core/if.wast:650
+assert_return(() => invoke($0, `as-mixed-operands`, [0]), [value("i32", -3)]);
+
+// ./test/core/if.wast:651
+assert_return(() => invoke($0, `as-mixed-operands`, [1]), [value("i32", 27)]);
+
+// ./test/core/if.wast:653
+assert_return(() => invoke($0, `break-bare`, []), [value("i32", 19)]);
+
+// ./test/core/if.wast:654
+assert_return(() => invoke($0, `break-value`, [1]), [value("i32", 18)]);
+
+// ./test/core/if.wast:655
+assert_return(() => invoke($0, `break-value`, [0]), [value("i32", 21)]);
+
+// ./test/core/if.wast:656
+assert_return(
+ () => invoke($0, `break-multi-value`, [0]),
+ [value("i32", -18), value("i32", 18), value("i64", -18n)],
+);
+
+// ./test/core/if.wast:659
+assert_return(
+ () => invoke($0, `break-multi-value`, [1]),
+ [value("i32", 18), value("i32", -18), value("i64", 18n)],
+);
+
+// ./test/core/if.wast:663
+assert_return(() => invoke($0, `param`, [0]), [value("i32", -1)]);
+
+// ./test/core/if.wast:664
+assert_return(() => invoke($0, `param`, [1]), [value("i32", 3)]);
+
+// ./test/core/if.wast:665
+assert_return(() => invoke($0, `params`, [0]), [value("i32", -1)]);
+
+// ./test/core/if.wast:666
+assert_return(() => invoke($0, `params`, [1]), [value("i32", 3)]);
+
+// ./test/core/if.wast:667
+assert_return(() => invoke($0, `params-id`, [0]), [value("i32", 3)]);
+
+// ./test/core/if.wast:668
+assert_return(() => invoke($0, `params-id`, [1]), [value("i32", 3)]);
+
+// ./test/core/if.wast:669
+assert_return(() => invoke($0, `param-break`, [0]), [value("i32", -1)]);
+
+// ./test/core/if.wast:670
+assert_return(() => invoke($0, `param-break`, [1]), [value("i32", 3)]);
+
+// ./test/core/if.wast:671
+assert_return(() => invoke($0, `params-break`, [0]), [value("i32", -1)]);
+
+// ./test/core/if.wast:672
+assert_return(() => invoke($0, `params-break`, [1]), [value("i32", 3)]);
+
+// ./test/core/if.wast:673
+assert_return(() => invoke($0, `params-id-break`, [0]), [value("i32", 3)]);
+
+// ./test/core/if.wast:674
+assert_return(() => invoke($0, `params-id-break`, [1]), [value("i32", 3)]);
+
+// ./test/core/if.wast:676
+assert_return(() => invoke($0, `effects`, [1]), [value("i32", -14)]);
+
+// ./test/core/if.wast:677
+assert_return(() => invoke($0, `effects`, [0]), [value("i32", -6)]);
+
+// ./test/core/if.wast:679
+assert_return(() => invoke($0, `add64_u_with_carry`, [0n, 0n, 0]), [value("i64", 0n), value("i32", 0)]);
+
+// ./test/core/if.wast:683
+assert_return(
+ () => invoke($0, `add64_u_with_carry`, [100n, 124n, 0]),
+ [value("i64", 224n), value("i32", 0)],
+);
+
+// ./test/core/if.wast:687
+assert_return(
+ () => invoke($0, `add64_u_with_carry`, [-1n, 0n, 0]),
+ [value("i64", -1n), value("i32", 0)],
+);
+
+// ./test/core/if.wast:691
+assert_return(() => invoke($0, `add64_u_with_carry`, [-1n, 1n, 0]), [value("i64", 0n), value("i32", 1)]);
+
+// ./test/core/if.wast:695
+assert_return(
+ () => invoke($0, `add64_u_with_carry`, [-1n, -1n, 0]),
+ [value("i64", -2n), value("i32", 1)],
+);
+
+// ./test/core/if.wast:699
+assert_return(() => invoke($0, `add64_u_with_carry`, [-1n, 0n, 1]), [value("i64", 0n), value("i32", 1)]);
+
+// ./test/core/if.wast:703
+assert_return(() => invoke($0, `add64_u_with_carry`, [-1n, 1n, 1]), [value("i64", 1n), value("i32", 1)]);
+
+// ./test/core/if.wast:707
+assert_return(
+ () => invoke($0, `add64_u_with_carry`, [
+ -9223372036854775808n,
+ -9223372036854775808n,
+ 0,
+ ]),
+ [value("i64", 0n), value("i32", 1)],
+);
+
+// ./test/core/if.wast:712
+assert_return(() => invoke($0, `add64_u_saturated`, [0n, 0n]), [value("i64", 0n)]);
+
+// ./test/core/if.wast:715
+assert_return(() => invoke($0, `add64_u_saturated`, [1230n, 23n]), [value("i64", 1253n)]);
+
+// ./test/core/if.wast:718
+assert_return(() => invoke($0, `add64_u_saturated`, [-1n, 0n]), [value("i64", -1n)]);
+
+// ./test/core/if.wast:721
+assert_return(() => invoke($0, `add64_u_saturated`, [-1n, 1n]), [value("i64", -1n)]);
+
+// ./test/core/if.wast:724
+assert_return(() => invoke($0, `add64_u_saturated`, [-1n, -1n]), [value("i64", -1n)]);
+
+// ./test/core/if.wast:727
+assert_return(
+ () => invoke($0, `add64_u_saturated`, [-9223372036854775808n, -9223372036854775808n]),
+ [value("i64", -1n)],
+);
+
+// ./test/core/if.wast:731
+assert_return(() => invoke($0, `type-use`, []), []);
+
+// ./test/core/if.wast:733
+assert_return(() => invoke($0, `atypical-condition`, []), []);
+
+// ./test/core/if.wast:735
+assert_malformed(
+ () => instantiate(`(type $$sig (func (param i32) (result i32))) (func (i32.const 0) (if (type $$sig) (result i32) (param i32) (i32.const 1) (then)) ) `),
+ `unexpected token`,
+);
+
+// ./test/core/if.wast:744
+assert_malformed(
+ () => instantiate(`(type $$sig (func (param i32) (result i32))) (func (i32.const 0) (if (param i32) (type $$sig) (result i32) (i32.const 1) (then)) ) `),
+ `unexpected token`,
+);
+
+// ./test/core/if.wast:753
+assert_malformed(
+ () => instantiate(`(type $$sig (func (param i32) (result i32))) (func (i32.const 0) (if (param i32) (result i32) (type $$sig) (i32.const 1) (then)) ) `),
+ `unexpected token`,
+);
+
+// ./test/core/if.wast:762
+assert_malformed(
+ () => instantiate(`(type $$sig (func (param i32) (result i32))) (func (i32.const 0) (if (result i32) (type $$sig) (param i32) (i32.const 1) (then)) ) `),
+ `unexpected token`,
+);
+
+// ./test/core/if.wast:771
+assert_malformed(
+ () => instantiate(`(type $$sig (func (param i32) (result i32))) (func (i32.const 0) (if (result i32) (param i32) (type $$sig) (i32.const 1) (then)) ) `),
+ `unexpected token`,
+);
+
+// ./test/core/if.wast:780
+assert_malformed(
+ () => instantiate(`(func (i32.const 0) (if (result i32) (param i32) (i32.const 1) (then))) `),
+ `unexpected token`,
+);
+
+// ./test/core/if.wast:787
+assert_malformed(
+ () => instantiate(`(func (i32.const 0) (i32.const 1) (if (param $$x i32) (then (drop)) (else (drop))) ) `),
+ `unexpected token`,
+);
+
+// ./test/core/if.wast:795
+assert_malformed(
+ () => instantiate(`(type $$sig (func)) (func (i32.const 1) (if (type $$sig) (result i32) (then (i32.const 0)) (else (i32.const 2))) (unreachable) ) `),
+ `inline function type`,
+);
+
+// ./test/core/if.wast:805
+assert_malformed(
+ () => instantiate(`(type $$sig (func (param i32) (result i32))) (func (i32.const 1) (if (type $$sig) (result i32) (then (i32.const 0)) (else (i32.const 2))) (unreachable) ) `),
+ `inline function type`,
+);
+
+// ./test/core/if.wast:815
+assert_malformed(
+ () => instantiate(`(type $$sig (func (param i32) (result i32))) (func (i32.const 0) (i32.const 1) (if (type $$sig) (param i32) (then (drop)) (else (drop))) (unreachable) ) `),
+ `inline function type`,
+);
+
+// ./test/core/if.wast:825
+assert_malformed(
+ () => instantiate(`(type $$sig (func (param i32 i32) (result i32))) (func (i32.const 0) (i32.const 1) (if (type $$sig) (param i32) (result i32) (then)) (unreachable) ) `),
+ `inline function type`,
+);
+
+// ./test/core/if.wast:835
+assert_invalid(
+ () => instantiate(`(module
+ (type $$sig (func))
+ (func (i32.const 1) (if (type $$sig) (i32.const 0) (then)))
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:843
+assert_invalid(
+ () => instantiate(`(module (func $$type-empty-i32 (result i32) (if (i32.const 0) (then))))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:847
+assert_invalid(
+ () => instantiate(`(module (func $$type-empty-i64 (result i64) (if (i32.const 0) (then))))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:851
+assert_invalid(
+ () => instantiate(`(module (func $$type-empty-f32 (result f32) (if (i32.const 0) (then))))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:855
+assert_invalid(
+ () => instantiate(`(module (func $$type-empty-f64 (result f64) (if (i32.const 0) (then))))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:860
+assert_invalid(
+ () => instantiate(`(module (func $$type-empty-i32 (result i32) (if (i32.const 0) (then) (else))))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:864
+assert_invalid(
+ () => instantiate(`(module (func $$type-empty-i64 (result i64) (if (i32.const 0) (then) (else))))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:868
+assert_invalid(
+ () => instantiate(`(module (func $$type-empty-f32 (result f32) (if (i32.const 0) (then) (else))))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:872
+assert_invalid(
+ () => instantiate(`(module (func $$type-empty-f64 (result f64) (if (i32.const 0) (then) (else))))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:877
+assert_invalid(
+ () => instantiate(`(module (func $$type-then-value-num-vs-void
+ (if (i32.const 1) (then (i32.const 1)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:883
+assert_invalid(
+ () => instantiate(`(module (func $$type-then-value-num-vs-void-else
+ (if (i32.const 1) (then (i32.const 1)) (else))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:889
+assert_invalid(
+ () => instantiate(`(module (func $$type-else-value-num-vs-void
+ (if (i32.const 1) (then) (else (i32.const 1)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:895
+assert_invalid(
+ () => instantiate(`(module (func $$type-both-value-num-vs-void
+ (if (i32.const 1) (then (i32.const 1)) (else (i32.const 1)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:902
+assert_invalid(
+ () => instantiate(`(module (func $$type-then-value-nums-vs-void
+ (if (i32.const 1) (then (i32.const 1) (i32.const 2)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:908
+assert_invalid(
+ () => instantiate(`(module (func $$type-then-value-nums-vs-void-else
+ (if (i32.const 1) (then (i32.const 1) (i32.const 2)) (else))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:914
+assert_invalid(
+ () => instantiate(`(module (func $$type-else-value-nums-vs-void
+ (if (i32.const 1) (then) (else (i32.const 1) (i32.const 2)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:920
+assert_invalid(
+ () => instantiate(`(module (func $$type-both-value-nums-vs-void
+ (if (i32.const 1) (then (i32.const 1) (i32.const 2)) (else (i32.const 2) (i32.const 1)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:927
+assert_invalid(
+ () => instantiate(`(module (func $$type-then-value-empty-vs-num (result i32)
+ (if (result i32) (i32.const 1) (then) (else (i32.const 0)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:933
+assert_invalid(
+ () => instantiate(`(module (func $$type-else-value-empty-vs-num (result i32)
+ (if (result i32) (i32.const 1) (then (i32.const 0)) (else))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:939
+assert_invalid(
+ () => instantiate(`(module (func $$type-both-value-empty-vs-num (result i32)
+ (if (result i32) (i32.const 1) (then) (else))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:946
+assert_invalid(
+ () => instantiate(`(module (func $$type-then-value-empty-vs-nums (result i32 i32)
+ (if (result i32 i32) (i32.const 1) (then) (else (i32.const 0) (i32.const 2)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:952
+assert_invalid(
+ () => instantiate(`(module (func $$type-else-value-empty-vs-nums (result i32 i32)
+ (if (result i32 i32) (i32.const 1) (then (i32.const 0) (i32.const 1)) (else))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:958
+assert_invalid(
+ () => instantiate(`(module (func $$type-both-value-empty-vs-nums (result i32 i32)
+ (if (result i32 i32) (i32.const 1) (then) (else))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:965
+assert_invalid(
+ () => instantiate(`(module (func $$type-no-else-vs-num (result i32)
+ (if (result i32) (i32.const 1) (then (i32.const 1)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:971
+assert_invalid(
+ () => instantiate(`(module (func $$type-no-else-vs-nums (result i32 i32)
+ (if (result i32 i32) (i32.const 1) (then (i32.const 1) (i32.const 1)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:978
+assert_invalid(
+ () => instantiate(`(module (func $$type-then-value-void-vs-num (result i32)
+ (if (result i32) (i32.const 1) (then (nop)) (else (i32.const 0)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:984
+assert_invalid(
+ () => instantiate(`(module (func $$type-else-value-void-vs-num (result i32)
+ (if (result i32) (i32.const 1) (then (i32.const 0)) (else (nop)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:990
+assert_invalid(
+ () => instantiate(`(module (func $$type-both-value-void-vs-num (result i32)
+ (if (result i32) (i32.const 1) (then (nop)) (else (nop)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:997
+assert_invalid(
+ () => instantiate(`(module (func $$type-then-value-void-vs-nums (result i32 i32)
+ (if (result i32 i32) (i32.const 1) (then (nop)) (else (i32.const 0) (i32.const 0)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1003
+assert_invalid(
+ () => instantiate(`(module (func $$type-else-value-void-vs-nums (result i32 i32)
+ (if (result i32 i32) (i32.const 1) (then (i32.const 0) (i32.const 0)) (else (nop)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1009
+assert_invalid(
+ () => instantiate(`(module (func $$type-both-value-void-vs-nums (result i32 i32)
+ (if (result i32 i32) (i32.const 1) (then (nop)) (else (nop)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1016
+assert_invalid(
+ () => instantiate(`(module (func $$type-then-value-num-vs-num (result i32)
+ (if (result i32) (i32.const 1) (then (i64.const 1)) (else (i32.const 1)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1022
+assert_invalid(
+ () => instantiate(`(module (func $$type-else-value-num-vs-num (result i32)
+ (if (result i32) (i32.const 1) (then (i32.const 1)) (else (i64.const 1)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1028
+assert_invalid(
+ () => instantiate(`(module (func $$type-both-value-num-vs-num (result i32)
+ (if (result i32) (i32.const 1) (then (i64.const 1)) (else (i64.const 1)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1035
+assert_invalid(
+ () => instantiate(`(module (func $$type-then-value-num-vs-nums (result i32 i32)
+ (if (result i32 i32) (i32.const 1) (then (i32.const 1)) (else (i32.const 1) (i32.const 1)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1041
+assert_invalid(
+ () => instantiate(`(module (func $$type-else-value-num-vs-nums (result i32 i32)
+ (if (result i32 i32) (i32.const 1) (then (i32.const 1) (i32.const 1)) (else (i32.const 1)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1047
+assert_invalid(
+ () => instantiate(`(module (func $$type-both-value-num-vs-nums (result i32 i32)
+ (if (result i32 i32) (i32.const 1) (then (i32.const 1)) (else (i32.const 1)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1054
+assert_invalid(
+ () => instantiate(`(module (func $$type-then-value-partial-vs-nums (result i32 i32)
+ (i32.const 0)
+ (if (result i32 i32) (i32.const 1) (then (i32.const 1)) (else (i32.const 1) (i32.const 1)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1061
+assert_invalid(
+ () => instantiate(`(module (func $$type-else-value-partial-vs-nums (result i32 i32)
+ (i32.const 0)
+ (if (result i32 i32) (i32.const 1) (then (i32.const 1) (i32.const 1)) (else (i32.const 1)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1068
+assert_invalid(
+ () => instantiate(`(module (func $$type-both-value-partial-vs-nums (result i32 i32)
+ (i32.const 0)
+ (if (result i32 i32) (i32.const 1) (then (i32.const 1)) (else (i32.const 1)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1076
+assert_invalid(
+ () => instantiate(`(module (func $$type-then-value-nums-vs-num (result i32)
+ (if (result i32) (i32.const 1) (then (i32.const 1) (i32.const 1)) (else (i32.const 1)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1082
+assert_invalid(
+ () => instantiate(`(module (func $$type-else-value-nums-vs-num (result i32)
+ (if (result i32) (i32.const 1) (then (i32.const 1)) (else (i32.const 1) (i32.const 1)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1088
+assert_invalid(
+ () => instantiate(`(module (func $$type-both-value-nums-vs-num (result i32)
+ (if (result i32) (i32.const 1) (then (i32.const 1) (i32.const 1)) (else (i32.const 1) (i32.const 1)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1095
+assert_invalid(
+ () => instantiate(`(module (func $$type-both-different-value-num-vs-num (result i32)
+ (if (result i32) (i32.const 1) (then (i64.const 1)) (else (f64.const 1)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1101
+assert_invalid(
+ () => instantiate(`(module (func $$type-both-different-value-nums-vs-nums (result i32 i32)
+ (if (result i32 i32) (i32.const 1) (then (i32.const 1) (i32.const 1) (i32.const 1)) (else (i32.const 1)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1108
+assert_invalid(
+ () => instantiate(`(module (func $$type-then-value-unreached-select (result i32)
+ (if (result i64)
+ (i32.const 0)
+ (then (select (unreachable) (unreachable) (unreachable)))
+ (else (i64.const 0))
+ )
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1118
+assert_invalid(
+ () => instantiate(`(module (func $$type-else-value-unreached-select (result i32)
+ (if (result i64)
+ (i32.const 1)
+ (then (i64.const 0))
+ (else (select (unreachable) (unreachable) (unreachable)))
+ )
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1128
+assert_invalid(
+ () => instantiate(`(module (func $$type-else-value-unreached-select (result i32)
+ (if (result i64)
+ (i32.const 1)
+ (then (select (unreachable) (unreachable) (unreachable)))
+ (else (select (unreachable) (unreachable) (unreachable)))
+ )
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1139
+assert_invalid(
+ () => instantiate(`(module (func $$type-then-break-last-void-vs-num (result i32)
+ (if (result i32) (i32.const 1) (then (br 0)) (else (i32.const 1)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1145
+assert_invalid(
+ () => instantiate(`(module (func $$type-else-break-last-void-vs-num (result i32)
+ (if (result i32) (i32.const 1) (then (i32.const 1)) (else (br 0)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1151
+assert_invalid(
+ () => instantiate(`(module (func $$type-then-break-last-void-vs-nums (result i32 i32)
+ (if (result i32 i32) (i32.const 1) (then (br 0)) (else (i32.const 1) (i32.const 1)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1157
+assert_invalid(
+ () => instantiate(`(module (func $$type-else-break-last-void-vs-nums (result i32 i32)
+ (if (result i32 i32) (i32.const 1) (then (i32.const 1) (i32.const 1)) (else (br 0)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1164
+assert_invalid(
+ () => instantiate(`(module (func $$type-then-break-empty-vs-num (result i32)
+ (if (result i32) (i32.const 1)
+ (then (br 0) (i32.const 1))
+ (else (i32.const 1))
+ )
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1173
+assert_invalid(
+ () => instantiate(`(module (func $$type-else-break-empty-vs-num (result i32)
+ (if (result i32) (i32.const 1)
+ (then (i32.const 1))
+ (else (br 0) (i32.const 1))
+ )
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1182
+assert_invalid(
+ () => instantiate(`(module (func $$type-then-break-empty-vs-nums (result i32 i32)
+ (if (result i32 i32) (i32.const 1)
+ (then (br 0) (i32.const 1) (i32.const 1))
+ (else (i32.const 1) (i32.const 1))
+ )
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1191
+assert_invalid(
+ () => instantiate(`(module (func $$type-else-break-empty-vs-nums (result i32 i32)
+ (if (result i32 i32) (i32.const 1)
+ (then (i32.const 1) (i32.const 1))
+ (else (br 0) (i32.const 1) (i32.const 1))
+ )
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1201
+assert_invalid(
+ () => instantiate(`(module (func $$type-then-break-void-vs-num (result i32)
+ (if (result i32) (i32.const 1)
+ (then (br 0 (nop)) (i32.const 1))
+ (else (i32.const 1))
+ )
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1210
+assert_invalid(
+ () => instantiate(`(module (func $$type-else-break-void-vs-num (result i32)
+ (if (result i32) (i32.const 1)
+ (then (i32.const 1))
+ (else (br 0 (nop)) (i32.const 1))
+ )
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1219
+assert_invalid(
+ () => instantiate(`(module (func $$type-then-break-void-vs-nums (result i32 i32)
+ (if (result i32 i32) (i32.const 1)
+ (then (br 0 (nop)) (i32.const 1) (i32.const 1))
+ (else (i32.const 1) (i32.const 1))
+ )
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1228
+assert_invalid(
+ () => instantiate(`(module (func $$type-else-break-void-vs-nums (result i32 i32)
+ (if (result i32 i32) (i32.const 1)
+ (then (i32.const 1) (i32.const 1))
+ (else (br 0 (nop)) (i32.const 1) (i32.const 1))
+ )
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1238
+assert_invalid(
+ () => instantiate(`(module (func $$type-then-break-num-vs-num (result i32)
+ (if (result i32) (i32.const 1)
+ (then (br 0 (i64.const 1)) (i32.const 1))
+ (else (i32.const 1))
+ )
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1247
+assert_invalid(
+ () => instantiate(`(module (func $$type-else-break-num-vs-num (result i32)
+ (if (result i32) (i32.const 1)
+ (then (i32.const 1))
+ (else (br 0 (i64.const 1)) (i32.const 1))
+ )
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1256
+assert_invalid(
+ () => instantiate(`(module (func $$type-then-break-num-vs-nums (result i32 i32)
+ (if (result i32 i32) (i32.const 1)
+ (then (br 0 (i64.const 1)) (i32.const 1) (i32.const 1))
+ (else (i32.const 1) (i32.const 1))
+ )
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1265
+assert_invalid(
+ () => instantiate(`(module (func $$type-else-break-num-vs-nums (result i32 i32)
+ (if (result i32 i32) (i32.const 1)
+ (then (i32.const 1) (i32.const 1))
+ (else (br 0 (i64.const 1)) (i32.const 1) (i32.const 1))
+ )
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1274
+assert_invalid(
+ () => instantiate(`(module (func $$type-then-break-partial-vs-nums (result i32 i32)
+ (i32.const 1)
+ (if (result i32 i32) (i32.const 1)
+ (then (br 0 (i64.const 1)) (i32.const 1))
+ (else (i32.const 1))
+ )
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1284
+assert_invalid(
+ () => instantiate(`(module (func $$type-else-break-partial-vs-nums (result i32 i32)
+ (i32.const 1)
+ (if (result i32 i32) (i32.const 1)
+ (then (i32.const 1))
+ (else (br 0 (i64.const 1)) (i32.const 1))
+ )
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1295
+assert_invalid(
+ () => instantiate(`(module
+ (func $$type-condition-empty
+ (if (then))
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1303
+assert_invalid(
+ () => instantiate(`(module
+ (func $$type-condition-empty-in-block
+ (i32.const 0)
+ (block (if (then)))
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1312
+assert_invalid(
+ () => instantiate(`(module
+ (func $$type-condition-empty-in-loop
+ (i32.const 0)
+ (loop (if (then)))
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1321
+assert_invalid(
+ () => instantiate(`(module
+ (func $$type-condition-empty-in-then
+ (i32.const 0) (i32.const 0)
+ (if (then (if (then))))
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1330
+assert_invalid(
+ () => instantiate(`(module
+ (func $$type-condition-empty-in-else
+ (i32.const 0) (i32.const 0)
+ (if (result i32) (then (i32.const 0)) (else (if (then)) (i32.const 0)))
+ (drop)
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1340
+assert_invalid(
+ () => instantiate(`(module
+ (func $$type-condition-empty-in-br
+ (i32.const 0)
+ (block (br 0 (if(then))) (drop))
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1349
+assert_invalid(
+ () => instantiate(`(module
+ (func $$type-condition-empty-in-br_if
+ (i32.const 0)
+ (block (br_if 0 (if(then)) (i32.const 1)) (drop))
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1358
+assert_invalid(
+ () => instantiate(`(module
+ (func $$type-condition-empty-in-br_table
+ (i32.const 0)
+ (block (br_table 0 (if(then))) (drop))
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1367
+assert_invalid(
+ () => instantiate(`(module
+ (func $$type-condition-empty-in-return
+ (return (if(then))) (drop)
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1375
+assert_invalid(
+ () => instantiate(`(module
+ (func $$type-condition-empty-in-select
+ (select (if(then)) (i32.const 1) (i32.const 2)) (drop)
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1383
+assert_invalid(
+ () => instantiate(`(module
+ (func $$type-condition-empty-in-call
+ (call 1 (if(then))) (drop)
+ )
+ (func (param i32) (result i32) (local.get 0))
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1392
+assert_invalid(
+ () => instantiate(`(module
+ (func $$f (param i32) (result i32) (local.get 0))
+ (type $$sig (func (param i32) (result i32)))
+ (table funcref (elem $$f))
+ (func $$type-condition-empty-in-call_indirect
+ (block (result i32)
+ (call_indirect (type $$sig)
+ (if(then)) (i32.const 0)
+ )
+ (drop)
+ )
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1408
+assert_invalid(
+ () => instantiate(`(module
+ (func $$type-condition-empty-in-local.set
+ (local i32)
+ (local.set 0 (if(then))) (local.get 0) (drop)
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1417
+assert_invalid(
+ () => instantiate(`(module
+ (func $$type-condition-empty-in-local.tee
+ (local i32)
+ (local.tee 0 (if(then))) (drop)
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1426
+assert_invalid(
+ () => instantiate(`(module
+ (global $$x (mut i32) (i32.const 0))
+ (func $$type-condition-empty-in-global.set
+ (global.set $$x (if(then))) (global.get $$x) (drop)
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1435
+assert_invalid(
+ () => instantiate(`(module
+ (memory 0)
+ (func $$type-condition-empty-in-memory.grow
+ (memory.grow (if(then))) (drop)
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1444
+assert_invalid(
+ () => instantiate(`(module
+ (memory 0)
+ (func $$type-condition-empty-in-load
+ (i32.load (if(then))) (drop)
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1453
+assert_invalid(
+ () => instantiate(`(module
+ (memory 1)
+ (func $$type-condition-empty-in-store
+ (i32.store (if(then)) (i32.const 1))
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1463
+assert_invalid(
+ () => instantiate(`(module (func $$type-param-void-vs-num
+ (if (param i32) (i32.const 1) (then (drop)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1469
+assert_invalid(
+ () => instantiate(`(module (func $$type-param-void-vs-nums
+ (if (param i32 f64) (i32.const 1) (then (drop) (drop)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1475
+assert_invalid(
+ () => instantiate(`(module (func $$type-param-num-vs-num
+ (f32.const 0) (if (param i32) (i32.const 1) (then (drop)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1481
+assert_invalid(
+ () => instantiate(`(module (func $$type-param-num-vs-nums
+ (f32.const 0) (if (param f32 i32) (i32.const 1) (then (drop) (drop)))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1487
+assert_invalid(
+ () => instantiate(`(module (func $$type-param-nested-void-vs-num
+ (block (if (param i32) (i32.const 1) (then (drop))))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1493
+assert_invalid(
+ () => instantiate(`(module (func $$type-param-void-vs-nums
+ (block (if (param i32 f64) (i32.const 1) (then (drop) (drop))))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1499
+assert_invalid(
+ () => instantiate(`(module (func $$type-param-num-vs-num
+ (block (f32.const 0) (if (param i32) (i32.const 1) (then (drop))))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1505
+assert_invalid(
+ () => instantiate(`(module (func $$type-param-num-vs-nums
+ (block (f32.const 0) (if (param f32 i32) (i32.const 1) (then (drop) (drop))))
+ ))`),
+ `type mismatch`,
+);
+
+// ./test/core/if.wast:1512
+assert_malformed(
+ () => instantiate(`(func (param i32) (result i32) if (param $$x i32) end) `),
+ `unexpected token`,
+);
+
+// ./test/core/if.wast:1516
+assert_malformed(
+ () => instantiate(`(func (param i32) (result i32) (if (param $$x i32) (then))) `),
+ `unexpected token`,
+);
+
+// ./test/core/if.wast:1521
+assert_malformed(() => instantiate(`(func i32.const 0 if end $$l) `), `mismatching label`);
+
+// ./test/core/if.wast:1525
+assert_malformed(
+ () => instantiate(`(func i32.const 0 if $$a end $$l) `),
+ `mismatching label`,
+);
+
+// ./test/core/if.wast:1529
+assert_malformed(
+ () => instantiate(`(func i32.const 0 if else $$l end) `),
+ `mismatching label`,
+);
+
+// ./test/core/if.wast:1533
+assert_malformed(
+ () => instantiate(`(func i32.const 0 if $$a else $$l end) `),
+ `mismatching label`,
+);
+
+// ./test/core/if.wast:1537
+assert_malformed(
+ () => instantiate(`(func i32.const 0 if else end $$l) `),
+ `mismatching label`,
+);
+
+// ./test/core/if.wast:1541
+assert_malformed(
+ () => instantiate(`(func i32.const 0 if else $$l end $$l) `),
+ `mismatching label`,
+);
+
+// ./test/core/if.wast:1545
+assert_malformed(
+ () => instantiate(`(func i32.const 0 if else $$l1 end $$l2) `),
+ `mismatching label`,
+);
+
+// ./test/core/if.wast:1549
+assert_malformed(
+ () => instantiate(`(func i32.const 0 if $$a else end $$l) `),
+ `mismatching label`,
+);
+
+// ./test/core/if.wast:1553
+assert_malformed(
+ () => instantiate(`(func i32.const 0 if $$a else $$a end $$l) `),
+ `mismatching label`,
+);
+
+// ./test/core/if.wast:1557
+assert_malformed(
+ () => instantiate(`(func i32.const 0 if $$a else $$l end $$l) `),
+ `mismatching label`,
+);
+
+// ./test/core/if.wast:1561
+assert_malformed(
+ () => instantiate(`(func (if i32.const 0 (then) (else))) `),
+ `unexpected token`,
+);
diff --git a/js/src/jit-test/tests/wasm/spec/gc/obsolete-keywords.wast.js b/js/src/jit-test/tests/wasm/spec/gc/obsolete-keywords.wast.js
new file mode 100644
index 0000000000..9f51433917
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/spec/gc/obsolete-keywords.wast.js
@@ -0,0 +1,82 @@
+/* Copyright 2021 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ./test/core/obsolete-keywords.wast
+
+// ./test/core/obsolete-keywords.wast:2
+assert_malformed(
+ () => instantiate(`(memory 1) (func (drop (current_memory))) `),
+ `unknown operator current_memory`,
+);
+
+// ./test/core/obsolete-keywords.wast:10
+assert_malformed(
+ () => instantiate(`(memory 1) (func (drop (grow_memory (i32.const 0)))) `),
+ `unknown operator grow_memory`,
+);
+
+// ./test/core/obsolete-keywords.wast:19
+assert_malformed(
+ () => instantiate(`(func (local $$i i32) (drop (get_local $$i))) `),
+ `unknown operator get_local`,
+);
+
+// ./test/core/obsolete-keywords.wast:26
+assert_malformed(
+ () => instantiate(`(func (local $$i i32) (set_local $$i (i32.const 0))) `),
+ `unknown operator set_local`,
+);
+
+// ./test/core/obsolete-keywords.wast:33
+assert_malformed(
+ () => instantiate(`(func (local $$i i32) (drop (tee_local $$i (i32.const 0)))) `),
+ `unknown operator tee_local`,
+);
+
+// ./test/core/obsolete-keywords.wast:40
+assert_malformed(
+ () => instantiate(`(global $$g anyfunc (ref.null func)) `),
+ `unknown operator anyfunc`,
+);
+
+// ./test/core/obsolete-keywords.wast:47
+assert_malformed(
+ () => instantiate(`(global $$g i32 (i32.const 0)) (func (drop (get_global $$g))) `),
+ `unknown operator get_global`,
+);
+
+// ./test/core/obsolete-keywords.wast:55
+assert_malformed(
+ () => instantiate(`(global $$g (mut i32) (i32.const 0)) (func (set_global $$g (i32.const 0))) `),
+ `unknown operator set_global`,
+);
+
+// ./test/core/obsolete-keywords.wast:63
+assert_malformed(
+ () => instantiate(`(func (drop (i32.wrap/i64 (i64.const 0)))) `),
+ `unknown operator i32.wrap/i64`,
+);
+
+// ./test/core/obsolete-keywords.wast:70
+assert_malformed(
+ () => instantiate(`(func (drop (i32.trunc_s:sat/f32 (f32.const 0)))) `),
+ `unknown operator i32.trunc_s:sat/f32`,
+);
+
+// ./test/core/obsolete-keywords.wast:77
+assert_malformed(
+ () => instantiate(`(func (drop (f32x4.convert_s/i32x4 (v128.const i64x2 0 0)))) `),
+ `unknown operator f32x4.convert_s/i32x4`,
+);
diff --git a/js/src/jit-test/tests/wasm/spec/gc/ref_cast.wast.js b/js/src/jit-test/tests/wasm/spec/gc/ref_cast.wast.js
new file mode 100644
index 0000000000..e5dcd20a95
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/spec/gc/ref_cast.wast.js
@@ -0,0 +1,279 @@
+/* Copyright 2021 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ./test/core/gc/ref_cast.wast
+
+// ./test/core/gc/ref_cast.wast:3
+let $0 = instantiate(`(module
+ (type $$ft (func))
+ (type $$st (struct))
+ (type $$at (array i8))
+
+ (table 10 anyref)
+
+ (elem declare func $$f)
+ (func $$f)
+
+ (func (export "init") (param $$x externref)
+ (table.set (i32.const 0) (ref.null any))
+ (table.set (i32.const 1) (ref.i31 (i32.const 7)))
+ (table.set (i32.const 2) (struct.new_default $$st))
+ (table.set (i32.const 3) (array.new_default $$at (i32.const 0)))
+ (table.set (i32.const 4) (any.convert_extern (local.get $$x)))
+ (table.set (i32.const 5) (ref.null i31))
+ (table.set (i32.const 6) (ref.null struct))
+ (table.set (i32.const 7) (ref.null none))
+ )
+
+ (func (export "ref_cast_non_null") (param $$i i32)
+ (drop (ref.as_non_null (table.get (local.get $$i))))
+ (drop (ref.cast (ref null any) (table.get (local.get $$i))))
+ )
+ (func (export "ref_cast_null") (param $$i i32)
+ (drop (ref.cast anyref (table.get (local.get $$i))))
+ (drop (ref.cast structref (table.get (local.get $$i))))
+ (drop (ref.cast arrayref (table.get (local.get $$i))))
+ (drop (ref.cast i31ref (table.get (local.get $$i))))
+ (drop (ref.cast nullref (table.get (local.get $$i))))
+ )
+ (func (export "ref_cast_i31") (param $$i i32)
+ (drop (ref.cast (ref i31) (table.get (local.get $$i))))
+ (drop (ref.cast i31ref (table.get (local.get $$i))))
+ )
+ (func (export "ref_cast_struct") (param $$i i32)
+ (drop (ref.cast (ref struct) (table.get (local.get $$i))))
+ (drop (ref.cast structref (table.get (local.get $$i))))
+ )
+ (func (export "ref_cast_array") (param $$i i32)
+ (drop (ref.cast (ref array) (table.get (local.get $$i))))
+ (drop (ref.cast arrayref (table.get (local.get $$i))))
+ )
+)`);
+
+// ./test/core/gc/ref_cast.wast:49
+invoke($0, `init`, [externref(0)]);
+
+// ./test/core/gc/ref_cast.wast:51
+assert_trap(() => invoke($0, `ref_cast_non_null`, [0]), `null reference`);
+
+// ./test/core/gc/ref_cast.wast:52
+assert_return(() => invoke($0, `ref_cast_non_null`, [1]), []);
+
+// ./test/core/gc/ref_cast.wast:53
+assert_return(() => invoke($0, `ref_cast_non_null`, [2]), []);
+
+// ./test/core/gc/ref_cast.wast:54
+assert_return(() => invoke($0, `ref_cast_non_null`, [3]), []);
+
+// ./test/core/gc/ref_cast.wast:55
+assert_return(() => invoke($0, `ref_cast_non_null`, [4]), []);
+
+// ./test/core/gc/ref_cast.wast:56
+assert_trap(() => invoke($0, `ref_cast_non_null`, [5]), `null reference`);
+
+// ./test/core/gc/ref_cast.wast:57
+assert_trap(() => invoke($0, `ref_cast_non_null`, [6]), `null reference`);
+
+// ./test/core/gc/ref_cast.wast:58
+assert_trap(() => invoke($0, `ref_cast_non_null`, [7]), `null reference`);
+
+// ./test/core/gc/ref_cast.wast:60
+assert_return(() => invoke($0, `ref_cast_null`, [0]), []);
+
+// ./test/core/gc/ref_cast.wast:61
+assert_trap(() => invoke($0, `ref_cast_null`, [1]), `cast failure`);
+
+// ./test/core/gc/ref_cast.wast:62
+assert_trap(() => invoke($0, `ref_cast_null`, [2]), `cast failure`);
+
+// ./test/core/gc/ref_cast.wast:63
+assert_trap(() => invoke($0, `ref_cast_null`, [3]), `cast failure`);
+
+// ./test/core/gc/ref_cast.wast:64
+assert_trap(() => invoke($0, `ref_cast_null`, [4]), `cast failure`);
+
+// ./test/core/gc/ref_cast.wast:65
+assert_return(() => invoke($0, `ref_cast_null`, [5]), []);
+
+// ./test/core/gc/ref_cast.wast:66
+assert_return(() => invoke($0, `ref_cast_null`, [6]), []);
+
+// ./test/core/gc/ref_cast.wast:67
+assert_return(() => invoke($0, `ref_cast_null`, [7]), []);
+
+// ./test/core/gc/ref_cast.wast:69
+assert_trap(() => invoke($0, `ref_cast_i31`, [0]), `cast failure`);
+
+// ./test/core/gc/ref_cast.wast:70
+assert_return(() => invoke($0, `ref_cast_i31`, [1]), []);
+
+// ./test/core/gc/ref_cast.wast:71
+assert_trap(() => invoke($0, `ref_cast_i31`, [2]), `cast failure`);
+
+// ./test/core/gc/ref_cast.wast:72
+assert_trap(() => invoke($0, `ref_cast_i31`, [3]), `cast failure`);
+
+// ./test/core/gc/ref_cast.wast:73
+assert_trap(() => invoke($0, `ref_cast_i31`, [4]), `cast failure`);
+
+// ./test/core/gc/ref_cast.wast:74
+assert_trap(() => invoke($0, `ref_cast_i31`, [5]), `cast failure`);
+
+// ./test/core/gc/ref_cast.wast:75
+assert_trap(() => invoke($0, `ref_cast_i31`, [6]), `cast failure`);
+
+// ./test/core/gc/ref_cast.wast:76
+assert_trap(() => invoke($0, `ref_cast_i31`, [7]), `cast failure`);
+
+// ./test/core/gc/ref_cast.wast:78
+assert_trap(() => invoke($0, `ref_cast_struct`, [0]), `cast failure`);
+
+// ./test/core/gc/ref_cast.wast:79
+assert_trap(() => invoke($0, `ref_cast_struct`, [1]), `cast failure`);
+
+// ./test/core/gc/ref_cast.wast:80
+assert_return(() => invoke($0, `ref_cast_struct`, [2]), []);
+
+// ./test/core/gc/ref_cast.wast:81
+assert_trap(() => invoke($0, `ref_cast_struct`, [3]), `cast failure`);
+
+// ./test/core/gc/ref_cast.wast:82
+assert_trap(() => invoke($0, `ref_cast_struct`, [4]), `cast failure`);
+
+// ./test/core/gc/ref_cast.wast:83
+assert_trap(() => invoke($0, `ref_cast_struct`, [5]), `cast failure`);
+
+// ./test/core/gc/ref_cast.wast:84
+assert_trap(() => invoke($0, `ref_cast_struct`, [6]), `cast failure`);
+
+// ./test/core/gc/ref_cast.wast:85
+assert_trap(() => invoke($0, `ref_cast_struct`, [7]), `cast failure`);
+
+// ./test/core/gc/ref_cast.wast:87
+assert_trap(() => invoke($0, `ref_cast_array`, [0]), `cast failure`);
+
+// ./test/core/gc/ref_cast.wast:88
+assert_trap(() => invoke($0, `ref_cast_array`, [1]), `cast failure`);
+
+// ./test/core/gc/ref_cast.wast:89
+assert_trap(() => invoke($0, `ref_cast_array`, [2]), `cast failure`);
+
+// ./test/core/gc/ref_cast.wast:90
+assert_return(() => invoke($0, `ref_cast_array`, [3]), []);
+
+// ./test/core/gc/ref_cast.wast:91
+assert_trap(() => invoke($0, `ref_cast_array`, [4]), `cast failure`);
+
+// ./test/core/gc/ref_cast.wast:92
+assert_trap(() => invoke($0, `ref_cast_array`, [5]), `cast failure`);
+
+// ./test/core/gc/ref_cast.wast:93
+assert_trap(() => invoke($0, `ref_cast_array`, [6]), `cast failure`);
+
+// ./test/core/gc/ref_cast.wast:94
+assert_trap(() => invoke($0, `ref_cast_array`, [7]), `cast failure`);
+
+// ./test/core/gc/ref_cast.wast:99
+let $1 = instantiate(`(module
+ (type $$t0 (sub (struct)))
+ (type $$t1 (sub $$t0 (struct (field i32))))
+ (type $$t1' (sub $$t0 (struct (field i32))))
+ (type $$t2 (sub $$t1 (struct (field i32 i32))))
+ (type $$t2' (sub $$t1' (struct (field i32 i32))))
+ (type $$t3 (sub $$t0 (struct (field i32 i32))))
+ (type $$t0' (sub $$t0 (struct)))
+ (type $$t4 (sub $$t0' (struct (field i32 i32))))
+
+ (table 20 (ref null struct))
+
+ (func $$init
+ (table.set (i32.const 0) (struct.new_default $$t0))
+ (table.set (i32.const 10) (struct.new_default $$t0))
+ (table.set (i32.const 1) (struct.new_default $$t1))
+ (table.set (i32.const 11) (struct.new_default $$t1'))
+ (table.set (i32.const 2) (struct.new_default $$t2))
+ (table.set (i32.const 12) (struct.new_default $$t2'))
+ (table.set (i32.const 3) (struct.new_default $$t3))
+ (table.set (i32.const 4) (struct.new_default $$t4))
+ )
+
+ (func (export "test-sub")
+ (call $$init)
+
+ (drop (ref.cast (ref null $$t0) (ref.null struct)))
+ (drop (ref.cast (ref null $$t0) (table.get (i32.const 0))))
+ (drop (ref.cast (ref null $$t0) (table.get (i32.const 1))))
+ (drop (ref.cast (ref null $$t0) (table.get (i32.const 2))))
+ (drop (ref.cast (ref null $$t0) (table.get (i32.const 3))))
+ (drop (ref.cast (ref null $$t0) (table.get (i32.const 4))))
+
+ (drop (ref.cast (ref null $$t0) (ref.null struct)))
+ (drop (ref.cast (ref null $$t1) (table.get (i32.const 1))))
+ (drop (ref.cast (ref null $$t1) (table.get (i32.const 2))))
+
+ (drop (ref.cast (ref null $$t0) (ref.null struct)))
+ (drop (ref.cast (ref null $$t2) (table.get (i32.const 2))))
+
+ (drop (ref.cast (ref null $$t0) (ref.null struct)))
+ (drop (ref.cast (ref null $$t3) (table.get (i32.const 3))))
+
+ (drop (ref.cast (ref null $$t4) (table.get (i32.const 4))))
+
+ (drop (ref.cast (ref $$t0) (table.get (i32.const 0))))
+ (drop (ref.cast (ref $$t0) (table.get (i32.const 1))))
+ (drop (ref.cast (ref $$t0) (table.get (i32.const 2))))
+ (drop (ref.cast (ref $$t0) (table.get (i32.const 3))))
+ (drop (ref.cast (ref $$t0) (table.get (i32.const 4))))
+
+ (drop (ref.cast (ref $$t1) (table.get (i32.const 1))))
+ (drop (ref.cast (ref $$t1) (table.get (i32.const 2))))
+
+ (drop (ref.cast (ref $$t2) (table.get (i32.const 2))))
+
+ (drop (ref.cast (ref $$t3) (table.get (i32.const 3))))
+
+ (drop (ref.cast (ref $$t4) (table.get (i32.const 4))))
+ )
+
+ (func (export "test-canon")
+ (call $$init)
+
+ (drop (ref.cast (ref $$t0) (table.get (i32.const 0))))
+ (drop (ref.cast (ref $$t0) (table.get (i32.const 1))))
+ (drop (ref.cast (ref $$t0) (table.get (i32.const 2))))
+ (drop (ref.cast (ref $$t0) (table.get (i32.const 3))))
+ (drop (ref.cast (ref $$t0) (table.get (i32.const 4))))
+
+ (drop (ref.cast (ref $$t0) (table.get (i32.const 10))))
+ (drop (ref.cast (ref $$t0) (table.get (i32.const 11))))
+ (drop (ref.cast (ref $$t0) (table.get (i32.const 12))))
+
+ (drop (ref.cast (ref $$t1') (table.get (i32.const 1))))
+ (drop (ref.cast (ref $$t1') (table.get (i32.const 2))))
+
+ (drop (ref.cast (ref $$t1) (table.get (i32.const 11))))
+ (drop (ref.cast (ref $$t1) (table.get (i32.const 12))))
+
+ (drop (ref.cast (ref $$t2') (table.get (i32.const 2))))
+
+ (drop (ref.cast (ref $$t2) (table.get (i32.const 12))))
+ )
+)`);
+
+// ./test/core/gc/ref_cast.wast:185
+invoke($1, `test-sub`, []);
+
+// ./test/core/gc/ref_cast.wast:186
+invoke($1, `test-canon`, []);
diff --git a/js/src/jit-test/tests/wasm/spec/gc/ref_eq.wast.js b/js/src/jit-test/tests/wasm/spec/gc/ref_eq.wast.js
new file mode 100644
index 0000000000..098e7a1396
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/spec/gc/ref_eq.wast.js
@@ -0,0 +1,351 @@
+/* Copyright 2021 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ./test/core/gc/ref_eq.wast
+
+// ./test/core/gc/ref_eq.wast:1
+let $0 = instantiate(`(module
+ (type $$st (sub (struct)))
+ (type $$st' (sub (struct (field i32))))
+ (type $$at (array i8))
+ (type $$st-sub1 (sub $$st (struct)))
+ (type $$st-sub2 (sub $$st (struct)))
+ (type $$st'-sub1 (sub $$st' (struct (field i32))))
+ (type $$st'-sub2 (sub $$st' (struct (field i32))))
+
+ (table 20 (ref null eq))
+
+ (func (export "init")
+ (table.set (i32.const 0) (ref.null eq))
+ (table.set (i32.const 1) (ref.null i31))
+ (table.set (i32.const 2) (ref.i31 (i32.const 7)))
+ (table.set (i32.const 3) (ref.i31 (i32.const 7)))
+ (table.set (i32.const 4) (ref.i31 (i32.const 8)))
+ (table.set (i32.const 5) (struct.new_default $$st))
+ (table.set (i32.const 6) (struct.new_default $$st))
+ (table.set (i32.const 7) (array.new_default $$at (i32.const 0)))
+ (table.set (i32.const 8) (array.new_default $$at (i32.const 0)))
+ )
+
+ (func (export "eq") (param $$i i32) (param $$j i32) (result i32)
+ (ref.eq (table.get (local.get $$i)) (table.get (local.get $$j)))
+ )
+)`);
+
+// ./test/core/gc/ref_eq.wast:29
+invoke($0, `init`, []);
+
+// ./test/core/gc/ref_eq.wast:31
+assert_return(() => invoke($0, `eq`, [0, 0]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_eq.wast:32
+assert_return(() => invoke($0, `eq`, [0, 1]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_eq.wast:33
+assert_return(() => invoke($0, `eq`, [0, 2]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:34
+assert_return(() => invoke($0, `eq`, [0, 3]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:35
+assert_return(() => invoke($0, `eq`, [0, 4]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:36
+assert_return(() => invoke($0, `eq`, [0, 5]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:37
+assert_return(() => invoke($0, `eq`, [0, 6]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:38
+assert_return(() => invoke($0, `eq`, [0, 7]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:39
+assert_return(() => invoke($0, `eq`, [0, 8]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:41
+assert_return(() => invoke($0, `eq`, [1, 0]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_eq.wast:42
+assert_return(() => invoke($0, `eq`, [1, 1]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_eq.wast:43
+assert_return(() => invoke($0, `eq`, [1, 2]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:44
+assert_return(() => invoke($0, `eq`, [1, 3]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:45
+assert_return(() => invoke($0, `eq`, [1, 4]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:46
+assert_return(() => invoke($0, `eq`, [1, 5]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:47
+assert_return(() => invoke($0, `eq`, [1, 6]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:48
+assert_return(() => invoke($0, `eq`, [1, 7]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:49
+assert_return(() => invoke($0, `eq`, [1, 8]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:51
+assert_return(() => invoke($0, `eq`, [2, 0]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:52
+assert_return(() => invoke($0, `eq`, [2, 1]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:53
+assert_return(() => invoke($0, `eq`, [2, 2]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_eq.wast:54
+assert_return(() => invoke($0, `eq`, [2, 3]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_eq.wast:55
+assert_return(() => invoke($0, `eq`, [2, 4]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:56
+assert_return(() => invoke($0, `eq`, [2, 5]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:57
+assert_return(() => invoke($0, `eq`, [2, 6]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:58
+assert_return(() => invoke($0, `eq`, [2, 7]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:59
+assert_return(() => invoke($0, `eq`, [2, 8]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:61
+assert_return(() => invoke($0, `eq`, [3, 0]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:62
+assert_return(() => invoke($0, `eq`, [3, 1]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:63
+assert_return(() => invoke($0, `eq`, [3, 2]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_eq.wast:64
+assert_return(() => invoke($0, `eq`, [3, 3]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_eq.wast:65
+assert_return(() => invoke($0, `eq`, [3, 4]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:66
+assert_return(() => invoke($0, `eq`, [3, 5]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:67
+assert_return(() => invoke($0, `eq`, [3, 6]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:68
+assert_return(() => invoke($0, `eq`, [3, 7]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:69
+assert_return(() => invoke($0, `eq`, [3, 8]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:71
+assert_return(() => invoke($0, `eq`, [4, 0]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:72
+assert_return(() => invoke($0, `eq`, [4, 1]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:73
+assert_return(() => invoke($0, `eq`, [4, 2]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:74
+assert_return(() => invoke($0, `eq`, [4, 3]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:75
+assert_return(() => invoke($0, `eq`, [4, 4]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_eq.wast:76
+assert_return(() => invoke($0, `eq`, [4, 5]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:77
+assert_return(() => invoke($0, `eq`, [4, 6]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:78
+assert_return(() => invoke($0, `eq`, [4, 7]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:79
+assert_return(() => invoke($0, `eq`, [4, 8]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:81
+assert_return(() => invoke($0, `eq`, [5, 0]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:82
+assert_return(() => invoke($0, `eq`, [5, 1]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:83
+assert_return(() => invoke($0, `eq`, [5, 2]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:84
+assert_return(() => invoke($0, `eq`, [5, 3]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:85
+assert_return(() => invoke($0, `eq`, [5, 4]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:86
+assert_return(() => invoke($0, `eq`, [5, 5]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_eq.wast:87
+assert_return(() => invoke($0, `eq`, [5, 6]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:88
+assert_return(() => invoke($0, `eq`, [5, 7]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:89
+assert_return(() => invoke($0, `eq`, [5, 8]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:91
+assert_return(() => invoke($0, `eq`, [6, 0]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:92
+assert_return(() => invoke($0, `eq`, [6, 1]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:93
+assert_return(() => invoke($0, `eq`, [6, 2]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:94
+assert_return(() => invoke($0, `eq`, [6, 3]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:95
+assert_return(() => invoke($0, `eq`, [6, 4]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:96
+assert_return(() => invoke($0, `eq`, [6, 5]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:97
+assert_return(() => invoke($0, `eq`, [6, 6]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_eq.wast:98
+assert_return(() => invoke($0, `eq`, [6, 7]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:99
+assert_return(() => invoke($0, `eq`, [6, 8]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:101
+assert_return(() => invoke($0, `eq`, [7, 0]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:102
+assert_return(() => invoke($0, `eq`, [7, 1]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:103
+assert_return(() => invoke($0, `eq`, [7, 2]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:104
+assert_return(() => invoke($0, `eq`, [7, 3]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:105
+assert_return(() => invoke($0, `eq`, [7, 4]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:106
+assert_return(() => invoke($0, `eq`, [7, 5]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:107
+assert_return(() => invoke($0, `eq`, [7, 6]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:108
+assert_return(() => invoke($0, `eq`, [7, 7]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_eq.wast:109
+assert_return(() => invoke($0, `eq`, [7, 8]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:111
+assert_return(() => invoke($0, `eq`, [8, 0]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:112
+assert_return(() => invoke($0, `eq`, [8, 1]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:113
+assert_return(() => invoke($0, `eq`, [8, 2]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:114
+assert_return(() => invoke($0, `eq`, [8, 3]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:115
+assert_return(() => invoke($0, `eq`, [8, 4]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:116
+assert_return(() => invoke($0, `eq`, [8, 5]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:117
+assert_return(() => invoke($0, `eq`, [8, 6]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:118
+assert_return(() => invoke($0, `eq`, [8, 7]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_eq.wast:119
+assert_return(() => invoke($0, `eq`, [8, 8]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_eq.wast:121
+assert_invalid(
+ () => instantiate(`(module
+ (func (export "eq") (param $$r (ref any)) (result i32)
+ (ref.eq (local.get $$r) (local.get $$r))
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/gc/ref_eq.wast:129
+assert_invalid(
+ () => instantiate(`(module
+ (func (export "eq") (param $$r (ref null any)) (result i32)
+ (ref.eq (local.get $$r) (local.get $$r))
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/gc/ref_eq.wast:137
+assert_invalid(
+ () => instantiate(`(module
+ (func (export "eq") (param $$r (ref func)) (result i32)
+ (ref.eq (local.get $$r) (local.get $$r))
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/gc/ref_eq.wast:145
+assert_invalid(
+ () => instantiate(`(module
+ (func (export "eq") (param $$r (ref null func)) (result i32)
+ (ref.eq (local.get $$r) (local.get $$r))
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/gc/ref_eq.wast:153
+assert_invalid(
+ () => instantiate(`(module
+ (func (export "eq") (param $$r (ref extern)) (result i32)
+ (ref.eq (local.get $$r) (local.get $$r))
+ )
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/gc/ref_eq.wast:161
+assert_invalid(
+ () => instantiate(`(module
+ (func (export "eq") (param $$r (ref null extern)) (result i32)
+ (ref.eq (local.get $$r) (local.get $$r))
+ )
+ )`),
+ `type mismatch`,
+);
diff --git a/js/src/jit-test/tests/wasm/spec/gc/ref_null.wast.js b/js/src/jit-test/tests/wasm/spec/gc/ref_null.wast.js
new file mode 100644
index 0000000000..46f1e2d50a
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/spec/gc/ref_null.wast.js
@@ -0,0 +1,127 @@
+/* Copyright 2021 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ./test/core/ref_null.wast
+
+// ./test/core/ref_null.wast:1
+let $0 = instantiate(`(module
+ (type $$t (func))
+ (func (export "anyref") (result anyref) (ref.null any))
+ (func (export "funcref") (result funcref) (ref.null func))
+ (func (export "ref") (result (ref null $$t)) (ref.null $$t))
+
+ (global anyref (ref.null any))
+ (global funcref (ref.null func))
+ (global (ref null $$t) (ref.null $$t))
+)`);
+
+// ./test/core/ref_null.wast:12
+assert_return(() => invoke($0, `anyref`, []), [value('anyref', null)]);
+
+// ./test/core/ref_null.wast:13
+assert_return(() => invoke($0, `funcref`, []), [value('anyfunc', null)]);
+
+// ./test/core/ref_null.wast:14
+assert_return(() => invoke($0, `ref`, []), [null]);
+
+// ./test/core/ref_null.wast:17
+let $1 = instantiate(`(module
+ (type $$t (func))
+ (global $$null nullref (ref.null none))
+ (global $$nullfunc nullfuncref (ref.null nofunc))
+ (global $$nullextern nullexternref (ref.null noextern))
+ (func (export "anyref") (result anyref) (global.get $$null))
+ (func (export "nullref") (result nullref) (global.get $$null))
+ (func (export "funcref") (result funcref) (global.get $$nullfunc))
+ (func (export "nullfuncref") (result nullfuncref) (global.get $$nullfunc))
+ (func (export "externref") (result externref) (global.get $$nullextern))
+ (func (export "nullexternref") (result nullexternref) (global.get $$nullextern))
+ (func (export "ref") (result (ref null $$t)) (global.get $$nullfunc))
+
+ (global anyref (ref.null any))
+ (global anyref (ref.null none))
+ (global funcref (ref.null func))
+ (global funcref (ref.null nofunc))
+ (global externref (ref.null extern))
+ (global externref (ref.null noextern))
+ (global nullref (ref.null none))
+ (global nullfuncref (ref.null nofunc))
+ (global nullexternref (ref.null noextern))
+ (global (ref null $$t) (ref.null $$t))
+ (global (ref null $$t) (ref.null nofunc))
+)`);
+
+// ./test/core/ref_null.wast:43
+assert_return(() => invoke($1, `anyref`, []), [value('anyref', null)]);
+
+// ./test/core/ref_null.wast:44
+assert_return(() => invoke($1, `anyref`, []), [value('nullref', null)]);
+
+// ./test/core/ref_null.wast:45
+assert_return(() => invoke($1, `anyref`, []), [null]);
+
+// ./test/core/ref_null.wast:46
+assert_return(() => invoke($1, `nullref`, []), [value('anyref', null)]);
+
+// ./test/core/ref_null.wast:47
+assert_return(() => invoke($1, `nullref`, []), [value('nullref', null)]);
+
+// ./test/core/ref_null.wast:48
+assert_return(() => invoke($1, `nullref`, []), [null]);
+
+// ./test/core/ref_null.wast:49
+assert_return(() => invoke($1, `funcref`, []), [value('anyfunc', null)]);
+
+// ./test/core/ref_null.wast:50
+assert_return(() => invoke($1, `funcref`, []), [value('nullfuncref', null)]);
+
+// ./test/core/ref_null.wast:51
+assert_return(() => invoke($1, `funcref`, []), [null]);
+
+// ./test/core/ref_null.wast:52
+assert_return(() => invoke($1, `nullfuncref`, []), [value('anyfunc', null)]);
+
+// ./test/core/ref_null.wast:53
+assert_return(() => invoke($1, `nullfuncref`, []), [value('nullfuncref', null)]);
+
+// ./test/core/ref_null.wast:54
+assert_return(() => invoke($1, `nullfuncref`, []), [null]);
+
+// ./test/core/ref_null.wast:55
+assert_return(() => invoke($1, `externref`, []), [value('externref', null)]);
+
+// ./test/core/ref_null.wast:56
+assert_return(() => invoke($1, `externref`, []), [value('nullexternref', null)]);
+
+// ./test/core/ref_null.wast:57
+assert_return(() => invoke($1, `externref`, []), [null]);
+
+// ./test/core/ref_null.wast:58
+assert_return(() => invoke($1, `nullexternref`, []), [value('externref', null)]);
+
+// ./test/core/ref_null.wast:59
+assert_return(() => invoke($1, `nullexternref`, []), [value('nullexternref', null)]);
+
+// ./test/core/ref_null.wast:60
+assert_return(() => invoke($1, `nullexternref`, []), [null]);
+
+// ./test/core/ref_null.wast:61
+assert_return(() => invoke($1, `ref`, []), [value('anyfunc', null)]);
+
+// ./test/core/ref_null.wast:62
+assert_return(() => invoke($1, `ref`, []), [value('nullfuncref', null)]);
+
+// ./test/core/ref_null.wast:63
+assert_return(() => invoke($1, `ref`, []), [null]);
diff --git a/js/src/jit-test/tests/wasm/spec/gc/ref_test.wast.js b/js/src/jit-test/tests/wasm/spec/gc/ref_test.wast.js
new file mode 100644
index 0000000000..fc0f2c0a4c
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/spec/gc/ref_test.wast.js
@@ -0,0 +1,470 @@
+/* Copyright 2021 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ./test/core/gc/ref_test.wast
+
+// ./test/core/gc/ref_test.wast:3
+let $0 = instantiate(`(module
+ (type $$ft (func))
+ (type $$st (struct))
+ (type $$at (array i8))
+
+ (table $$ta 10 anyref)
+ (table $$tf 10 funcref)
+ (table $$te 10 externref)
+
+ (elem declare func $$f)
+ (func $$f)
+
+ (func (export "init") (param $$x externref)
+ (table.set $$ta (i32.const 0) (ref.null any))
+ (table.set $$ta (i32.const 1) (ref.null struct))
+ (table.set $$ta (i32.const 2) (ref.null none))
+ (table.set $$ta (i32.const 3) (ref.i31 (i32.const 7)))
+ (table.set $$ta (i32.const 4) (struct.new_default $$st))
+ (table.set $$ta (i32.const 5) (array.new_default $$at (i32.const 0)))
+ (table.set $$ta (i32.const 6) (any.convert_extern (local.get $$x)))
+ (table.set $$ta (i32.const 7) (any.convert_extern (ref.null extern)))
+
+ (table.set $$tf (i32.const 0) (ref.null nofunc))
+ (table.set $$tf (i32.const 1) (ref.null func))
+ (table.set $$tf (i32.const 2) (ref.func $$f))
+
+ (table.set $$te (i32.const 0) (ref.null noextern))
+ (table.set $$te (i32.const 1) (ref.null extern))
+ (table.set $$te (i32.const 2) (local.get $$x))
+ (table.set $$te (i32.const 3) (extern.convert_any (ref.i31 (i32.const 8))))
+ (table.set $$te (i32.const 4) (extern.convert_any (struct.new_default $$st)))
+ (table.set $$te (i32.const 5) (extern.convert_any (ref.null any)))
+ )
+
+ (func (export "ref_test_null_data") (param $$i i32) (result i32)
+ (i32.add
+ (ref.is_null (table.get $$ta (local.get $$i)))
+ (ref.test nullref (table.get $$ta (local.get $$i)))
+ )
+ )
+ (func (export "ref_test_any") (param $$i i32) (result i32)
+ (i32.add
+ (ref.test (ref any) (table.get $$ta (local.get $$i)))
+ (ref.test anyref (table.get $$ta (local.get $$i)))
+ )
+ )
+ (func (export "ref_test_eq") (param $$i i32) (result i32)
+ (i32.add
+ (ref.test (ref eq) (table.get $$ta (local.get $$i)))
+ (ref.test eqref (table.get $$ta (local.get $$i)))
+ )
+ )
+ (func (export "ref_test_i31") (param $$i i32) (result i32)
+ (i32.add
+ (ref.test (ref i31) (table.get $$ta (local.get $$i)))
+ (ref.test i31ref (table.get $$ta (local.get $$i)))
+ )
+ )
+ (func (export "ref_test_struct") (param $$i i32) (result i32)
+ (i32.add
+ (ref.test (ref struct) (table.get $$ta (local.get $$i)))
+ (ref.test structref (table.get $$ta (local.get $$i)))
+ )
+ )
+ (func (export "ref_test_array") (param $$i i32) (result i32)
+ (i32.add
+ (ref.test (ref array) (table.get $$ta (local.get $$i)))
+ (ref.test arrayref (table.get $$ta (local.get $$i)))
+ )
+ )
+
+ (func (export "ref_test_null_func") (param $$i i32) (result i32)
+ (i32.add
+ (ref.is_null (table.get $$tf (local.get $$i)))
+ (ref.test (ref null nofunc) (table.get $$tf (local.get $$i)))
+ )
+ )
+ (func (export "ref_test_func") (param $$i i32) (result i32)
+ (i32.add
+ (ref.test (ref func) (table.get $$tf (local.get $$i)))
+ (ref.test funcref (table.get $$tf (local.get $$i)))
+ )
+ )
+
+ (func (export "ref_test_null_extern") (param $$i i32) (result i32)
+ (i32.add
+ (ref.is_null (table.get $$te (local.get $$i)))
+ (ref.test (ref null noextern) (table.get $$te (local.get $$i)))
+ )
+ )
+ (func (export "ref_test_extern") (param $$i i32) (result i32)
+ (i32.add
+ (ref.test (ref extern) (table.get $$te (local.get $$i)))
+ (ref.test externref (table.get $$te (local.get $$i)))
+ )
+ )
+)`);
+
+// ./test/core/gc/ref_test.wast:101
+invoke($0, `init`, [externref(0)]);
+
+// ./test/core/gc/ref_test.wast:103
+assert_return(() => invoke($0, `ref_test_null_data`, [0]), [value("i32", 2)]);
+
+// ./test/core/gc/ref_test.wast:104
+assert_return(() => invoke($0, `ref_test_null_data`, [1]), [value("i32", 2)]);
+
+// ./test/core/gc/ref_test.wast:105
+assert_return(() => invoke($0, `ref_test_null_data`, [2]), [value("i32", 2)]);
+
+// ./test/core/gc/ref_test.wast:106
+assert_return(() => invoke($0, `ref_test_null_data`, [3]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_test.wast:107
+assert_return(() => invoke($0, `ref_test_null_data`, [4]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_test.wast:108
+assert_return(() => invoke($0, `ref_test_null_data`, [5]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_test.wast:109
+assert_return(() => invoke($0, `ref_test_null_data`, [6]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_test.wast:110
+assert_return(() => invoke($0, `ref_test_null_data`, [7]), [value("i32", 2)]);
+
+// ./test/core/gc/ref_test.wast:112
+assert_return(() => invoke($0, `ref_test_any`, [0]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_test.wast:113
+assert_return(() => invoke($0, `ref_test_any`, [1]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_test.wast:114
+assert_return(() => invoke($0, `ref_test_any`, [2]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_test.wast:115
+assert_return(() => invoke($0, `ref_test_any`, [3]), [value("i32", 2)]);
+
+// ./test/core/gc/ref_test.wast:116
+assert_return(() => invoke($0, `ref_test_any`, [4]), [value("i32", 2)]);
+
+// ./test/core/gc/ref_test.wast:117
+assert_return(() => invoke($0, `ref_test_any`, [5]), [value("i32", 2)]);
+
+// ./test/core/gc/ref_test.wast:118
+assert_return(() => invoke($0, `ref_test_any`, [6]), [value("i32", 2)]);
+
+// ./test/core/gc/ref_test.wast:119
+assert_return(() => invoke($0, `ref_test_any`, [7]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_test.wast:121
+assert_return(() => invoke($0, `ref_test_eq`, [0]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_test.wast:122
+assert_return(() => invoke($0, `ref_test_eq`, [1]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_test.wast:123
+assert_return(() => invoke($0, `ref_test_eq`, [2]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_test.wast:124
+assert_return(() => invoke($0, `ref_test_eq`, [3]), [value("i32", 2)]);
+
+// ./test/core/gc/ref_test.wast:125
+assert_return(() => invoke($0, `ref_test_eq`, [4]), [value("i32", 2)]);
+
+// ./test/core/gc/ref_test.wast:126
+assert_return(() => invoke($0, `ref_test_eq`, [5]), [value("i32", 2)]);
+
+// ./test/core/gc/ref_test.wast:127
+assert_return(() => invoke($0, `ref_test_eq`, [6]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_test.wast:128
+assert_return(() => invoke($0, `ref_test_eq`, [7]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_test.wast:130
+assert_return(() => invoke($0, `ref_test_i31`, [0]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_test.wast:131
+assert_return(() => invoke($0, `ref_test_i31`, [1]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_test.wast:132
+assert_return(() => invoke($0, `ref_test_i31`, [2]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_test.wast:133
+assert_return(() => invoke($0, `ref_test_i31`, [3]), [value("i32", 2)]);
+
+// ./test/core/gc/ref_test.wast:134
+assert_return(() => invoke($0, `ref_test_i31`, [4]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_test.wast:135
+assert_return(() => invoke($0, `ref_test_i31`, [5]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_test.wast:136
+assert_return(() => invoke($0, `ref_test_i31`, [6]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_test.wast:137
+assert_return(() => invoke($0, `ref_test_i31`, [7]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_test.wast:139
+assert_return(() => invoke($0, `ref_test_struct`, [0]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_test.wast:140
+assert_return(() => invoke($0, `ref_test_struct`, [1]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_test.wast:141
+assert_return(() => invoke($0, `ref_test_struct`, [2]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_test.wast:142
+assert_return(() => invoke($0, `ref_test_struct`, [3]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_test.wast:143
+assert_return(() => invoke($0, `ref_test_struct`, [4]), [value("i32", 2)]);
+
+// ./test/core/gc/ref_test.wast:144
+assert_return(() => invoke($0, `ref_test_struct`, [5]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_test.wast:145
+assert_return(() => invoke($0, `ref_test_struct`, [6]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_test.wast:146
+assert_return(() => invoke($0, `ref_test_struct`, [7]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_test.wast:148
+assert_return(() => invoke($0, `ref_test_array`, [0]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_test.wast:149
+assert_return(() => invoke($0, `ref_test_array`, [1]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_test.wast:150
+assert_return(() => invoke($0, `ref_test_array`, [2]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_test.wast:151
+assert_return(() => invoke($0, `ref_test_array`, [3]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_test.wast:152
+assert_return(() => invoke($0, `ref_test_array`, [4]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_test.wast:153
+assert_return(() => invoke($0, `ref_test_array`, [5]), [value("i32", 2)]);
+
+// ./test/core/gc/ref_test.wast:154
+assert_return(() => invoke($0, `ref_test_array`, [6]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_test.wast:155
+assert_return(() => invoke($0, `ref_test_array`, [7]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_test.wast:157
+assert_return(() => invoke($0, `ref_test_null_func`, [0]), [value("i32", 2)]);
+
+// ./test/core/gc/ref_test.wast:158
+assert_return(() => invoke($0, `ref_test_null_func`, [1]), [value("i32", 2)]);
+
+// ./test/core/gc/ref_test.wast:159
+assert_return(() => invoke($0, `ref_test_null_func`, [2]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_test.wast:161
+assert_return(() => invoke($0, `ref_test_func`, [0]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_test.wast:162
+assert_return(() => invoke($0, `ref_test_func`, [1]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_test.wast:163
+assert_return(() => invoke($0, `ref_test_func`, [2]), [value("i32", 2)]);
+
+// ./test/core/gc/ref_test.wast:165
+assert_return(() => invoke($0, `ref_test_null_extern`, [0]), [value("i32", 2)]);
+
+// ./test/core/gc/ref_test.wast:166
+assert_return(() => invoke($0, `ref_test_null_extern`, [1]), [value("i32", 2)]);
+
+// ./test/core/gc/ref_test.wast:167
+assert_return(() => invoke($0, `ref_test_null_extern`, [2]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_test.wast:168
+assert_return(() => invoke($0, `ref_test_null_extern`, [3]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_test.wast:169
+assert_return(() => invoke($0, `ref_test_null_extern`, [4]), [value("i32", 0)]);
+
+// ./test/core/gc/ref_test.wast:170
+assert_return(() => invoke($0, `ref_test_null_extern`, [5]), [value("i32", 2)]);
+
+// ./test/core/gc/ref_test.wast:172
+assert_return(() => invoke($0, `ref_test_extern`, [0]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_test.wast:173
+assert_return(() => invoke($0, `ref_test_extern`, [1]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_test.wast:174
+assert_return(() => invoke($0, `ref_test_extern`, [2]), [value("i32", 2)]);
+
+// ./test/core/gc/ref_test.wast:175
+assert_return(() => invoke($0, `ref_test_extern`, [3]), [value("i32", 2)]);
+
+// ./test/core/gc/ref_test.wast:176
+assert_return(() => invoke($0, `ref_test_extern`, [4]), [value("i32", 2)]);
+
+// ./test/core/gc/ref_test.wast:177
+assert_return(() => invoke($0, `ref_test_extern`, [5]), [value("i32", 1)]);
+
+// ./test/core/gc/ref_test.wast:182
+let $1 = instantiate(`(module
+ (type $$t0 (sub (struct)))
+ (type $$t1 (sub $$t0 (struct (field i32))))
+ (type $$t1' (sub $$t0 (struct (field i32))))
+ (type $$t2 (sub $$t1 (struct (field i32 i32))))
+ (type $$t2' (sub $$t1' (struct (field i32 i32))))
+ (type $$t3 (sub $$t0 (struct (field i32 i32))))
+ (type $$t0' (sub $$t0 (struct)))
+ (type $$t4 (sub $$t0' (struct (field i32 i32))))
+
+ (table 20 (ref null struct))
+
+ (func $$init
+ (table.set (i32.const 0) (struct.new_default $$t0))
+ (table.set (i32.const 10) (struct.new_default $$t0))
+ (table.set (i32.const 1) (struct.new_default $$t1))
+ (table.set (i32.const 11) (struct.new_default $$t1'))
+ (table.set (i32.const 2) (struct.new_default $$t2))
+ (table.set (i32.const 12) (struct.new_default $$t2'))
+ (table.set (i32.const 3) (struct.new_default $$t3))
+ (table.set (i32.const 4) (struct.new_default $$t4))
+ )
+
+ (func (export "test-sub")
+ (call $$init)
+ (block $$l
+ ;; must hold
+ (br_if $$l (i32.eqz (ref.test (ref null $$t0) (ref.null struct))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t0) (ref.null $$t0))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t0) (ref.null $$t1))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t0) (ref.null $$t2))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t0) (ref.null $$t3))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t0) (ref.null $$t4))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t0) (table.get (i32.const 0)))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t0) (table.get (i32.const 1)))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t0) (table.get (i32.const 2)))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t0) (table.get (i32.const 3)))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t0) (table.get (i32.const 4)))))
+
+ (br_if $$l (i32.eqz (ref.test (ref null $$t1) (ref.null struct))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t1) (ref.null $$t0))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t1) (ref.null $$t1))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t1) (ref.null $$t2))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t1) (ref.null $$t3))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t1) (ref.null $$t4))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t1) (table.get (i32.const 1)))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t1) (table.get (i32.const 2)))))
+
+ (br_if $$l (i32.eqz (ref.test (ref null $$t2) (ref.null struct))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t2) (ref.null $$t0))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t2) (ref.null $$t1))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t2) (ref.null $$t2))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t2) (ref.null $$t3))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t2) (ref.null $$t4))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t2) (table.get (i32.const 2)))))
+
+ (br_if $$l (i32.eqz (ref.test (ref null $$t3) (ref.null struct))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t3) (ref.null $$t0))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t3) (ref.null $$t1))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t3) (ref.null $$t2))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t3) (ref.null $$t3))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t3) (ref.null $$t4))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t3) (table.get (i32.const 3)))))
+
+ (br_if $$l (i32.eqz (ref.test (ref null $$t4) (ref.null struct))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t4) (ref.null $$t0))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t4) (ref.null $$t1))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t4) (ref.null $$t2))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t4) (ref.null $$t3))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t4) (ref.null $$t4))))
+ (br_if $$l (i32.eqz (ref.test (ref null $$t4) (table.get (i32.const 4)))))
+
+ (br_if $$l (i32.eqz (ref.test (ref $$t0) (table.get (i32.const 0)))))
+ (br_if $$l (i32.eqz (ref.test (ref $$t0) (table.get (i32.const 1)))))
+ (br_if $$l (i32.eqz (ref.test (ref $$t0) (table.get (i32.const 2)))))
+ (br_if $$l (i32.eqz (ref.test (ref $$t0) (table.get (i32.const 3)))))
+ (br_if $$l (i32.eqz (ref.test (ref $$t0) (table.get (i32.const 4)))))
+
+ (br_if $$l (i32.eqz (ref.test (ref $$t1) (table.get (i32.const 1)))))
+ (br_if $$l (i32.eqz (ref.test (ref $$t1) (table.get (i32.const 2)))))
+
+ (br_if $$l (i32.eqz (ref.test (ref $$t2) (table.get (i32.const 2)))))
+
+ (br_if $$l (i32.eqz (ref.test (ref $$t3) (table.get (i32.const 3)))))
+
+ (br_if $$l (i32.eqz (ref.test (ref $$t4) (table.get (i32.const 4)))))
+
+ ;; must not hold
+ (br_if $$l (ref.test (ref $$t0) (ref.null struct)))
+ (br_if $$l (ref.test (ref $$t1) (ref.null struct)))
+ (br_if $$l (ref.test (ref $$t2) (ref.null struct)))
+ (br_if $$l (ref.test (ref $$t3) (ref.null struct)))
+ (br_if $$l (ref.test (ref $$t4) (ref.null struct)))
+
+ (br_if $$l (ref.test (ref $$t1) (table.get (i32.const 0))))
+ (br_if $$l (ref.test (ref $$t1) (table.get (i32.const 3))))
+ (br_if $$l (ref.test (ref $$t1) (table.get (i32.const 4))))
+
+ (br_if $$l (ref.test (ref $$t2) (table.get (i32.const 0))))
+ (br_if $$l (ref.test (ref $$t2) (table.get (i32.const 1))))
+ (br_if $$l (ref.test (ref $$t2) (table.get (i32.const 3))))
+ (br_if $$l (ref.test (ref $$t2) (table.get (i32.const 4))))
+
+ (br_if $$l (ref.test (ref $$t3) (table.get (i32.const 0))))
+ (br_if $$l (ref.test (ref $$t3) (table.get (i32.const 1))))
+ (br_if $$l (ref.test (ref $$t3) (table.get (i32.const 2))))
+ (br_if $$l (ref.test (ref $$t3) (table.get (i32.const 4))))
+
+ (br_if $$l (ref.test (ref $$t4) (table.get (i32.const 0))))
+ (br_if $$l (ref.test (ref $$t4) (table.get (i32.const 1))))
+ (br_if $$l (ref.test (ref $$t4) (table.get (i32.const 2))))
+ (br_if $$l (ref.test (ref $$t4) (table.get (i32.const 3))))
+
+ (return)
+ )
+ (unreachable)
+ )
+
+ (func (export "test-canon")
+ (call $$init)
+ (block $$l
+ (br_if $$l (i32.eqz (ref.test (ref $$t0) (table.get (i32.const 0)))))
+ (br_if $$l (i32.eqz (ref.test (ref $$t0) (table.get (i32.const 1)))))
+ (br_if $$l (i32.eqz (ref.test (ref $$t0) (table.get (i32.const 2)))))
+ (br_if $$l (i32.eqz (ref.test (ref $$t0) (table.get (i32.const 3)))))
+ (br_if $$l (i32.eqz (ref.test (ref $$t0) (table.get (i32.const 4)))))
+
+ (br_if $$l (i32.eqz (ref.test (ref $$t0) (table.get (i32.const 10)))))
+ (br_if $$l (i32.eqz (ref.test (ref $$t0) (table.get (i32.const 11)))))
+ (br_if $$l (i32.eqz (ref.test (ref $$t0) (table.get (i32.const 12)))))
+
+ (br_if $$l (i32.eqz (ref.test (ref $$t1') (table.get (i32.const 1)))))
+ (br_if $$l (i32.eqz (ref.test (ref $$t1') (table.get (i32.const 2)))))
+
+ (br_if $$l (i32.eqz (ref.test (ref $$t1) (table.get (i32.const 11)))))
+ (br_if $$l (i32.eqz (ref.test (ref $$t1) (table.get (i32.const 12)))))
+
+ (br_if $$l (i32.eqz (ref.test (ref $$t2') (table.get (i32.const 2)))))
+
+ (br_if $$l (i32.eqz (ref.test (ref $$t2) (table.get (i32.const 12)))))
+
+ (return)
+ )
+ (unreachable)
+ )
+)`);
+
+// ./test/core/gc/ref_test.wast:329
+assert_return(() => invoke($1, `test-sub`, []), []);
+
+// ./test/core/gc/ref_test.wast:330
+assert_return(() => invoke($1, `test-canon`, []), []);
diff --git a/js/src/jit-test/tests/wasm/spec/gc/struct.wast.js b/js/src/jit-test/tests/wasm/spec/gc/struct.wast.js
new file mode 100644
index 0000000000..24b57b8466
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/spec/gc/struct.wast.js
@@ -0,0 +1,271 @@
+/* Copyright 2021 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ./test/core/gc/struct.wast
+
+// ./test/core/gc/struct.wast:3
+let $0 = instantiate(`(module
+ (type (struct))
+ (type (struct (field)))
+ (type (struct (field i8)))
+ (type (struct (field i8 i8 i8 i8)))
+ (type (struct (field $$x1 i32) (field $$y1 i32)))
+ (type (struct (field i8 i16 i32 i64 f32 f64 anyref funcref (ref 0) (ref null 1))))
+ (type (struct (field i32 i64 i8) (field) (field) (field (ref null i31) anyref)))
+ (type (struct (field $$x2 i32) (field f32 f64) (field $$y2 i32)))
+)`);
+
+// ./test/core/gc/struct.wast:15
+assert_malformed(
+ () => instantiate(`(type (struct (field $$x i32) (field $$x i32))) `),
+ `duplicate field`,
+);
+
+// ./test/core/gc/struct.wast:25
+let $1 = instantiate(`(module
+ (rec
+ (type $$s0 (struct (field (ref 0) (ref 1) (ref $$s0) (ref $$s1))))
+ (type $$s1 (struct (field (ref 0) (ref 1) (ref $$s0) (ref $$s1))))
+ )
+
+ (func (param (ref $$forward)))
+
+ (type $$forward (struct))
+)`);
+
+// ./test/core/gc/struct.wast:36
+assert_invalid(
+ () => instantiate(`(module (type (struct (field (ref 1)))))`),
+ `unknown type`,
+);
+
+// ./test/core/gc/struct.wast:40
+assert_invalid(
+ () => instantiate(`(module (type (struct (field (mut (ref 1))))))`),
+ `unknown type`,
+);
+
+// ./test/core/gc/struct.wast:48
+let $2 = instantiate(`(module
+ (type (struct (field $$x i32)))
+ (type $$t1 (struct (field i32) (field $$x f32)))
+ (type $$t2 (struct (field i32 i32) (field $$x i64)))
+
+ (func (param (ref 0)) (result i32) (struct.get 0 $$x (local.get 0)))
+ (func (param (ref $$t1)) (result f32) (struct.get 1 $$x (local.get 0)))
+ (func (param (ref $$t2)) (result i64) (struct.get $$t2 $$x (local.get 0)))
+)`);
+
+// ./test/core/gc/struct.wast:58
+assert_invalid(
+ () => instantiate(`(module
+ (type (struct (field $$x i64)))
+ (type $$t (struct (field $$x i32)))
+ (func (param (ref 0)) (result i32) (struct.get 0 $$x (local.get 0)))
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/gc/struct.wast:70
+let $3 = instantiate(`(module
+ (type $$vec (struct (field f32) (field $$y (mut f32)) (field $$z f32)))
+
+ (global (ref $$vec) (struct.new $$vec (f32.const 1) (f32.const 2) (f32.const 3)))
+ (global (ref $$vec) (struct.new_default $$vec))
+
+ (func (export "new") (result anyref)
+ (struct.new_default $$vec)
+ )
+
+ (func $$get_0_0 (param $$v (ref $$vec)) (result f32)
+ (struct.get 0 0 (local.get $$v))
+ )
+ (func (export "get_0_0") (result f32)
+ (call $$get_0_0 (struct.new_default $$vec))
+ )
+ (func $$get_vec_0 (param $$v (ref $$vec)) (result f32)
+ (struct.get $$vec 0 (local.get $$v))
+ )
+ (func (export "get_vec_0") (result f32)
+ (call $$get_vec_0 (struct.new_default $$vec))
+ )
+ (func $$get_0_y (param $$v (ref $$vec)) (result f32)
+ (struct.get 0 $$y (local.get $$v))
+ )
+ (func (export "get_0_y") (result f32)
+ (call $$get_0_y (struct.new_default $$vec))
+ )
+ (func $$get_vec_y (param $$v (ref $$vec)) (result f32)
+ (struct.get $$vec $$y (local.get $$v))
+ )
+ (func (export "get_vec_y") (result f32)
+ (call $$get_vec_y (struct.new_default $$vec))
+ )
+
+ (func $$set_get_y (param $$v (ref $$vec)) (param $$y f32) (result f32)
+ (struct.set $$vec $$y (local.get $$v) (local.get $$y))
+ (struct.get $$vec $$y (local.get $$v))
+ )
+ (func (export "set_get_y") (param $$y f32) (result f32)
+ (call $$set_get_y (struct.new_default $$vec) (local.get $$y))
+ )
+
+ (func $$set_get_1 (param $$v (ref $$vec)) (param $$y f32) (result f32)
+ (struct.set $$vec 1 (local.get $$v) (local.get $$y))
+ (struct.get $$vec $$y (local.get $$v))
+ )
+ (func (export "set_get_1") (param $$y f32) (result f32)
+ (call $$set_get_1 (struct.new_default $$vec) (local.get $$y))
+ )
+)`);
+
+// ./test/core/gc/struct.wast:122
+assert_return(() => invoke($3, `new`, []), [new RefWithType('structref')]);
+
+// ./test/core/gc/struct.wast:124
+assert_return(() => invoke($3, `get_0_0`, []), [value("f32", 0)]);
+
+// ./test/core/gc/struct.wast:125
+assert_return(() => invoke($3, `get_vec_0`, []), [value("f32", 0)]);
+
+// ./test/core/gc/struct.wast:126
+assert_return(() => invoke($3, `get_0_y`, []), [value("f32", 0)]);
+
+// ./test/core/gc/struct.wast:127
+assert_return(() => invoke($3, `get_vec_y`, []), [value("f32", 0)]);
+
+// ./test/core/gc/struct.wast:129
+assert_return(() => invoke($3, `set_get_y`, [value("f32", 7)]), [value("f32", 7)]);
+
+// ./test/core/gc/struct.wast:130
+assert_return(() => invoke($3, `set_get_1`, [value("f32", 7)]), [value("f32", 7)]);
+
+// ./test/core/gc/struct.wast:132
+assert_invalid(
+ () => instantiate(`(module
+ (type $$s (struct (field i64)))
+ (func (export "struct.set-immutable") (param $$s (ref $$s))
+ (struct.set $$s 0 (local.get $$s) (i64.const 1))
+ )
+ )`),
+ `field is immutable`,
+);
+
+// ./test/core/gc/struct.wast:145
+let $4 = instantiate(`(module
+ (type $$t (struct (field i32 (mut i32))))
+ (func (export "struct.get-null")
+ (local (ref null $$t)) (drop (struct.get $$t 1 (local.get 0)))
+ )
+ (func (export "struct.set-null")
+ (local (ref null $$t)) (struct.set $$t 1 (local.get 0) (i32.const 0))
+ )
+)`);
+
+// ./test/core/gc/struct.wast:155
+assert_trap(() => invoke($4, `struct.get-null`, []), `null structure reference`);
+
+// ./test/core/gc/struct.wast:156
+assert_trap(() => invoke($4, `struct.set-null`, []), `null structure reference`);
+
+// ./test/core/gc/struct.wast:160
+let $5 = instantiate(`(module
+ (type $$s (struct (field i8) (field (mut i8)) (field i16) (field (mut i16))))
+
+ (global (export "g0") (ref $$s) (struct.new $$s (i32.const 0) (i32.const 1) (i32.const 2) (i32.const 3)))
+ (global (export "g1") (ref $$s) (struct.new $$s (i32.const 254) (i32.const 255) (i32.const 65534) (i32.const 65535)))
+
+ (func (export "get_packed_g0_0") (result i32 i32)
+ (struct.get_s 0 0 (global.get 0))
+ (struct.get_u 0 0 (global.get 0))
+ )
+
+ (func (export "get_packed_g1_0") (result i32 i32)
+ (struct.get_s 0 0 (global.get 1))
+ (struct.get_u 0 0 (global.get 1))
+ )
+
+ (func (export "get_packed_g0_1") (result i32 i32)
+ (struct.get_s 0 1 (global.get 0))
+ (struct.get_u 0 1 (global.get 0))
+ )
+
+ (func (export "get_packed_g1_1") (result i32 i32)
+ (struct.get_s 0 1 (global.get 1))
+ (struct.get_u 0 1 (global.get 1))
+ )
+
+ (func (export "get_packed_g0_2") (result i32 i32)
+ (struct.get_s 0 2 (global.get 0))
+ (struct.get_u 0 2 (global.get 0))
+ )
+
+ (func (export "get_packed_g1_2") (result i32 i32)
+ (struct.get_s 0 2 (global.get 1))
+ (struct.get_u 0 2 (global.get 1))
+ )
+
+ (func (export "get_packed_g0_3") (result i32 i32)
+ (struct.get_s 0 3 (global.get 0))
+ (struct.get_u 0 3 (global.get 0))
+ )
+
+ (func (export "get_packed_g1_3") (result i32 i32)
+ (struct.get_s 0 3 (global.get 1))
+ (struct.get_u 0 3 (global.get 1))
+ )
+
+ (func (export "set_get_packed_g0_1") (param i32) (result i32 i32)
+ (struct.set 0 1 (global.get 0) (local.get 0))
+ (struct.get_s 0 1 (global.get 0))
+ (struct.get_u 0 1 (global.get 0))
+ )
+
+ (func (export "set_get_packed_g0_3") (param i32) (result i32 i32)
+ (struct.set 0 3 (global.get 0) (local.get 0))
+ (struct.get_s 0 3 (global.get 0))
+ (struct.get_u 0 3 (global.get 0))
+ )
+)`);
+
+// ./test/core/gc/struct.wast:219
+assert_return(() => invoke($5, `get_packed_g0_0`, []), [value("i32", 0), value("i32", 0)]);
+
+// ./test/core/gc/struct.wast:220
+assert_return(() => invoke($5, `get_packed_g1_0`, []), [value("i32", -2), value("i32", 254)]);
+
+// ./test/core/gc/struct.wast:221
+assert_return(() => invoke($5, `get_packed_g0_1`, []), [value("i32", 1), value("i32", 1)]);
+
+// ./test/core/gc/struct.wast:222
+assert_return(() => invoke($5, `get_packed_g1_1`, []), [value("i32", -1), value("i32", 255)]);
+
+// ./test/core/gc/struct.wast:223
+assert_return(() => invoke($5, `get_packed_g0_2`, []), [value("i32", 2), value("i32", 2)]);
+
+// ./test/core/gc/struct.wast:224
+assert_return(() => invoke($5, `get_packed_g1_2`, []), [value("i32", -2), value("i32", 65534)]);
+
+// ./test/core/gc/struct.wast:225
+assert_return(() => invoke($5, `get_packed_g0_3`, []), [value("i32", 3), value("i32", 3)]);
+
+// ./test/core/gc/struct.wast:226
+assert_return(() => invoke($5, `get_packed_g1_3`, []), [value("i32", -1), value("i32", 65535)]);
+
+// ./test/core/gc/struct.wast:228
+assert_return(() => invoke($5, `set_get_packed_g0_1`, [257]), [value("i32", 1), value("i32", 1)]);
+
+// ./test/core/gc/struct.wast:229
+assert_return(() => invoke($5, `set_get_packed_g0_3`, [257]), [value("i32", 257), value("i32", 257)]);
diff --git a/js/src/jit-test/tests/wasm/spec/gc/token.wast.js b/js/src/jit-test/tests/wasm/spec/gc/token.wast.js
new file mode 100644
index 0000000000..6d8f63faae
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/spec/gc/token.wast.js
@@ -0,0 +1,289 @@
+/* Copyright 2021 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ./test/core/token.wast
+
+// ./test/core/token.wast:3
+assert_malformed(() => instantiate(`(func (drop (i32.const0))) `), `unknown operator`);
+
+// ./test/core/token.wast:7
+assert_malformed(() => instantiate(`(func br 0drop) `), `unknown operator`);
+
+// ./test/core/token.wast:15
+let $0 = instantiate(`(module
+ (func(nop))
+)`);
+
+// ./test/core/token.wast:18
+let $1 = instantiate(`(module
+ (func (nop)nop)
+)`);
+
+// ./test/core/token.wast:21
+let $2 = instantiate(`(module
+ (func nop(nop))
+)`);
+
+// ./test/core/token.wast:24
+let $3 = instantiate(`(module
+ (func(nop)(nop))
+)`);
+
+// ./test/core/token.wast:27
+let $4 = instantiate(`(module
+ (func $$f(nop))
+)`);
+
+// ./test/core/token.wast:30
+let $5 = instantiate(`(module
+ (func br 0(nop))
+)`);
+
+// ./test/core/token.wast:33
+let $6 = instantiate(`(module
+ (table 1 funcref)
+ (func)
+ (elem (i32.const 0)0)
+)`);
+
+// ./test/core/token.wast:38
+let $7 = instantiate(`(module
+ (table 1 funcref)
+ (func $$f)
+ (elem (i32.const 0)$$f)
+)`);
+
+// ./test/core/token.wast:43
+let $8 = instantiate(`(module
+ (memory 1)
+ (data (i32.const 0)"a")
+)`);
+
+// ./test/core/token.wast:47
+let $9 = instantiate(`(module
+ (import "spectest" "print"(func))
+)`);
+
+// ./test/core/token.wast:54
+let $10 = instantiate(`(module
+ (func;;bla
+ )
+)`);
+
+// ./test/core/token.wast:58
+let $11 = instantiate(`(module
+ (func (nop);;bla
+ )
+)`);
+
+// ./test/core/token.wast:62
+let $12 = instantiate(`(module
+ (func nop;;bla
+ )
+)`);
+
+// ./test/core/token.wast:66
+let $13 = instantiate(`(module
+ (func $$f;;bla
+ )
+)`);
+
+// ./test/core/token.wast:70
+let $14 = instantiate(`(module
+ (func br 0;;bla
+ )
+)`);
+
+// ./test/core/token.wast:74
+let $15 = instantiate(`(module
+ (data "a";;bla
+ )
+)`);
+
+// ./test/core/token.wast:82
+let $16 = instantiate(`(module
+ (func (block $$l (i32.const 0) (br_table 0 $$l)))
+)`);
+
+// ./test/core/token.wast:85
+assert_malformed(
+ () => instantiate(`(func (block $$l (i32.const 0) (br_table 0$$l))) `),
+ `unknown operator`,
+);
+
+// ./test/core/token.wast:92
+let $17 = instantiate(`(module
+ (func (block $$l (i32.const 0) (br_table $$l 0)))
+)`);
+
+// ./test/core/token.wast:95
+assert_malformed(
+ () => instantiate(`(func (block $$l (i32.const 0) (br_table $$l0))) `),
+ `unknown label`,
+);
+
+// ./test/core/token.wast:102
+let $18 = instantiate(`(module
+ (func (block $$l (i32.const 0) (br_table $$l $$l)))
+)`);
+
+// ./test/core/token.wast:105
+assert_malformed(
+ () => instantiate(`(func (block $$l (i32.const 0) (br_table $$l$$l))) `),
+ `unknown label`,
+);
+
+// ./test/core/token.wast:112
+let $19 = instantiate(`(module
+ (func (block $$l0 (i32.const 0) (br_table $$l0)))
+)`);
+
+// ./test/core/token.wast:115
+let $20 = instantiate(`(module
+ (func (block $$l$$l (i32.const 0) (br_table $$l$$l)))
+)`);
+
+// ./test/core/token.wast:122
+let $21 = instantiate(`(module
+ (data "a")
+)`);
+
+// ./test/core/token.wast:125
+assert_malformed(() => instantiate(`(data"a") `), `unknown operator`);
+
+// ./test/core/token.wast:132
+let $22 = instantiate(`(module
+ (data $$l "a")
+)`);
+
+// ./test/core/token.wast:135
+assert_malformed(() => instantiate(`(data $$l"a") `), `unknown operator`);
+
+// ./test/core/token.wast:142
+let $23 = instantiate(`(module
+ (data $$l " a")
+)`);
+
+// ./test/core/token.wast:145
+assert_malformed(() => instantiate(`(data $$l" a") `), `unknown operator`);
+
+// ./test/core/token.wast:152
+let $24 = instantiate(`(module
+ (data $$l "a ")
+)`);
+
+// ./test/core/token.wast:155
+assert_malformed(() => instantiate(`(data $$l"a ") `), `unknown operator`);
+
+// ./test/core/token.wast:162
+let $25 = instantiate(`(module
+ (data $$l "a " "b")
+)`);
+
+// ./test/core/token.wast:165
+assert_malformed(() => instantiate(`(data $$l"a ""b") `), `unknown operator`);
+
+// ./test/core/token.wast:172
+let $26 = instantiate(`(module
+ (data $$l "\u{f61a}\u{f4a9}")
+)`);
+
+// ./test/core/token.wast:175
+assert_malformed(() => instantiate(`(data $$l"\u{f61a}\u{f4a9}") `), `unknown operator`);
+
+// ./test/core/token.wast:182
+let $27 = instantiate(`(module
+ (data $$l " \u{f61a}\u{f4a9}")
+)`);
+
+// ./test/core/token.wast:185
+assert_malformed(() => instantiate(`(data $$l" \u{f61a}\u{f4a9}") `), `unknown operator`);
+
+// ./test/core/token.wast:192
+let $28 = instantiate(`(module
+ (data $$l "\u{f61a}\u{f4a9} ")
+)`);
+
+// ./test/core/token.wast:195
+assert_malformed(() => instantiate(`(data $$l"\u{f61a}\u{f4a9} ") `), `unknown operator`);
+
+// ./test/core/token.wast:202
+let $29 = instantiate(`(module
+ (data "a" "b")
+)`);
+
+// ./test/core/token.wast:205
+assert_malformed(() => instantiate(`(data "a""b") `), `unknown operator`);
+
+// ./test/core/token.wast:212
+let $30 = instantiate(`(module
+ (data "a" " b")
+)`);
+
+// ./test/core/token.wast:215
+assert_malformed(() => instantiate(`(data "a"" b") `), `unknown operator`);
+
+// ./test/core/token.wast:222
+let $31 = instantiate(`(module
+ (data "a " "b")
+)`);
+
+// ./test/core/token.wast:225
+assert_malformed(() => instantiate(`(data "a ""b") `), `unknown operator`);
+
+// ./test/core/token.wast:232
+let $32 = instantiate(`(module
+ (data "\u{f61a}\u{f4a9}" "\u{f61a}\u{f4a9}")
+)`);
+
+// ./test/core/token.wast:235
+assert_malformed(
+ () => instantiate(`(data "\u{f61a}\u{f4a9}""\u{f61a}\u{f4a9}") `),
+ `unknown operator`,
+);
+
+// ./test/core/token.wast:242
+let $33 = instantiate(`(module
+ (data "\u{f61a}\u{f4a9}" " \u{f61a}\u{f4a9}")
+)`);
+
+// ./test/core/token.wast:245
+assert_malformed(
+ () => instantiate(`(data "\u{f61a}\u{f4a9}"" \u{f61a}\u{f4a9}") `),
+ `unknown operator`,
+);
+
+// ./test/core/token.wast:252
+let $34 = instantiate(`(module
+ (data "\u{f61a}\u{f4a9} " "\u{f61a}\u{f4a9}")
+)`);
+
+// ./test/core/token.wast:255
+assert_malformed(
+ () => instantiate(`(data "\u{f61a}\u{f4a9} ""\u{f61a}\u{f4a9}") `),
+ `unknown operator`,
+);
+
+// ./test/core/token.wast:263
+assert_malformed(() => instantiate(`(func "a"x) `), `unknown operator`);
+
+// ./test/core/token.wast:269
+assert_malformed(() => instantiate(`(func "a"0) `), `unknown operator`);
+
+// ./test/core/token.wast:275
+assert_malformed(() => instantiate(`(func 0"a") `), `unknown operator`);
+
+// ./test/core/token.wast:281
+assert_malformed(() => instantiate(`(func "a"$$x) `), `unknown operator`);
diff --git a/js/src/jit-test/tests/wasm/spec/gc/type-canon.wast.js b/js/src/jit-test/tests/wasm/spec/gc/type-canon.wast.js
new file mode 100644
index 0000000000..52d48143ee
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/spec/gc/type-canon.wast.js
@@ -0,0 +1,36 @@
+/* Copyright 2021 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ./test/core/type-canon.wast
+
+// ./test/core/type-canon.wast:1
+let $0 = instantiate(`(module
+ (rec
+ (type $$t1 (func (param i32 (ref $$t3))))
+ (type $$t2 (func (param i32 (ref $$t1))))
+ (type $$t3 (func (param i32 (ref $$t2))))
+ )
+)`);
+
+// ./test/core/type-canon.wast:9
+let $1 = instantiate(`(module
+ (rec
+ (type $$t0 (func (param i32 (ref $$t2) (ref $$t3))))
+ (type $$t1 (func (param i32 (ref $$t0) i32 (ref $$t4))))
+ (type $$t2 (func (param i32 (ref $$t2) (ref $$t1))))
+ (type $$t3 (func (param i32 (ref $$t2) i32 (ref $$t4))))
+ (type $$t4 (func (param (ref $$t0) (ref $$t2))))
+ )
+)`);
diff --git a/js/src/jit-test/tests/wasm/spec/gc/type-equivalence.wast.js b/js/src/jit-test/tests/wasm/spec/gc/type-equivalence.wast.js
new file mode 100644
index 0000000000..447729927e
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/spec/gc/type-equivalence.wast.js
@@ -0,0 +1,345 @@
+/* Copyright 2021 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ./test/core/type-equivalence.wast
+
+// ./test/core/type-equivalence.wast:5
+let $0 = instantiate(`(module
+ (type $$t1 (func (param f32 f32) (result f32)))
+ (type $$t2 (func (param $$x f32) (param $$y f32) (result f32)))
+
+ (func $$f1 (param $$r (ref $$t1)) (call $$f2 (local.get $$r)))
+ (func $$f2 (param $$r (ref $$t2)) (call $$f1 (local.get $$r)))
+)`);
+
+// ./test/core/type-equivalence.wast:16
+let $1 = instantiate(`(module
+ (type $$s0 (func (param i32) (result f32)))
+ (type $$s1 (func (param i32 (ref $$s0)) (result (ref $$s0))))
+ (type $$s2 (func (param i32 (ref $$s0)) (result (ref $$s0))))
+ (type $$t1 (func (param (ref $$s1)) (result (ref $$s2))))
+ (type $$t2 (func (param (ref $$s2)) (result (ref $$s1))))
+
+ (func $$f1 (param $$r (ref $$t1)) (call $$f2 (local.get $$r)))
+ (func $$f2 (param $$r (ref $$t2)) (call $$f1 (local.get $$r)))
+)`);
+
+// ./test/core/type-equivalence.wast:30
+let $2 = instantiate(`(module
+ (rec (type $$t1 (func (param i32 (ref $$t1)))))
+ (rec (type $$t2 (func (param i32 (ref $$t2)))))
+
+ (func $$f1 (param $$r (ref $$t1)) (call $$f2 (local.get $$r)))
+ (func $$f2 (param $$r (ref $$t2)) (call $$f1 (local.get $$r)))
+)`);
+
+// ./test/core/type-equivalence.wast:38
+let $3 = instantiate(`(module
+ (type $$t1 (func (param i32 (ref $$t1))))
+ (type $$t2 (func (param i32 (ref $$t2))))
+
+ (func $$f1 (param $$r (ref $$t1)) (call $$f2 (local.get $$r)))
+ (func $$f2 (param $$r (ref $$t2)) (call $$f1 (local.get $$r)))
+)`);
+
+// ./test/core/type-equivalence.wast:49
+let $4 = instantiate(`(module
+ (rec
+ (type $$t0 (func (param i32 (ref $$t1))))
+ (type $$t1 (func (param i32 (ref $$t0))))
+ )
+ (rec
+ (type $$t2 (func (param i32 (ref $$t3))))
+ (type $$t3 (func (param i32 (ref $$t2))))
+ )
+
+ (func $$f0 (param $$r (ref $$t0))
+ (call $$f2 (local.get $$r))
+ )
+ (func $$f1 (param $$r (ref $$t1))
+ (call $$f3 (local.get $$r))
+ )
+ (func $$f2 (param $$r (ref $$t2))
+ (call $$f0 (local.get $$r))
+ )
+ (func $$f3 (param $$r (ref $$t3))
+ (call $$f1 (local.get $$r))
+ )
+)`);
+
+// ./test/core/type-equivalence.wast:76
+assert_invalid(
+ () => instantiate(`(module
+ (type $$t1 (func (param (ref $$t2))))
+ (type $$t2 (func (param (ref $$t1))))
+ )`),
+ `unknown type`,
+);
+
+// ./test/core/type-equivalence.wast:89
+let $5 = instantiate(`(module
+ (type $$t1 (func (param f32 f32)))
+ (type $$t2 (func (param $$x f32) (param $$y f32)))
+
+ (func $$f1 (type $$t1))
+ (func $$f2 (type $$t2))
+ (table funcref (elem $$f1 $$f2))
+
+ (func (export "run")
+ (call_indirect (type $$t1) (f32.const 1) (f32.const 2) (i32.const 1))
+ (call_indirect (type $$t2) (f32.const 1) (f32.const 2) (i32.const 0))
+ )
+)`);
+
+// ./test/core/type-equivalence.wast:102
+assert_return(() => invoke($5, `run`, []), []);
+
+// ./test/core/type-equivalence.wast:107
+let $6 = instantiate(`(module
+ (type $$s0 (func (param i32)))
+ (type $$s1 (func (param i32 (ref $$s0))))
+ (type $$s2 (func (param i32 (ref $$s0))))
+ (type $$t1 (func (param (ref $$s1))))
+ (type $$t2 (func (param (ref $$s2))))
+
+ (func $$s1 (type $$s1))
+ (func $$s2 (type $$s2))
+ (func $$f1 (type $$t1))
+ (func $$f2 (type $$t2))
+ (table funcref (elem $$f1 $$f2 $$s1 $$s2))
+
+ (func (export "run")
+ (call_indirect (type $$t1) (ref.func $$s1) (i32.const 0))
+ (call_indirect (type $$t1) (ref.func $$s1) (i32.const 1))
+ (call_indirect (type $$t1) (ref.func $$s2) (i32.const 0))
+ (call_indirect (type $$t1) (ref.func $$s2) (i32.const 1))
+ (call_indirect (type $$t2) (ref.func $$s1) (i32.const 0))
+ (call_indirect (type $$t2) (ref.func $$s1) (i32.const 1))
+ (call_indirect (type $$t2) (ref.func $$s2) (i32.const 0))
+ (call_indirect (type $$t2) (ref.func $$s2) (i32.const 1))
+ )
+)`);
+
+// ./test/core/type-equivalence.wast:131
+assert_return(() => invoke($6, `run`, []), []);
+
+// ./test/core/type-equivalence.wast:136
+let $7 = instantiate(`(module
+ (rec (type $$t1 (func (result (ref null $$t1)))))
+ (rec (type $$t2 (func (result (ref null $$t2)))))
+
+ (func $$f1 (type $$t1) (ref.null $$t1))
+ (func $$f2 (type $$t2) (ref.null $$t2))
+ (table funcref (elem $$f1 $$f2))
+
+ (func (export "run")
+ (block (result (ref null $$t1)) (call_indirect (type $$t1) (i32.const 0)))
+ (block (result (ref null $$t1)) (call_indirect (type $$t2) (i32.const 0)))
+ (block (result (ref null $$t2)) (call_indirect (type $$t1) (i32.const 0)))
+ (block (result (ref null $$t2)) (call_indirect (type $$t2) (i32.const 0)))
+ (block (result (ref null $$t1)) (call_indirect (type $$t1) (i32.const 1)))
+ (block (result (ref null $$t1)) (call_indirect (type $$t2) (i32.const 1)))
+ (block (result (ref null $$t2)) (call_indirect (type $$t1) (i32.const 1)))
+ (block (result (ref null $$t2)) (call_indirect (type $$t2) (i32.const 1)))
+ (br 0)
+ )
+)`);
+
+// ./test/core/type-equivalence.wast:156
+assert_return(() => invoke($7, `run`, []), []);
+
+// ./test/core/type-equivalence.wast:161
+let $8 = instantiate(`(module
+ (rec
+ (type $$t1 (func (param i32 (ref $$t1))))
+ (type $$t2 (func (param i32 (ref $$t3))))
+ (type $$t3 (func (param i32 (ref $$t2))))
+ )
+
+ (rec
+ (type $$u1 (func (param i32 (ref $$u1))))
+ (type $$u2 (func (param i32 (ref $$u3))))
+ (type $$u3 (func (param i32 (ref $$u2))))
+ )
+
+ (func $$f1 (type $$t1))
+ (func $$f2 (type $$t2))
+ (func $$f3 (type $$t3))
+ (table funcref (elem $$f1 $$f2 $$f3))
+
+ (func (export "run")
+ (call_indirect (type $$t1) (i32.const 1) (ref.func $$f1) (i32.const 0))
+ (call_indirect (type $$t2) (i32.const 1) (ref.func $$f3) (i32.const 1))
+ (call_indirect (type $$t3) (i32.const 1) (ref.func $$f2) (i32.const 2))
+ (call_indirect (type $$u1) (i32.const 1) (ref.func $$f1) (i32.const 0))
+ (call_indirect (type $$u2) (i32.const 1) (ref.func $$f3) (i32.const 1))
+ (call_indirect (type $$u3) (i32.const 1) (ref.func $$f2) (i32.const 2))
+ )
+)`);
+
+// ./test/core/type-equivalence.wast:188
+assert_return(() => invoke($8, `run`, []), []);
+
+// ./test/core/type-equivalence.wast:195
+let $9 = instantiate(`(module
+ (type $$t1 (func (param f32 f32) (result f32)))
+ (func (export "f") (param (ref $$t1)))
+)`);
+
+// ./test/core/type-equivalence.wast:199
+register($9, `M`);
+
+// ./test/core/type-equivalence.wast:200
+let $10 = instantiate(`(module
+ (type $$t2 (func (param $$x f32) (param $$y f32) (result f32)))
+ (func (import "M" "f") (param (ref $$t2)))
+)`);
+
+// ./test/core/type-equivalence.wast:208
+let $11 = instantiate(`(module
+ (type $$s0 (func (param i32) (result f32)))
+ (type $$s1 (func (param i32 (ref $$s0)) (result (ref $$s0))))
+ (type $$s2 (func (param i32 (ref $$s0)) (result (ref $$s0))))
+ (type $$t1 (func (param (ref $$s1)) (result (ref $$s2))))
+ (type $$t2 (func (param (ref $$s2)) (result (ref $$s1))))
+ (func (export "f1") (param (ref $$t1)))
+ (func (export "f2") (param (ref $$t1)))
+)`);
+
+// ./test/core/type-equivalence.wast:217
+register($11, `N`);
+
+// ./test/core/type-equivalence.wast:218
+let $12 = instantiate(`(module
+ (type $$s0 (func (param i32) (result f32)))
+ (type $$s1 (func (param i32 (ref $$s0)) (result (ref $$s0))))
+ (type $$s2 (func (param i32 (ref $$s0)) (result (ref $$s0))))
+ (type $$t1 (func (param (ref $$s1)) (result (ref $$s2))))
+ (type $$t2 (func (param (ref $$s2)) (result (ref $$s1))))
+ (func (import "N" "f1") (param (ref $$t1)))
+ (func (import "N" "f1") (param (ref $$t2)))
+ (func (import "N" "f2") (param (ref $$t1)))
+ (func (import "N" "f2") (param (ref $$t1)))
+)`);
+
+// ./test/core/type-equivalence.wast:233
+let $13 = instantiate(`(module
+ (rec (type $$t1 (func (param i32 (ref $$t1)))))
+ (func (export "f") (param (ref $$t1)))
+)`);
+
+// ./test/core/type-equivalence.wast:237
+register($13, `Mr1`);
+
+// ./test/core/type-equivalence.wast:238
+let $14 = instantiate(`(module
+ (rec (type $$t2 (func (param i32 (ref $$t2)))))
+ (func (import "Mr1" "f") (param (ref $$t2)))
+)`);
+
+// ./test/core/type-equivalence.wast:246
+let $15 = instantiate(`(module
+ (rec
+ (type $$t1 (func (param i32 (ref $$t1))))
+ (type $$t2 (func (param i32 (ref $$t3))))
+ (type $$t3 (func (param i32 (ref $$t2))))
+ )
+ (func (export "f1") (param (ref $$t1)))
+ (func (export "f2") (param (ref $$t2)))
+ (func (export "f3") (param (ref $$t3)))
+)`);
+
+// ./test/core/type-equivalence.wast:256
+register($15, `Mr2`);
+
+// ./test/core/type-equivalence.wast:257
+let $16 = instantiate(`(module
+ (rec
+ (type $$t1 (func (param i32 (ref $$t1))))
+ (type $$t2 (func (param i32 (ref $$t3))))
+ (type $$t3 (func (param i32 (ref $$t2))))
+ )
+ (func (import "Mr2" "f1") (param (ref $$t1)))
+ (func (import "Mr2" "f2") (param (ref $$t2)))
+ (func (import "Mr2" "f3") (param (ref $$t3)))
+)`);
+
+// ./test/core/type-equivalence.wast:268
+let $17 = instantiate(`(module
+ (rec
+ (type $$t1 (func (param i32 (ref $$t3))))
+ (type $$t2 (func (param i32 (ref $$t1))))
+ (type $$t3 (func (param i32 (ref $$t2))))
+ )
+ (func (export "f1") (param (ref $$t1)))
+ (func (export "f2") (param (ref $$t2)))
+ (func (export "f3") (param (ref $$t3)))
+)`);
+
+// ./test/core/type-equivalence.wast:278
+register($17, `Mr3`);
+
+// ./test/core/type-equivalence.wast:279
+let $18 = instantiate(`(module
+ (rec
+ (type $$t1 (func (param i32 (ref $$t3))))
+ (type $$t2 (func (param i32 (ref $$t1))))
+ (type $$t3 (func (param i32 (ref $$t2))))
+ )
+ (func (import "Mr3" "f1") (param (ref $$t1)))
+ (func (import "Mr3" "f2") (param (ref $$t2)))
+ (func (import "Mr3" "f3") (param (ref $$t3)))
+)`);
+
+// ./test/core/type-equivalence.wast:290
+let $19 = instantiate(`(module
+ (rec
+ (type $$t1 (func (param i32 (ref $$u1))))
+ (type $$u1 (func (param f32 (ref $$t1))))
+ )
+
+ (rec
+ (type $$t2 (func (param i32 (ref $$u3))))
+ (type $$u2 (func (param f32 (ref $$t3))))
+ (type $$t3 (func (param i32 (ref $$u2))))
+ (type $$u3 (func (param f32 (ref $$t2))))
+ )
+
+ (func (export "f1") (param (ref $$t1)))
+ (func (export "f2") (param (ref $$t2)))
+ (func (export "f3") (param (ref $$t3)))
+)`);
+
+// ./test/core/type-equivalence.wast:307
+register($19, `Mr4`);
+
+// ./test/core/type-equivalence.wast:308
+let $20 = instantiate(`(module
+ (rec
+ (type $$t1 (func (param i32 (ref $$u1))))
+ (type $$u1 (func (param f32 (ref $$t1))))
+ )
+
+ (rec
+ (type $$t2 (func (param i32 (ref $$u3))))
+ (type $$u2 (func (param f32 (ref $$t3))))
+ (type $$t3 (func (param i32 (ref $$u2))))
+ (type $$u3 (func (param f32 (ref $$t2))))
+ )
+
+ (func (import "Mr4" "f1") (param (ref $$t1)))
+ (func (import "Mr4" "f2") (param (ref $$t2)))
+ (func (import "Mr4" "f3") (param (ref $$t3)))
+)`);
diff --git a/js/src/jit-test/tests/wasm/spec/gc/type-rec.wast.js b/js/src/jit-test/tests/wasm/spec/gc/type-rec.wast.js
new file mode 100644
index 0000000000..8bf18cb6e5
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/spec/gc/type-rec.wast.js
@@ -0,0 +1,189 @@
+/* Copyright 2021 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ./test/core/type-rec.wast
+
+// ./test/core/type-rec.wast:3
+let $0 = instantiate(`(module
+ (rec (type $$f1 (func)) (type (struct (field (ref $$f1)))))
+ (rec (type $$f2 (func)) (type (struct (field (ref $$f2)))))
+ (func $$f (type $$f2))
+ (global (ref $$f1) (ref.func $$f))
+)`);
+
+// ./test/core/type-rec.wast:10
+let $1 = instantiate(`(module
+ (rec (type $$f1 (func)) (type (struct (field (ref $$f1)))))
+ (rec (type $$f2 (func)) (type (struct (field (ref $$f2)))))
+ (rec
+ (type $$g1 (func))
+ (type (struct (field (ref $$f1) (ref $$f1) (ref $$f2) (ref $$f2) (ref $$g1))))
+ )
+ (rec
+ (type $$g2 (func))
+ (type (struct (field (ref $$f1) (ref $$f2) (ref $$f1) (ref $$f2) (ref $$g2))))
+ )
+ (func $$g (type $$g2))
+ (global (ref $$g1) (ref.func $$g))
+)`);
+
+// ./test/core/type-rec.wast:25
+assert_invalid(
+ () => instantiate(`(module
+ (rec (type $$f1 (func)) (type (struct (field (ref $$f1)))))
+ (rec (type $$f2 (func)) (type (struct (field (ref $$f1)))))
+ (func $$f (type $$f2))
+ (global (ref $$f1) (ref.func $$f))
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/type-rec.wast:35
+assert_invalid(
+ () => instantiate(`(module
+ (rec (type $$f0 (func)) (type (struct (field (ref $$f0)))))
+ (rec (type $$f1 (func)) (type (struct (field (ref $$f0)))))
+ (rec (type $$f2 (func)) (type (struct (field (ref $$f1)))))
+ (func $$f (type $$f2))
+ (global (ref $$f1) (ref.func $$f))
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/type-rec.wast:46
+assert_invalid(
+ () => instantiate(`(module
+ (rec (type $$f1 (func)) (type (struct)))
+ (rec (type (struct)) (type $$f2 (func)))
+ (global (ref $$f1) (ref.func $$f))
+ (func $$f (type $$f2))
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/type-rec.wast:56
+assert_invalid(
+ () => instantiate(`(module
+ (rec (type $$f1 (func)) (type (struct)))
+ (rec (type $$f2 (func)) (type (struct)) (type (func)))
+ (global (ref $$f1) (ref.func $$f))
+ (func $$f (type $$f2))
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/type-rec.wast:69
+let $2 = instantiate(`(module $$M
+ (rec (type $$f1 (func)) (type (struct)))
+ (func (export "f") (type $$f1))
+)`);
+register($2, `M`);
+
+// ./test/core/type-rec.wast:73
+register(`M`, `M`);
+
+// ./test/core/type-rec.wast:75
+let $3 = instantiate(`(module
+ (rec (type $$f2 (func)) (type (struct)))
+ (func (import "M" "f") (type $$f2))
+)`);
+
+// ./test/core/type-rec.wast:80
+assert_unlinkable(
+ () => instantiate(`(module
+ (rec (type (struct)) (type $$f2 (func)))
+ (func (import "M" "f") (type $$f2))
+ )`),
+ `incompatible import type`,
+);
+
+// ./test/core/type-rec.wast:88
+assert_unlinkable(
+ () => instantiate(`(module
+ (rec (type $$f2 (func)))
+ (func (import "M" "f") (type $$f2))
+ )`),
+ `incompatible import type`,
+);
+
+// ./test/core/type-rec.wast:99
+let $4 = instantiate(`(module
+ (rec (type $$f1 (func)) (type (struct)))
+ (rec (type $$f2 (func)) (type (struct)))
+ (table funcref (elem $$f1))
+ (func $$f1 (type $$f1))
+ (func (export "run") (call_indirect (type $$f2) (i32.const 0)))
+)`);
+
+// ./test/core/type-rec.wast:106
+assert_return(() => invoke($4, `run`, []), []);
+
+// ./test/core/type-rec.wast:108
+let $5 = instantiate(`(module
+ (rec (type $$f1 (func)) (type (struct)))
+ (rec (type (struct)) (type $$f2 (func)))
+ (table funcref (elem $$f1))
+ (func $$f1 (type $$f1))
+ (func (export "run") (call_indirect (type $$f2) (i32.const 0)))
+)`);
+
+// ./test/core/type-rec.wast:115
+assert_trap(() => invoke($5, `run`, []), `indirect call type mismatch`);
+
+// ./test/core/type-rec.wast:117
+let $6 = instantiate(`(module
+ (rec (type $$f1 (func)) (type (struct)))
+ (rec (type $$f2 (func)))
+ (table funcref (elem $$f1))
+ (func $$f1 (type $$f1))
+ (func (export "run") (call_indirect (type $$f2) (i32.const 0)))
+)`);
+
+// ./test/core/type-rec.wast:124
+assert_trap(() => invoke($6, `run`, []), `indirect call type mismatch`);
+
+// ./test/core/type-rec.wast:129
+let $7 = instantiate(`(module
+ (rec (type $$s (struct)))
+ (rec (type $$t (func (param (ref $$s)))))
+ (func $$f (param (ref $$s))) ;; okay, type is equivalent to $$t
+ (global (ref $$t) (ref.func $$f))
+)`);
+
+// ./test/core/type-rec.wast:136
+assert_invalid(
+ () => instantiate(`(module
+ (rec
+ (type $$s (struct))
+ (type $$t (func (param (ref $$s))))
+ )
+ (func $$f (param (ref $$s))) ;; type is not equivalent to $$t
+ (global (ref $$t) (ref.func $$f))
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/type-rec.wast:148
+assert_invalid(
+ () => instantiate(`(module
+ (rec
+ (type (struct))
+ (type $$t (func))
+ )
+ (func $$f) ;; type is not equivalent to $$t
+ (global (ref $$t) (ref.func $$f))
+ )`),
+ `type mismatch`,
+);
diff --git a/js/src/jit-test/tests/wasm/spec/gc/type-subtyping.wast.js b/js/src/jit-test/tests/wasm/spec/gc/type-subtyping.wast.js
new file mode 100644
index 0000000000..474789c145
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/spec/gc/type-subtyping.wast.js
@@ -0,0 +1,943 @@
+/* Copyright 2021 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ./test/core/gc/type-subtyping.wast
+
+// ./test/core/gc/type-subtyping.wast:3
+let $0 = instantiate(`(module
+ (type $$e0 (sub (array i32)))
+ (type $$e1 (sub $$e0 (array i32)))
+
+ (type $$e2 (sub (array anyref)))
+ (type $$e3 (sub (array (ref null $$e0))))
+ (type $$e4 (sub (array (ref $$e1))))
+
+ (type $$m1 (sub (array (mut i32))))
+ (type $$m2 (sub $$m1 (array (mut i32))))
+)`);
+
+// ./test/core/gc/type-subtyping.wast:15
+let $1 = instantiate(`(module
+ (type $$e0 (sub (struct)))
+ (type $$e1 (sub $$e0 (struct)))
+ (type $$e2 (sub $$e1 (struct (field i32))))
+ (type $$e3 (sub $$e2 (struct (field i32 (ref null $$e0)))))
+ (type $$e4 (sub $$e3 (struct (field i32 (ref $$e0) (mut i64)))))
+ (type $$e5 (sub $$e4 (struct (field i32 (ref $$e1) (mut i64)))))
+)`);
+
+// ./test/core/gc/type-subtyping.wast:24
+let $2 = instantiate(`(module
+ (type $$s (sub (struct)))
+ (type $$s' (sub $$s (struct)))
+
+ (type $$f1 (sub (func (param (ref $$s')) (result anyref))))
+ (type $$f2 (sub $$f1 (func (param (ref $$s)) (result (ref any)))))
+ (type $$f3 (sub $$f2 (func (param (ref null $$s)) (result (ref $$s)))))
+ (type $$f4 (sub $$f3 (func (param (ref null struct)) (result (ref $$s')))))
+)`);
+
+// ./test/core/gc/type-subtyping.wast:37
+let $3 = instantiate(`(module
+ (type $$t (sub (struct (field anyref))))
+ (rec (type $$r (sub $$t (struct (field (ref $$r))))))
+ (type $$t' (sub $$r (struct (field (ref $$r) i32))))
+)`);
+
+// ./test/core/gc/type-subtyping.wast:43
+let $4 = instantiate(`(module
+ (rec
+ (type $$r1 (sub (struct (field i32 (ref $$r1)))))
+ )
+ (rec
+ (type $$r2 (sub $$r1 (struct (field i32 (ref $$r3)))))
+ (type $$r3 (sub $$r1 (struct (field i32 (ref $$r2)))))
+ )
+)`);
+
+// ./test/core/gc/type-subtyping.wast:53
+let $5 = instantiate(`(module
+ (rec
+ (type $$a1 (sub (struct (field i32 (ref $$a2)))))
+ (type $$a2 (sub (struct (field i64 (ref $$a1)))))
+ )
+ (rec
+ (type $$b1 (sub $$a2 (struct (field i64 (ref $$a1) i32))))
+ (type $$b2 (sub $$a1 (struct (field i32 (ref $$a2) i32))))
+ (type $$b3 (sub $$a2 (struct (field i64 (ref $$b2) i32))))
+ )
+)`);
+
+// ./test/core/gc/type-subtyping.wast:68
+let $6 = instantiate(`(module
+ (rec
+ (type $$t1 (sub (func (param i32 (ref $$t3)))))
+ (type $$t2 (sub $$t1 (func (param i32 (ref $$t2)))))
+ (type $$t3 (sub $$t2 (func (param i32 (ref $$t1)))))
+ )
+
+ (func $$f1 (param $$r (ref $$t1))
+ (call $$f1 (local.get $$r))
+ )
+ (func $$f2 (param $$r (ref $$t2))
+ (call $$f1 (local.get $$r))
+ (call $$f2 (local.get $$r))
+ )
+ (func $$f3 (param $$r (ref $$t3))
+ (call $$f1 (local.get $$r))
+ (call $$f2 (local.get $$r))
+ (call $$f3 (local.get $$r))
+ )
+)`);
+
+// ./test/core/gc/type-subtyping.wast:89
+let $7 = instantiate(`(module
+ (rec
+ (type $$t1 (sub (func (result i32 (ref $$u1)))))
+ (type $$u1 (sub (func (result f32 (ref $$t1)))))
+ )
+
+ (rec
+ (type $$t2 (sub $$t1 (func (result i32 (ref $$u3)))))
+ (type $$u2 (sub $$u1 (func (result f32 (ref $$t3)))))
+ (type $$t3 (sub $$t1 (func (result i32 (ref $$u2)))))
+ (type $$u3 (sub $$u1 (func (result f32 (ref $$t2)))))
+ )
+
+ (func $$f1 (param $$r (ref $$t1))
+ (call $$f1 (local.get $$r))
+ )
+ (func $$f2 (param $$r (ref $$t2))
+ (call $$f1 (local.get $$r))
+ (call $$f2 (local.get $$r))
+ )
+ (func $$f3 (param $$r (ref $$t3))
+ (call $$f1 (local.get $$r))
+ (call $$f3 (local.get $$r))
+ )
+)`);
+
+// ./test/core/gc/type-subtyping.wast:115
+let $8 = instantiate(`(module
+ (rec (type $$f1 (sub (func))) (type (struct (field (ref $$f1)))))
+ (rec (type $$f2 (sub (func))) (type (struct (field (ref $$f2)))))
+ (rec (type $$g1 (sub $$f1 (func))) (type (struct)))
+ (rec (type $$g2 (sub $$f2 (func))) (type (struct)))
+ (func $$g (type $$g2))
+ (global (ref $$g1) (ref.func $$g))
+)`);
+
+// ./test/core/gc/type-subtyping.wast:124
+let $9 = instantiate(`(module
+ (rec (type $$f1 (sub (func))) (type $$s1 (sub (struct (field (ref $$f1))))))
+ (rec (type $$f2 (sub (func))) (type $$s2 (sub (struct (field (ref $$f2))))))
+ (rec
+ (type $$g1 (sub $$f1 (func)))
+ (type (sub $$s1 (struct (field (ref $$f1) (ref $$f1) (ref $$f2) (ref $$f2) (ref $$g1)))))
+ )
+ (rec
+ (type $$g2 (sub $$f2 (func)))
+ (type (sub $$s2 (struct (field (ref $$f1) (ref $$f2) (ref $$f1) (ref $$f2) (ref $$g2)))))
+ )
+ (func $$g (type $$g2))
+ (global (ref $$g1) (ref.func $$g))
+)`);
+
+// ./test/core/gc/type-subtyping.wast:139
+assert_invalid(
+ () => instantiate(`(module
+ (rec (type $$f1 (sub (func))) (type (struct (field (ref $$f1)))))
+ (rec (type $$f2 (sub (func))) (type (struct (field (ref $$f1)))))
+ (rec (type $$g1 (sub $$f1 (func))) (type (struct)))
+ (rec (type $$g2 (sub $$f2 (func))) (type (struct)))
+ (func $$g (type $$g2))
+ (global (ref $$g1) (ref.func $$g))
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/gc/type-subtyping.wast:151
+let $10 = instantiate(`(module
+ (rec (type $$f1 (sub (func))) (type (struct (field (ref $$f1)))))
+ (rec (type $$f2 (sub (func))) (type (struct (field (ref $$f2)))))
+ (rec (type $$g (sub $$f1 (func))) (type (struct)))
+ (func $$g (type $$g))
+ (global (ref $$f1) (ref.func $$g))
+)`);
+
+// ./test/core/gc/type-subtyping.wast:159
+let $11 = instantiate(`(module
+ (rec (type $$f1 (sub (func))) (type $$s1 (sub (struct (field (ref $$f1))))))
+ (rec (type $$f2 (sub (func))) (type $$s2 (sub (struct (field (ref $$f2))))))
+ (rec
+ (type $$g1 (sub $$f1 (func)))
+ (type (sub $$s1 (struct (field (ref $$f1) (ref $$f1) (ref $$f2) (ref $$f2) (ref $$g1)))))
+ )
+ (rec
+ (type $$g2 (sub $$f2 (func)))
+ (type (sub $$s2 (struct (field (ref $$f1) (ref $$f2) (ref $$f1) (ref $$f2) (ref $$g2)))))
+ )
+ (rec (type $$h (sub $$g2 (func))) (type (struct)))
+ (func $$h (type $$h))
+ (global (ref $$f1) (ref.func $$h))
+ (global (ref $$g1) (ref.func $$h))
+)`);
+
+// ./test/core/gc/type-subtyping.wast:177
+let $12 = instantiate(`(module
+ (rec (type $$f11 (sub (func (result (ref func))))) (type $$f12 (sub $$f11 (func (result (ref $$f11))))))
+ (rec (type $$f21 (sub (func (result (ref func))))) (type $$f22 (sub $$f21 (func (result (ref $$f21))))))
+ (func $$f11 (type $$f11) (unreachable))
+ (func $$f12 (type $$f12) (unreachable))
+ (global (ref $$f11) (ref.func $$f11))
+ (global (ref $$f21) (ref.func $$f11))
+ (global (ref $$f12) (ref.func $$f12))
+ (global (ref $$f22) (ref.func $$f12))
+)`);
+
+// ./test/core/gc/type-subtyping.wast:188
+let $13 = instantiate(`(module
+ (rec (type $$f11 (sub (func (result (ref func))))) (type $$f12 (sub $$f11 (func (result (ref $$f11))))))
+ (rec (type $$f21 (sub (func (result (ref func))))) (type $$f22 (sub $$f21 (func (result (ref $$f21))))))
+ (rec (type $$g11 (sub $$f11 (func (result (ref func))))) (type $$g12 (sub $$g11 (func (result (ref $$g11))))))
+ (rec (type $$g21 (sub $$f21 (func (result (ref func))))) (type $$g22 (sub $$g21 (func (result (ref $$g21))))))
+ (func $$g11 (type $$g11) (unreachable))
+ (func $$g12 (type $$g12) (unreachable))
+ (global (ref $$f11) (ref.func $$g11))
+ (global (ref $$f21) (ref.func $$g11))
+ (global (ref $$f11) (ref.func $$g12))
+ (global (ref $$f21) (ref.func $$g12))
+ (global (ref $$g11) (ref.func $$g11))
+ (global (ref $$g21) (ref.func $$g11))
+ (global (ref $$g12) (ref.func $$g12))
+ (global (ref $$g22) (ref.func $$g12))
+)`);
+
+// ./test/core/gc/type-subtyping.wast:205
+assert_invalid(
+ () => instantiate(`(module
+ (rec (type $$f11 (sub (func))) (type $$f12 (sub $$f11 (func))))
+ (rec (type $$f21 (sub (func))) (type $$f22 (sub $$f11 (func))))
+ (func $$f (type $$f21))
+ (global (ref $$f11) (ref.func $$f))
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/gc/type-subtyping.wast:215
+assert_invalid(
+ () => instantiate(`(module
+ (rec (type $$f01 (sub (func))) (type $$f02 (sub $$f01 (func))))
+ (rec (type $$f11 (sub (func))) (type $$f12 (sub $$f01 (func))))
+ (rec (type $$f21 (sub (func))) (type $$f22 (sub $$f11 (func))))
+ (func $$f (type $$f21))
+ (global (ref $$f11) (ref.func $$f))
+ )`),
+ `type mismatch`,
+);
+
+// ./test/core/gc/type-subtyping.wast:229
+let $14 = instantiate(`(module
+ (type $$t0 (sub (func (result (ref null func)))))
+ (rec (type $$t1 (sub $$t0 (func (result (ref null $$t1))))))
+ (rec (type $$t2 (sub $$t1 (func (result (ref null $$t2))))))
+
+ (func $$f0 (type $$t0) (ref.null func))
+ (func $$f1 (type $$t1) (ref.null $$t1))
+ (func $$f2 (type $$t2) (ref.null $$t2))
+ (table funcref (elem $$f0 $$f1 $$f2))
+
+ (func (export "run")
+ (block (result (ref null func)) (call_indirect (type $$t0) (i32.const 0)))
+ (block (result (ref null func)) (call_indirect (type $$t0) (i32.const 1)))
+ (block (result (ref null func)) (call_indirect (type $$t0) (i32.const 2)))
+ (block (result (ref null $$t1)) (call_indirect (type $$t1) (i32.const 1)))
+ (block (result (ref null $$t1)) (call_indirect (type $$t1) (i32.const 2)))
+ (block (result (ref null $$t2)) (call_indirect (type $$t2) (i32.const 2)))
+
+ (block (result (ref null $$t0)) (ref.cast (ref $$t0) (table.get (i32.const 0))))
+ (block (result (ref null $$t0)) (ref.cast (ref $$t0) (table.get (i32.const 1))))
+ (block (result (ref null $$t0)) (ref.cast (ref $$t0) (table.get (i32.const 2))))
+ (block (result (ref null $$t1)) (ref.cast (ref $$t1) (table.get (i32.const 1))))
+ (block (result (ref null $$t1)) (ref.cast (ref $$t1) (table.get (i32.const 2))))
+ (block (result (ref null $$t2)) (ref.cast (ref $$t2) (table.get (i32.const 2))))
+ (br 0)
+ )
+
+ (func (export "fail1")
+ (block (result (ref null $$t1)) (call_indirect (type $$t1) (i32.const 0)))
+ (br 0)
+ )
+ (func (export "fail2")
+ (block (result (ref null $$t1)) (call_indirect (type $$t2) (i32.const 0)))
+ (br 0)
+ )
+ (func (export "fail3")
+ (block (result (ref null $$t1)) (call_indirect (type $$t2) (i32.const 1)))
+ (br 0)
+ )
+
+ (func (export "fail4")
+ (ref.cast (ref $$t1) (table.get (i32.const 0)))
+ (br 0)
+ )
+ (func (export "fail5")
+ (ref.cast (ref $$t2) (table.get (i32.const 0)))
+ (br 0)
+ )
+ (func (export "fail6")
+ (ref.cast (ref $$t2) (table.get (i32.const 1)))
+ (br 0)
+ )
+)`);
+
+// ./test/core/gc/type-subtyping.wast:282
+assert_return(() => invoke($14, `run`, []), []);
+
+// ./test/core/gc/type-subtyping.wast:283
+assert_trap(() => invoke($14, `fail1`, []), `indirect call`);
+
+// ./test/core/gc/type-subtyping.wast:284
+assert_trap(() => invoke($14, `fail2`, []), `indirect call`);
+
+// ./test/core/gc/type-subtyping.wast:285
+assert_trap(() => invoke($14, `fail3`, []), `indirect call`);
+
+// ./test/core/gc/type-subtyping.wast:286
+assert_trap(() => invoke($14, `fail4`, []), `cast`);
+
+// ./test/core/gc/type-subtyping.wast:287
+assert_trap(() => invoke($14, `fail5`, []), `cast`);
+
+// ./test/core/gc/type-subtyping.wast:288
+assert_trap(() => invoke($14, `fail6`, []), `cast`);
+
+// ./test/core/gc/type-subtyping.wast:290
+let $15 = instantiate(`(module
+ (type $$t1 (sub (func)))
+ (type $$t2 (sub final (func)))
+
+ (func $$f1 (type $$t1))
+ (func $$f2 (type $$t2))
+ (table funcref (elem $$f1 $$f2))
+
+ (func (export "fail1")
+ (block (call_indirect (type $$t1) (i32.const 1)))
+ )
+ (func (export "fail2")
+ (block (call_indirect (type $$t2) (i32.const 0)))
+ )
+
+ (func (export "fail3")
+ (ref.cast (ref $$t1) (table.get (i32.const 1)))
+ (drop)
+ )
+ (func (export "fail4")
+ (ref.cast (ref $$t2) (table.get (i32.const 0)))
+ (drop)
+ )
+)`);
+
+// ./test/core/gc/type-subtyping.wast:314
+assert_trap(() => invoke($15, `fail1`, []), `indirect call`);
+
+// ./test/core/gc/type-subtyping.wast:315
+assert_trap(() => invoke($15, `fail2`, []), `indirect call`);
+
+// ./test/core/gc/type-subtyping.wast:316
+assert_trap(() => invoke($15, `fail3`, []), `cast`);
+
+// ./test/core/gc/type-subtyping.wast:317
+assert_trap(() => invoke($15, `fail4`, []), `cast`);
+
+// ./test/core/gc/type-subtyping.wast:320
+let $16 = instantiate(`(module
+ (rec (type $$f1 (sub (func))) (type (struct (field (ref $$f1)))))
+ (rec (type $$f2 (sub (func))) (type (struct (field (ref $$f2)))))
+ (rec (type $$g1 (sub $$f1 (func))) (type (struct)))
+ (rec (type $$g2 (sub $$f2 (func))) (type (struct)))
+ (func $$g (type $$g2)) (elem declare func $$g)
+ (func (export "run") (result i32)
+ (ref.test (ref $$g1) (ref.func $$g))
+ )
+)`);
+
+// ./test/core/gc/type-subtyping.wast:330
+assert_return(() => invoke($16, `run`, []), [value("i32", 1)]);
+
+// ./test/core/gc/type-subtyping.wast:332
+let $17 = instantiate(`(module
+ (rec (type $$f1 (sub (func))) (type $$s1 (sub (struct (field (ref $$f1))))))
+ (rec (type $$f2 (sub (func))) (type $$s2 (sub (struct (field (ref $$f2))))))
+ (rec
+ (type $$g1 (sub $$f1 (func)))
+ (type (sub $$s1 (struct (field (ref $$f1) (ref $$f1) (ref $$f2) (ref $$f2) (ref $$g1)))))
+ )
+ (rec
+ (type $$g2 (sub $$f2 (func)))
+ (type (sub $$s2 (struct (field (ref $$f1) (ref $$f2) (ref $$f1) (ref $$f2) (ref $$g2)))))
+ )
+ (func $$g (type $$g2)) (elem declare func $$g)
+ (func (export "run") (result i32)
+ (ref.test (ref $$g1) (ref.func $$g))
+ )
+)`);
+
+// ./test/core/gc/type-subtyping.wast:348
+assert_return(() => invoke($17, `run`, []), [value("i32", 1)]);
+
+// ./test/core/gc/type-subtyping.wast:350
+let $18 = instantiate(`(module
+ (rec (type $$f1 (sub (func))) (type (struct (field (ref $$f1)))))
+ (rec (type $$f2 (sub (func))) (type (struct (field (ref $$f1)))))
+ (rec (type $$g1 (sub $$f1 (func))) (type (struct)))
+ (rec (type $$g2 (sub $$f2 (func))) (type (struct)))
+ (func $$g (type $$g2)) (elem declare func $$g)
+ (func (export "run") (result i32)
+ (ref.test (ref $$g1) (ref.func $$g))
+ )
+)`);
+
+// ./test/core/gc/type-subtyping.wast:360
+assert_return(() => invoke($18, `run`, []), [value("i32", 0)]);
+
+// ./test/core/gc/type-subtyping.wast:362
+let $19 = instantiate(`(module
+ (rec (type $$f1 (sub (func))) (type (struct (field (ref $$f1)))))
+ (rec (type $$f2 (sub (func))) (type (struct (field (ref $$f2)))))
+ (rec (type $$g (sub $$f1 (func))) (type (struct)))
+ (func $$g (type $$g)) (elem declare func $$g)
+ (func (export "run") (result i32)
+ (ref.test (ref $$f1) (ref.func $$g))
+ )
+)`);
+
+// ./test/core/gc/type-subtyping.wast:371
+assert_return(() => invoke($19, `run`, []), [value("i32", 1)]);
+
+// ./test/core/gc/type-subtyping.wast:373
+let $20 = instantiate(`(module
+ (rec (type $$f1 (sub (func))) (type $$s1 (sub (struct (field (ref $$f1))))))
+ (rec (type $$f2 (sub (func))) (type $$s2 (sub (struct (field (ref $$f2))))))
+ (rec
+ (type $$g1 (sub $$f1 (func)))
+ (type (sub $$s1 (struct (field (ref $$f1) (ref $$f1) (ref $$f2) (ref $$f2) (ref $$g1)))))
+ )
+ (rec
+ (type $$g2 (sub $$f2 (func)))
+ (type (sub $$s2 (struct (field (ref $$f1) (ref $$f2) (ref $$f1) (ref $$f2) (ref $$g2)))))
+ )
+ (rec (type $$h (sub $$g2 (func))) (type (struct)))
+ (func $$h (type $$h)) (elem declare func $$h)
+ (func (export "run") (result i32 i32)
+ (ref.test (ref $$f1) (ref.func $$h))
+ (ref.test (ref $$g1) (ref.func $$h))
+ )
+)`);
+
+// ./test/core/gc/type-subtyping.wast:391
+assert_return(() => invoke($20, `run`, []), [value("i32", 1), value("i32", 1)]);
+
+// ./test/core/gc/type-subtyping.wast:394
+let $21 = instantiate(`(module
+ (rec (type $$f11 (sub (func (result (ref func))))) (type $$f12 (sub $$f11 (func (result (ref $$f11))))))
+ (rec (type $$f21 (sub (func (result (ref func))))) (type $$f22 (sub $$f21 (func (result (ref $$f21))))))
+ (func $$f11 (type $$f11) (unreachable)) (elem declare func $$f11)
+ (func $$f12 (type $$f12) (unreachable)) (elem declare func $$f12)
+ (func (export "run") (result i32 i32 i32 i32)
+ (ref.test (ref $$f11) (ref.func $$f11))
+ (ref.test (ref $$f21) (ref.func $$f11))
+ (ref.test (ref $$f12) (ref.func $$f12))
+ (ref.test (ref $$f22) (ref.func $$f12))
+ )
+)`);
+
+// ./test/core/gc/type-subtyping.wast:406
+assert_return(
+ () => invoke($21, `run`, []),
+ [value("i32", 1), value("i32", 1), value("i32", 1), value("i32", 1)],
+);
+
+// ./test/core/gc/type-subtyping.wast:410
+let $22 = instantiate(`(module
+ (rec (type $$f11 (sub (func (result (ref func))))) (type $$f12 (sub $$f11 (func (result (ref $$f11))))))
+ (rec (type $$f21 (sub (func (result (ref func))))) (type $$f22 (sub $$f21 (func (result (ref $$f21))))))
+ (rec (type $$g11 (sub $$f11 (func (result (ref func))))) (type $$g12 (sub $$g11 (func (result (ref $$g11))))))
+ (rec (type $$g21 (sub $$f21 (func (result (ref func))))) (type $$g22 (sub $$g21 (func (result (ref $$g21))))))
+ (func $$g11 (type $$g11) (unreachable)) (elem declare func $$g11)
+ (func $$g12 (type $$g12) (unreachable)) (elem declare func $$g12)
+ (func (export "run") (result i32 i32 i32 i32 i32 i32 i32 i32)
+ (ref.test (ref $$f11) (ref.func $$g11))
+ (ref.test (ref $$f21) (ref.func $$g11))
+ (ref.test (ref $$f11) (ref.func $$g12))
+ (ref.test (ref $$f21) (ref.func $$g12))
+ (ref.test (ref $$g11) (ref.func $$g11))
+ (ref.test (ref $$g21) (ref.func $$g11))
+ (ref.test (ref $$g12) (ref.func $$g12))
+ (ref.test (ref $$g22) (ref.func $$g12))
+ )
+)`);
+
+// ./test/core/gc/type-subtyping.wast:428
+assert_return(
+ () => invoke($22, `run`, []),
+ [
+ value("i32", 1),
+ value("i32", 1),
+ value("i32", 1),
+ value("i32", 1),
+ value("i32", 1),
+ value("i32", 1),
+ value("i32", 1),
+ value("i32", 1),
+ ],
+);
+
+// ./test/core/gc/type-subtyping.wast:433
+let $23 = instantiate(`(module
+ (rec (type $$f11 (sub (func))) (type $$f12 (sub $$f11 (func))))
+ (rec (type $$f21 (sub (func))) (type $$f22 (sub $$f11 (func))))
+ (func $$f (type $$f21)) (elem declare func $$f)
+ (func (export "run") (result i32)
+ (ref.test (ref $$f11) (ref.func $$f))
+ )
+)`);
+
+// ./test/core/gc/type-subtyping.wast:441
+assert_return(() => invoke($23, `run`, []), [value("i32", 0)]);
+
+// ./test/core/gc/type-subtyping.wast:443
+let $24 = instantiate(`(module
+ (rec (type $$f01 (sub (func))) (type $$f02 (sub $$f01 (func))))
+ (rec (type $$f11 (sub (func))) (type $$f12 (sub $$f01 (func))))
+ (rec (type $$f21 (sub (func))) (type $$f22 (sub $$f11 (func))))
+ (func $$f (type $$f21)) (elem declare func $$f)
+ (func (export "run") (result i32)
+ (ref.test (ref $$f11) (ref.func $$f))
+ )
+)`);
+
+// ./test/core/gc/type-subtyping.wast:452
+assert_return(() => invoke($24, `run`, []), [value("i32", 0)]);
+
+// ./test/core/gc/type-subtyping.wast:458
+let $25 = instantiate(`(module
+ (type $$t0 (sub (func (result (ref null func)))))
+ (rec (type $$t1 (sub $$t0 (func (result (ref null $$t1))))))
+ (rec (type $$t2 (sub $$t1 (func (result (ref null $$t2))))))
+
+ (func (export "f0") (type $$t0) (ref.null func))
+ (func (export "f1") (type $$t1) (ref.null $$t1))
+ (func (export "f2") (type $$t2) (ref.null $$t2))
+)`);
+
+// ./test/core/gc/type-subtyping.wast:467
+register($25, `M`);
+
+// ./test/core/gc/type-subtyping.wast:469
+let $26 = instantiate(`(module
+ (type $$t0 (sub (func (result (ref null func)))))
+ (rec (type $$t1 (sub $$t0 (func (result (ref null $$t1))))))
+ (rec (type $$t2 (sub $$t1 (func (result (ref null $$t2))))))
+
+ (func (import "M" "f0") (type $$t0))
+ (func (import "M" "f1") (type $$t0))
+ (func (import "M" "f1") (type $$t1))
+ (func (import "M" "f2") (type $$t0))
+ (func (import "M" "f2") (type $$t1))
+ (func (import "M" "f2") (type $$t2))
+)`);
+
+// ./test/core/gc/type-subtyping.wast:482
+assert_unlinkable(
+ () => instantiate(`(module
+ (type $$t0 (sub (func (result (ref null func)))))
+ (rec (type $$t1 (sub $$t0 (func (result (ref null $$t1))))))
+ (rec (type $$t2 (sub $$t1 (func (result (ref null $$t2))))))
+ (func (import "M" "f0") (type $$t1))
+ )`),
+ `incompatible import type`,
+);
+
+// ./test/core/gc/type-subtyping.wast:492
+assert_unlinkable(
+ () => instantiate(`(module
+ (type $$t0 (sub (func (result (ref null func)))))
+ (rec (type $$t1 (sub $$t0 (func (result (ref null $$t1))))))
+ (rec (type $$t2 (sub $$t1 (func (result (ref null $$t2))))))
+ (func (import "M" "f0") (type $$t2))
+ )`),
+ `incompatible import type`,
+);
+
+// ./test/core/gc/type-subtyping.wast:502
+assert_unlinkable(
+ () => instantiate(`(module
+ (type $$t0 (sub (func (result (ref null func)))))
+ (rec (type $$t1 (sub $$t0 (func (result (ref null $$t1))))))
+ (rec (type $$t2 (sub $$t1 (func (result (ref null $$t2))))))
+ (func (import "M" "f1") (type $$t2))
+ )`),
+ `incompatible import type`,
+);
+
+// ./test/core/gc/type-subtyping.wast:512
+let $27 = instantiate(`(module
+ (type $$t1 (sub (func)))
+ (type $$t2 (sub final (func)))
+ (func (export "f1") (type $$t1))
+ (func (export "f2") (type $$t2))
+)`);
+
+// ./test/core/gc/type-subtyping.wast:518
+register($27, `M2`);
+
+// ./test/core/gc/type-subtyping.wast:520
+assert_unlinkable(
+ () => instantiate(`(module
+ (type $$t1 (sub (func)))
+ (type $$t2 (sub final (func)))
+ (func (import "M2" "f1") (type $$t2))
+ )`),
+ `incompatible import type`,
+);
+
+// ./test/core/gc/type-subtyping.wast:528
+assert_unlinkable(
+ () => instantiate(`(module
+ (type $$t1 (sub (func)))
+ (type $$t2 (sub final (func)))
+ (func (import "M2" "f2") (type $$t1))
+ )`),
+ `incompatible import type`,
+);
+
+// ./test/core/gc/type-subtyping.wast:538
+let $28 = instantiate(`(module
+ (rec (type $$f2 (sub (func))) (type (struct (field (ref $$f2)))))
+ (rec (type $$g2 (sub $$f2 (func))) (type (struct)))
+ (func (export "g") (type $$g2))
+)`);
+
+// ./test/core/gc/type-subtyping.wast:543
+register($28, `M3`);
+
+// ./test/core/gc/type-subtyping.wast:544
+let $29 = instantiate(`(module
+ (rec (type $$f1 (sub (func))) (type (struct (field (ref $$f1)))))
+ (rec (type $$g1 (sub $$f1 (func))) (type (struct)))
+ (func (import "M3" "g") (type $$g1))
+)`);
+
+// ./test/core/gc/type-subtyping.wast:550
+let $30 = instantiate(`(module
+ (rec (type $$f1 (sub (func))) (type $$s1 (sub (struct (field (ref $$f1))))))
+ (rec (type $$f2 (sub (func))) (type $$s2 (sub (struct (field (ref $$f2))))))
+ (rec
+ (type $$g2 (sub $$f2 (func)))
+ (type (sub $$s2 (struct (field (ref $$f1) (ref $$f2) (ref $$f1) (ref $$f2) (ref $$g2)))))
+ )
+ (func (export "g") (type $$g2))
+)`);
+
+// ./test/core/gc/type-subtyping.wast:559
+register($30, `M4`);
+
+// ./test/core/gc/type-subtyping.wast:560
+let $31 = instantiate(`(module
+ (rec (type $$f1 (sub (func))) (type $$s1 (sub (struct (field (ref $$f1))))))
+ (rec (type $$f2 (sub (func))) (type $$s2 (sub (struct (field (ref $$f2))))))
+ (rec
+ (type $$g1 (sub $$f1 (func)))
+ (type (sub $$s1 (struct (field (ref $$f1) (ref $$f1) (ref $$f2) (ref $$f2) (ref $$g1)))))
+ )
+ (func (import "M4" "g") (type $$g1))
+)`);
+
+// ./test/core/gc/type-subtyping.wast:570
+let $32 = instantiate(`(module
+ (rec (type $$f1 (sub (func))) (type (struct (field (ref $$f1)))))
+ (rec (type $$f2 (sub (func))) (type (struct (field (ref $$f1)))))
+ (rec (type $$g2 (sub $$f2 (func))) (type (struct)))
+ (func (export "g") (type $$g2))
+)`);
+
+// ./test/core/gc/type-subtyping.wast:576
+register($32, `M5`);
+
+// ./test/core/gc/type-subtyping.wast:577
+assert_unlinkable(
+ () => instantiate(`(module
+ (rec (type $$f1 (sub (func))) (type (struct (field (ref $$f1)))))
+ (rec (type $$g1 (sub $$f1 (func))) (type (struct)))
+ (func (import "M5" "g") (type $$g1))
+ )`),
+ `incompatible import`,
+);
+
+// ./test/core/gc/type-subtyping.wast:586
+let $33 = instantiate(`(module
+ (rec (type $$f1 (sub (func))) (type (struct (field (ref $$f1)))))
+ (rec (type $$f2 (sub (func))) (type (struct (field (ref $$f2)))))
+ (rec (type $$g (sub $$f1 (func))) (type (struct)))
+ (func (export "g") (type $$g))
+)`);
+
+// ./test/core/gc/type-subtyping.wast:592
+register($33, `M6`);
+
+// ./test/core/gc/type-subtyping.wast:593
+let $34 = instantiate(`(module
+ (rec (type $$f1 (sub (func))) (type (struct (field (ref $$f1)))))
+ (rec (type $$f2 (sub (func))) (type (struct (field (ref $$f2)))))
+ (rec (type $$g (sub $$f1 (func))) (type (struct)))
+ (func (import "M6" "g") (type $$f1))
+)`);
+
+// ./test/core/gc/type-subtyping.wast:600
+let $35 = instantiate(`(module
+ (rec (type $$f1 (sub (func))) (type $$s1 (sub (struct (field (ref $$f1))))))
+ (rec (type $$f2 (sub (func))) (type $$s2 (sub (struct (field (ref $$f2))))))
+ (rec
+ (type $$g2 (sub $$f2 (func)))
+ (type (sub $$s2 (struct (field (ref $$f1) (ref $$f2) (ref $$f1) (ref $$f2) (ref $$g2)))))
+ )
+ (rec (type $$h (sub $$g2 (func))) (type (struct)))
+ (func (export "h") (type $$h))
+)`);
+
+// ./test/core/gc/type-subtyping.wast:610
+register($35, `M7`);
+
+// ./test/core/gc/type-subtyping.wast:611
+let $36 = instantiate(`(module
+ (rec (type $$f1 (sub (func))) (type $$s1 (sub (struct (field (ref $$f1))))))
+ (rec (type $$f2 (sub (func))) (type $$s2 (sub (struct (field (ref $$f2))))))
+ (rec
+ (type $$g1 (sub $$f1 (func)))
+ (type (sub $$s1 (struct (field (ref $$f1) (ref $$f1) (ref $$f2) (ref $$f2) (ref $$g1)))))
+ )
+ (rec (type $$h (sub $$g1 (func))) (type (struct)))
+ (func (import "M7" "h") (type $$f1))
+ (func (import "M7" "h") (type $$g1))
+)`);
+
+// ./test/core/gc/type-subtyping.wast:624
+let $37 = instantiate(`(module
+ (rec (type $$f11 (sub (func (result (ref func))))) (type $$f12 (sub $$f11 (func (result (ref $$f11))))))
+ (rec (type $$f21 (sub (func (result (ref func))))) (type $$f22 (sub $$f21 (func (result (ref $$f21))))))
+ (func (export "f11") (type $$f11) (unreachable))
+ (func (export "f12") (type $$f12) (unreachable))
+)`);
+
+// ./test/core/gc/type-subtyping.wast:630
+register($37, `M8`);
+
+// ./test/core/gc/type-subtyping.wast:631
+let $38 = instantiate(`(module
+ (rec (type $$f11 (sub (func (result (ref func))))) (type $$f12 (sub $$f11 (func (result (ref $$f11))))))
+ (rec (type $$f21 (sub (func (result (ref func))))) (type $$f22 (sub $$f21 (func (result (ref $$f21))))))
+ (func (import "M8" "f11") (type $$f11))
+ (func (import "M8" "f11") (type $$f21))
+ (func (import "M8" "f12") (type $$f12))
+ (func (import "M8" "f12") (type $$f22))
+)`);
+
+// ./test/core/gc/type-subtyping.wast:640
+let $39 = instantiate(`(module
+ (rec (type $$f11 (sub (func (result (ref func))))) (type $$f12 (sub $$f11 (func (result (ref $$f11))))))
+ (rec (type $$f21 (sub (func (result (ref func))))) (type $$f22 (sub $$f21 (func (result (ref $$f21))))))
+ (rec (type $$g11 (sub $$f11 (func (result (ref func))))) (type $$g12 (sub $$g11 (func (result (ref $$g11))))))
+ (rec (type $$g21 (sub $$f21 (func (result (ref func))))) (type $$g22 (sub $$g21 (func (result (ref $$g21))))))
+ (func (export "g11") (type $$g11) (unreachable))
+ (func (export "g12") (type $$g12) (unreachable))
+)`);
+
+// ./test/core/gc/type-subtyping.wast:648
+register($39, `M9`);
+
+// ./test/core/gc/type-subtyping.wast:649
+let $40 = instantiate(`(module
+ (rec (type $$f11 (sub (func (result (ref func))))) (type $$f12 (sub $$f11 (func (result (ref $$f11))))))
+ (rec (type $$f21 (sub (func (result (ref func))))) (type $$f22 (sub $$f21 (func (result (ref $$f21))))))
+ (rec (type $$g11 (sub $$f11 (func (result (ref func))))) (type $$g12 (sub $$g11 (func (result (ref $$g11))))))
+ (rec (type $$g21 (sub $$f21 (func (result (ref func))))) (type $$g22 (sub $$g21 (func (result (ref $$g21))))))
+ (func (import "M9" "g11") (type $$f11))
+ (func (import "M9" "g11") (type $$f21))
+ (func (import "M9" "g12") (type $$f11))
+ (func (import "M9" "g12") (type $$f21))
+ (func (import "M9" "g11") (type $$g11))
+ (func (import "M9" "g11") (type $$g21))
+ (func (import "M9" "g12") (type $$g12))
+ (func (import "M9" "g12") (type $$g22))
+)`);
+
+// ./test/core/gc/type-subtyping.wast:664
+let $41 = instantiate(`(module
+ (rec (type $$f11 (sub (func))) (type $$f12 (sub $$f11 (func))))
+ (rec (type $$f21 (sub (func))) (type $$f22 (sub $$f11 (func))))
+ (func (export "f") (type $$f21))
+)`);
+
+// ./test/core/gc/type-subtyping.wast:669
+register($41, `M10`);
+
+// ./test/core/gc/type-subtyping.wast:670
+assert_unlinkable(
+ () => instantiate(`(module
+ (rec (type $$f11 (sub (func))) (type $$f12 (sub $$f11 (func))))
+ (func (import "M10" "f") (type $$f11))
+ )`),
+ `incompatible import`,
+);
+
+// ./test/core/gc/type-subtyping.wast:678
+let $42 = instantiate(`(module
+ (rec (type $$f01 (sub (func))) (type $$f02 (sub $$f01 (func))))
+ (rec (type $$f11 (sub (func))) (type $$f12 (sub $$f01 (func))))
+ (rec (type $$f21 (sub (func))) (type $$f22 (sub $$f11 (func))))
+ (func (export "f") (type $$f21))
+)`);
+
+// ./test/core/gc/type-subtyping.wast:684
+register($42, `M11`);
+
+// ./test/core/gc/type-subtyping.wast:685
+assert_unlinkable(
+ () => instantiate(`(module
+ (rec (type $$f01 (sub (func))) (type $$f02 (sub $$f01 (func))))
+ (rec (type $$f11 (sub (func))) (type $$f12 (sub $$f01 (func))))
+ (func (import "M11" "f") (type $$f11))
+ )`),
+ `incompatible import`,
+);
+
+// ./test/core/gc/type-subtyping.wast:698
+assert_invalid(
+ () => instantiate(`(module
+ (type $$t (func))
+ (type $$s (sub $$t (func)))
+ )`),
+ `sub type`,
+);
+
+// ./test/core/gc/type-subtyping.wast:706
+assert_invalid(
+ () => instantiate(`(module
+ (type $$t (struct))
+ (type $$s (sub $$t (struct)))
+ )`),
+ `sub type`,
+);
+
+// ./test/core/gc/type-subtyping.wast:714
+assert_invalid(
+ () => instantiate(`(module
+ (type $$t (sub final (func)))
+ (type $$s (sub $$t (func)))
+ )`),
+ `sub type`,
+);
+
+// ./test/core/gc/type-subtyping.wast:722
+assert_invalid(
+ () => instantiate(`(module
+ (type $$t (sub (func)))
+ (type $$s (sub final $$t (func)))
+ (type $$u (sub $$s (func)))
+ )`),
+ `sub type`,
+);
+
+// ./test/core/gc/type-subtyping.wast:735
+assert_invalid(
+ () => instantiate(`(module
+ (type $$a0 (sub (array i32)))
+ (type $$s0 (sub $$a0 (struct)))
+ )`),
+ `sub type`,
+);
+
+// ./test/core/gc/type-subtyping.wast:743
+assert_invalid(
+ () => instantiate(`(module
+ (type $$f0 (sub (func (param i32) (result i32))))
+ (type $$s0 (sub $$f0 (struct)))
+ )`),
+ `sub type`,
+);
+
+// ./test/core/gc/type-subtyping.wast:751
+assert_invalid(
+ () => instantiate(`(module
+ (type $$s0 (sub (struct)))
+ (type $$a0 (sub $$s0 (array i32)))
+ )`),
+ `sub type`,
+);
+
+// ./test/core/gc/type-subtyping.wast:759
+assert_invalid(
+ () => instantiate(`(module
+ (type $$f0 (sub (func (param i32) (result i32))))
+ (type $$a0 (sub $$f0 (array i32)))
+ )`),
+ `sub type`,
+);
+
+// ./test/core/gc/type-subtyping.wast:767
+assert_invalid(
+ () => instantiate(`(module
+ (type $$s0 (sub (struct)))
+ (type $$f0 (sub $$s0 (func (param i32) (result i32))))
+ )`),
+ `sub type`,
+);
+
+// ./test/core/gc/type-subtyping.wast:775
+assert_invalid(
+ () => instantiate(`(module
+ (type $$a0 (sub (array i32)))
+ (type $$f0 (sub $$a0 (func (param i32) (result i32))))
+ )`),
+ `sub type`,
+);
+
+// ./test/core/gc/type-subtyping.wast:783
+assert_invalid(
+ () => instantiate(`(module
+ (type $$a0 (sub (array i32)))
+ (type $$a1 (sub $$a0 (array i64)))
+ )`),
+ `sub type`,
+);
+
+// ./test/core/gc/type-subtyping.wast:791
+assert_invalid(
+ () => instantiate(`(module
+ (type $$s0 (sub (struct (field i32))))
+ (type $$s1 (sub $$s0 (struct (field i64))))
+ )`),
+ `sub type`,
+);
+
+// ./test/core/gc/type-subtyping.wast:799
+assert_invalid(
+ () => instantiate(`(module
+ (type $$f0 (sub (func)))
+ (type $$f1 (sub $$f0 (func (param i32))))
+ )`),
+ `sub type`,
+);
diff --git a/js/src/jit-test/tests/wasm/spec/gc/unreachable.wast.js b/js/src/jit-test/tests/wasm/spec/gc/unreachable.wast.js
new file mode 100644
index 0000000000..68401d21d0
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/spec/gc/unreachable.wast.js
@@ -0,0 +1,424 @@
+/* Copyright 2021 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ./test/core/unreachable.wast
+
+// ./test/core/unreachable.wast:3
+let $0 = instantiate(`(module
+ ;; Auxiliary definitions
+ (func $$dummy)
+ (func $$dummy3 (param i32 i32 i32))
+
+ (func (export "type-i32") (result i32) (unreachable))
+ (func (export "type-i64") (result i64) (unreachable))
+ (func (export "type-f32") (result f32) (unreachable))
+ (func (export "type-f64") (result f64) (unreachable))
+
+ (func (export "as-func-first") (result i32)
+ (unreachable) (i32.const -1)
+ )
+ (func (export "as-func-mid") (result i32)
+ (call $$dummy) (unreachable) (i32.const -1)
+ )
+ (func (export "as-func-last")
+ (call $$dummy) (unreachable)
+ )
+ (func (export "as-func-value") (result i32)
+ (call $$dummy) (unreachable)
+ )
+
+ (func (export "as-block-first") (result i32)
+ (block (result i32) (unreachable) (i32.const 2))
+ )
+ (func (export "as-block-mid") (result i32)
+ (block (result i32) (call $$dummy) (unreachable) (i32.const 2))
+ )
+ (func (export "as-block-last")
+ (block (nop) (call $$dummy) (unreachable))
+ )
+ (func (export "as-block-value") (result i32)
+ (block (result i32) (nop) (call $$dummy) (unreachable))
+ )
+ (func (export "as-block-broke") (result i32)
+ (block (result i32) (call $$dummy) (br 0 (i32.const 1)) (unreachable))
+ )
+
+ (func (export "as-loop-first") (result i32)
+ (loop (result i32) (unreachable) (i32.const 2))
+ )
+ (func (export "as-loop-mid") (result i32)
+ (loop (result i32) (call $$dummy) (unreachable) (i32.const 2))
+ )
+ (func (export "as-loop-last")
+ (loop (nop) (call $$dummy) (unreachable))
+ )
+ (func (export "as-loop-broke") (result i32)
+ (block (result i32)
+ (loop (result i32) (call $$dummy) (br 1 (i32.const 1)) (unreachable))
+ )
+ )
+
+ (func (export "as-br-value") (result i32)
+ (block (result i32) (br 0 (unreachable)))
+ )
+
+ (func (export "as-br_if-cond")
+ (block (br_if 0 (unreachable)))
+ )
+ (func (export "as-br_if-value") (result i32)
+ (block (result i32)
+ (drop (br_if 0 (unreachable) (i32.const 1))) (i32.const 7)
+ )
+ )
+ (func (export "as-br_if-value-cond") (result i32)
+ (block (result i32)
+ (drop (br_if 0 (i32.const 6) (unreachable))) (i32.const 7)
+ )
+ )
+
+ (func (export "as-br_table-index")
+ (block (br_table 0 0 0 (unreachable)))
+ )
+ (func (export "as-br_table-value") (result i32)
+ (block (result i32)
+ (br_table 0 0 0 (unreachable) (i32.const 1)) (i32.const 7)
+ )
+ )
+ (func (export "as-br_table-value-2") (result i32)
+ (block (result i32)
+ (block (result i32) (br_table 0 1 (unreachable) (i32.const 1)))
+ )
+ )
+ (func (export "as-br_table-value-index") (result i32)
+ (block (result i32)
+ (br_table 0 0 (i32.const 6) (unreachable)) (i32.const 7)
+ )
+ )
+ (func (export "as-br_table-value-and-index") (result i32)
+ (block (result i32) (br_table 0 0 (unreachable)) (i32.const 8))
+ )
+
+ (func (export "as-return-value") (result i64)
+ (return (unreachable))
+ )
+
+ (func (export "as-if-cond") (result i32)
+ (if (result i32) (unreachable) (then (i32.const 0)) (else (i32.const 1)))
+ )
+ (func (export "as-if-then") (param i32 i32) (result i32)
+ (if (result i32) (local.get 0) (then (unreachable)) (else (local.get 1)))
+ )
+ (func (export "as-if-else") (param i32 i32) (result i32)
+ (if (result i32) (local.get 0) (then (local.get 1)) (else (unreachable)))
+ )
+ (func (export "as-if-then-no-else") (param i32 i32) (result i32)
+ (if (local.get 0) (then (unreachable))) (local.get 1)
+ )
+
+ (func (export "as-select-first") (param i32 i32) (result i32)
+ (select (unreachable) (local.get 0) (local.get 1))
+ )
+ (func (export "as-select-second") (param i32 i32) (result i32)
+ (select (local.get 0) (unreachable) (local.get 1))
+ )
+ (func (export "as-select-cond") (result i32)
+ (select (i32.const 0) (i32.const 1) (unreachable))
+ )
+
+ (func (export "as-call-first")
+ (call $$dummy3 (unreachable) (i32.const 2) (i32.const 3))
+ )
+ (func (export "as-call-mid")
+ (call $$dummy3 (i32.const 1) (unreachable) (i32.const 3))
+ )
+ (func (export "as-call-last")
+ (call $$dummy3 (i32.const 1) (i32.const 2) (unreachable))
+ )
+
+ (type $$sig (func (param i32 i32 i32)))
+ (table funcref (elem $$dummy3))
+ (func (export "as-call_indirect-func")
+ (call_indirect (type $$sig)
+ (unreachable) (i32.const 1) (i32.const 2) (i32.const 3)
+ )
+ )
+ (func (export "as-call_indirect-first")
+ (call_indirect (type $$sig)
+ (i32.const 0) (unreachable) (i32.const 2) (i32.const 3)
+ )
+ )
+ (func (export "as-call_indirect-mid")
+ (call_indirect (type $$sig)
+ (i32.const 0) (i32.const 1) (unreachable) (i32.const 3)
+ )
+ )
+ (func (export "as-call_indirect-last")
+ (call_indirect (type $$sig)
+ (i32.const 0) (i32.const 1) (i32.const 2) (unreachable)
+ )
+ )
+
+ (func (export "as-local.set-value") (local f32)
+ (local.set 0 (unreachable))
+ )
+ (func (export "as-local.tee-value") (result f32) (local f32)
+ (local.tee 0 (unreachable))
+ )
+ (global $$a (mut f32) (f32.const 0))
+ (func (export "as-global.set-value") (result f32)
+ (global.set $$a (unreachable))
+ )
+
+ (memory 1)
+ (func (export "as-load-address") (result f32)
+ (f32.load (unreachable))
+ )
+ (func (export "as-loadN-address") (result i64)
+ (i64.load8_s (unreachable))
+ )
+
+ (func (export "as-store-address")
+ (f64.store (unreachable) (f64.const 7))
+ )
+ (func (export "as-store-value")
+ (i64.store (i32.const 2) (unreachable))
+ )
+
+ (func (export "as-storeN-address")
+ (i32.store8 (unreachable) (i32.const 7))
+ )
+ (func (export "as-storeN-value")
+ (i64.store16 (i32.const 2) (unreachable))
+ )
+
+ (func (export "as-unary-operand") (result f32)
+ (f32.neg (unreachable))
+ )
+
+ (func (export "as-binary-left") (result i32)
+ (i32.add (unreachable) (i32.const 10))
+ )
+ (func (export "as-binary-right") (result i64)
+ (i64.sub (i64.const 10) (unreachable))
+ )
+
+ (func (export "as-test-operand") (result i32)
+ (i32.eqz (unreachable))
+ )
+
+ (func (export "as-compare-left") (result i32)
+ (f64.le (unreachable) (f64.const 10))
+ )
+ (func (export "as-compare-right") (result i32)
+ (f32.ne (f32.const 10) (unreachable))
+ )
+
+ (func (export "as-convert-operand") (result i32)
+ (i32.wrap_i64 (unreachable))
+ )
+
+ (func (export "as-memory.grow-size") (result i32)
+ (memory.grow (unreachable))
+ )
+)`);
+
+// ./test/core/unreachable.wast:221
+assert_trap(() => invoke($0, `type-i32`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:222
+assert_trap(() => invoke($0, `type-i64`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:223
+assert_trap(() => invoke($0, `type-f32`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:224
+assert_trap(() => invoke($0, `type-f64`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:226
+assert_trap(() => invoke($0, `as-func-first`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:227
+assert_trap(() => invoke($0, `as-func-mid`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:228
+assert_trap(() => invoke($0, `as-func-last`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:229
+assert_trap(() => invoke($0, `as-func-value`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:231
+assert_trap(() => invoke($0, `as-block-first`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:232
+assert_trap(() => invoke($0, `as-block-mid`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:233
+assert_trap(() => invoke($0, `as-block-last`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:234
+assert_trap(() => invoke($0, `as-block-value`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:235
+assert_return(() => invoke($0, `as-block-broke`, []), [value("i32", 1)]);
+
+// ./test/core/unreachable.wast:237
+assert_trap(() => invoke($0, `as-loop-first`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:238
+assert_trap(() => invoke($0, `as-loop-mid`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:239
+assert_trap(() => invoke($0, `as-loop-last`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:240
+assert_return(() => invoke($0, `as-loop-broke`, []), [value("i32", 1)]);
+
+// ./test/core/unreachable.wast:242
+assert_trap(() => invoke($0, `as-br-value`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:244
+assert_trap(() => invoke($0, `as-br_if-cond`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:245
+assert_trap(() => invoke($0, `as-br_if-value`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:246
+assert_trap(() => invoke($0, `as-br_if-value-cond`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:248
+assert_trap(() => invoke($0, `as-br_table-index`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:249
+assert_trap(() => invoke($0, `as-br_table-value`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:250
+assert_trap(() => invoke($0, `as-br_table-value-2`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:251
+assert_trap(() => invoke($0, `as-br_table-value-index`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:252
+assert_trap(() => invoke($0, `as-br_table-value-and-index`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:254
+assert_trap(() => invoke($0, `as-return-value`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:256
+assert_trap(() => invoke($0, `as-if-cond`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:257
+assert_trap(() => invoke($0, `as-if-then`, [1, 6]), `unreachable`);
+
+// ./test/core/unreachable.wast:258
+assert_return(() => invoke($0, `as-if-then`, [0, 6]), [value("i32", 6)]);
+
+// ./test/core/unreachable.wast:259
+assert_trap(() => invoke($0, `as-if-else`, [0, 6]), `unreachable`);
+
+// ./test/core/unreachable.wast:260
+assert_return(() => invoke($0, `as-if-else`, [1, 6]), [value("i32", 6)]);
+
+// ./test/core/unreachable.wast:261
+assert_trap(() => invoke($0, `as-if-then-no-else`, [1, 6]), `unreachable`);
+
+// ./test/core/unreachable.wast:262
+assert_return(() => invoke($0, `as-if-then-no-else`, [0, 6]), [value("i32", 6)]);
+
+// ./test/core/unreachable.wast:264
+assert_trap(() => invoke($0, `as-select-first`, [0, 6]), `unreachable`);
+
+// ./test/core/unreachable.wast:265
+assert_trap(() => invoke($0, `as-select-first`, [1, 6]), `unreachable`);
+
+// ./test/core/unreachable.wast:266
+assert_trap(() => invoke($0, `as-select-second`, [0, 6]), `unreachable`);
+
+// ./test/core/unreachable.wast:267
+assert_trap(() => invoke($0, `as-select-second`, [1, 6]), `unreachable`);
+
+// ./test/core/unreachable.wast:268
+assert_trap(() => invoke($0, `as-select-cond`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:270
+assert_trap(() => invoke($0, `as-call-first`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:271
+assert_trap(() => invoke($0, `as-call-mid`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:272
+assert_trap(() => invoke($0, `as-call-last`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:274
+assert_trap(() => invoke($0, `as-call_indirect-func`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:275
+assert_trap(() => invoke($0, `as-call_indirect-first`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:276
+assert_trap(() => invoke($0, `as-call_indirect-mid`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:277
+assert_trap(() => invoke($0, `as-call_indirect-last`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:279
+assert_trap(() => invoke($0, `as-local.set-value`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:280
+assert_trap(() => invoke($0, `as-local.tee-value`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:281
+assert_trap(() => invoke($0, `as-global.set-value`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:283
+assert_trap(() => invoke($0, `as-load-address`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:284
+assert_trap(() => invoke($0, `as-loadN-address`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:286
+assert_trap(() => invoke($0, `as-store-address`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:287
+assert_trap(() => invoke($0, `as-store-value`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:288
+assert_trap(() => invoke($0, `as-storeN-address`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:289
+assert_trap(() => invoke($0, `as-storeN-value`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:291
+assert_trap(() => invoke($0, `as-unary-operand`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:293
+assert_trap(() => invoke($0, `as-binary-left`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:294
+assert_trap(() => invoke($0, `as-binary-right`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:296
+assert_trap(() => invoke($0, `as-test-operand`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:298
+assert_trap(() => invoke($0, `as-compare-left`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:299
+assert_trap(() => invoke($0, `as-compare-right`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:301
+assert_trap(() => invoke($0, `as-convert-operand`, []), `unreachable`);
+
+// ./test/core/unreachable.wast:303
+assert_trap(() => invoke($0, `as-memory.grow-size`, []), `unreachable`);
diff --git a/js/src/jit-test/tests/wasm/spec/gc/unreached-valid.wast.js b/js/src/jit-test/tests/wasm/spec/gc/unreached-valid.wast.js
new file mode 100644
index 0000000000..ced4b9df3c
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/spec/gc/unreached-valid.wast.js
@@ -0,0 +1,138 @@
+/* Copyright 2021 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ./test/core/unreached-valid.wast
+
+// ./test/core/unreached-valid.wast:1
+let $0 = instantiate(`(module
+
+ ;; Check that both sides of the select are evaluated
+ (func (export "select-trap-left") (param $$cond i32) (result i32)
+ (select (unreachable) (i32.const 0) (local.get $$cond))
+ )
+ (func (export "select-trap-right") (param $$cond i32) (result i32)
+ (select (i32.const 0) (unreachable) (local.get $$cond))
+ )
+
+ (func (export "select-unreached")
+ (unreachable) (select)
+ (unreachable) (i32.const 0) (select)
+ (unreachable) (i32.const 0) (i32.const 0) (select)
+ (unreachable) (i32.const 0) (i32.const 0) (i32.const 0) (select)
+ (unreachable) (f32.const 0) (i32.const 0) (select)
+ (unreachable)
+ )
+
+ (func (export "select-unreached-result1") (result i32)
+ (unreachable) (i32.add (select))
+ )
+
+ (func (export "select-unreached-result2") (result i64)
+ (unreachable) (i64.add (select (i64.const 0) (i32.const 0)))
+ )
+
+ (func (export "select-unreached-num")
+ (unreachable)
+ (select)
+ (i32.eqz)
+ (drop)
+ )
+ (func (export "select-unreached-ref")
+ (unreachable)
+ (select)
+ (ref.is_null)
+ (drop)
+ )
+
+ (type $$t (func (param i32) (result i32)))
+ (func (export "call_ref-unreached") (result i32)
+ (unreachable)
+ (call_ref $$t)
+ )
+)`);
+
+// ./test/core/unreached-valid.wast:48
+assert_trap(() => invoke($0, `select-trap-left`, [1]), `unreachable`);
+
+// ./test/core/unreached-valid.wast:49
+assert_trap(() => invoke($0, `select-trap-left`, [0]), `unreachable`);
+
+// ./test/core/unreached-valid.wast:50
+assert_trap(() => invoke($0, `select-trap-right`, [1]), `unreachable`);
+
+// ./test/core/unreached-valid.wast:51
+assert_trap(() => invoke($0, `select-trap-right`, [0]), `unreachable`);
+
+// ./test/core/unreached-valid.wast:53
+assert_trap(() => invoke($0, `select-unreached-result1`, []), `unreachable`);
+
+// ./test/core/unreached-valid.wast:54
+assert_trap(() => invoke($0, `select-unreached-result2`, []), `unreachable`);
+
+// ./test/core/unreached-valid.wast:55
+assert_trap(() => invoke($0, `select-unreached-num`, []), `unreachable`);
+
+// ./test/core/unreached-valid.wast:56
+assert_trap(() => invoke($0, `select-unreached-ref`, []), `unreachable`);
+
+// ./test/core/unreached-valid.wast:58
+assert_trap(() => invoke($0, `call_ref-unreached`, []), `unreachable`);
+
+// ./test/core/unreached-valid.wast:63
+let $1 = instantiate(`(module
+ (func (export "meet-bottom")
+ (block (result f64)
+ (block (result f32)
+ (unreachable)
+ (br_table 0 1 1 (i32.const 1))
+ )
+ (drop)
+ (f64.const 0)
+ )
+ (drop)
+ )
+)`);
+
+// ./test/core/unreached-valid.wast:77
+assert_trap(() => invoke($1, `meet-bottom`, []), `unreachable`);
+
+// ./test/core/unreached-valid.wast:82
+let $2 = instantiate(`(module
+ (func (result (ref func))
+ (unreachable)
+ (ref.as_non_null)
+ )
+ (func (result (ref extern))
+ (unreachable)
+ (ref.as_non_null)
+ )
+
+ (func (result (ref func))
+ (block (result funcref)
+ (unreachable)
+ (br_on_null 0)
+ (return)
+ )
+ (unreachable)
+ )
+ (func (result (ref extern))
+ (block (result externref)
+ (unreachable)
+ (br_on_null 0)
+ (return)
+ )
+ (unreachable)
+ )
+)`);