summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/wasm/gc/arrays.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/jit-test/tests/wasm/gc/arrays.js')
-rw-r--r--js/src/jit-test/tests/wasm/gc/arrays.js143
1 files changed, 143 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/wasm/gc/arrays.js b/js/src/jit-test/tests/wasm/gc/arrays.js
index b3f03151bb..cb61bb1b07 100644
--- a/js/src/jit-test/tests/wasm/gc/arrays.js
+++ b/js/src/jit-test/tests/wasm/gc/arrays.js
@@ -604,6 +604,51 @@ assertErrorMessage(() => wasmEvalText(`(module
},WebAssembly.RuntimeError, /index out of bounds/);
}
+// run: zero-length copies are allowed
+{
+ let { newData } = wasmEvalText(`(module
+ (type $a (array i8))
+ (data $d "1337")
+ (func (export "newData") (result eqref)
+ (; offset=0 into data ;) i32.const 0
+ (; size=0 into data ;) i32.const 0
+ array.new_data $a $d
+ )
+ )`).exports;
+ let arr = newData();
+ assertEq(wasmGcArrayLength(arr), 0);
+}
+
+// run: a zero-length copy from the end is allowed
+{
+ let { newData } = wasmEvalText(`(module
+ (type $a (array i8))
+ (data $d "1337")
+ (func (export "newData") (result eqref)
+ (; offset=4 into data ;) i32.const 4
+ (; size=0 into data ;) i32.const 0
+ array.new_data $a $d
+ )
+ )`).exports;
+ let arr = newData();
+ assertEq(wasmGcArrayLength(arr), 0);
+}
+
+// run: even empty data segments are allowed
+{
+ let { newData } = wasmEvalText(`(module
+ (type $a (array i8))
+ (data $d "")
+ (func (export "newData") (result eqref)
+ (; offset=0 into data ;) i32.const 0
+ (; size=0 into data ;) i32.const 0
+ array.new_data $a $d
+ )
+ )`).exports;
+ let arr = newData();
+ assertEq(wasmGcArrayLength(arr), 0);
+}
+
// run: resulting array is as expected
{
let { newData } = wasmEvalText(`(module
@@ -802,6 +847,59 @@ assertErrorMessage(() => wasmEvalText(`(module
},WebAssembly.RuntimeError, /index out of bounds/);
}
+// run: zero-length copies are allowed
+{
+ let { newElem, f1, f2, f3, f4 } = wasmEvalText(`(module
+ (type $a (array funcref))
+ (elem $e func $f1 $f2 $f3 $f4)
+ (func $f1 (export "f1"))
+ (func $f2 (export "f2"))
+ (func $f3 (export "f3"))
+ (func $f4 (export "f4"))
+ (func (export "newElem") (result eqref)
+ (; offset=0 into elem ;) i32.const 0
+ (; size=0 into elem ;) i32.const 0
+ array.new_elem $a $e
+ )
+ )`).exports;
+ let arr = newElem();
+ assertEq(wasmGcArrayLength(arr), 0);
+}
+
+// run: a zero-length copy from the end is allowed
+{
+ let { newElem, f1, f2, f3, f4 } = wasmEvalText(`(module
+ (type $a (array funcref))
+ (elem $e func $f1 $f2 $f3 $f4)
+ (func $f1 (export "f1"))
+ (func $f2 (export "f2"))
+ (func $f3 (export "f3"))
+ (func $f4 (export "f4"))
+ (func (export "newElem") (result eqref)
+ (; offset=4 into elem ;) i32.const 4
+ (; size=0 into elem ;) i32.const 0
+ array.new_elem $a $e
+ )
+ )`).exports;
+ let arr = newElem();
+ assertEq(wasmGcArrayLength(arr), 0);
+}
+
+// run: even empty elem segments are allowed
+{
+ let { newElem, f1, f2, f3, f4 } = wasmEvalText(`(module
+ (type $a (array funcref))
+ (elem $e func)
+ (func (export "newElem") (result eqref)
+ (; offset=0 into elem ;) i32.const 0
+ (; size=0 into elem ;) i32.const 0
+ array.new_elem $a $e
+ )
+ )`).exports;
+ let arr = newElem();
+ assertEq(wasmGcArrayLength(arr), 0);
+}
+
// run: resulting array is as expected
{
let { newElem, f1, f2, f3, f4 } = wasmEvalText(`(module
@@ -1130,6 +1228,29 @@ assertErrorMessage(() => wasmEvalText(`(module
},WebAssembly.RuntimeError, /index out of bounds/);
}
+// run: zeroes everywhere
+{
+ let { initData } = wasmEvalText(`(module
+ (type $a (array (mut i8)))
+ (data $d "")
+ (func (export "initData") (result eqref)
+ (local $arr (ref $a))
+ (local.set $arr (array.new_default $a (i32.const 0)))
+
+ (; array to init ;) local.get $arr
+ (; offset=0 into array ;) i32.const 0
+ (; offset=0 into data ;) i32.const 0
+ (; size=0 elements ;) i32.const 0
+ array.init_data $a $d
+
+ local.get $arr
+ )
+ (func data.drop 0) ;; force write of data count section, see https://github.com/bytecodealliance/wasm-tools/pull/1194
+ )`).exports;
+ let arr = initData();
+ assertEq(wasmGcArrayLength(arr), 0);
+}
+
// run: resulting array is as expected
{
let { initData } = wasmEvalText(`(module
@@ -1488,6 +1609,28 @@ assertErrorMessage(() => wasmEvalText(`(module
},WebAssembly.RuntimeError, /index out of bounds/);
}
+// run: zeroes everywhere
+{
+ let { initElem, f1, f2, f3, f4 } = wasmEvalText(`(module
+ (type $a (array (mut funcref)))
+ (elem $e func)
+ (func (export "initElem") (result eqref)
+ (local $arr (ref $a))
+ (local.set $arr (array.new_default $a (i32.const 0)))
+
+ (; array to init ;) local.get $arr
+ (; offset=0 into array ;) i32.const 0
+ (; offset=0 into elem ;) i32.const 0
+ (; size=0 into elem ;) i32.const 0
+ array.init_elem $a $e
+
+ local.get $arr
+ )
+ )`).exports;
+ let arr = initElem();
+ assertEq(wasmGcArrayLength(arr), 0);
+}
+
// run: resulting array is as expected
{
let { initElem, f1, f2, f3, f4 } = wasmEvalText(`(module