summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/wasm/gc/tables-generalized-struct.js
blob: b0bd96402727c6a9f3f7f63766ae8b1a311281a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// |jit-test| skip-if: !wasmGcEnabled()

// table.set in bounds with i32 x eqref - works, no value generated
// table.set with (ref null T) - works
// table.set with null - works
// table.set out of bounds - fails

{
    let ins = wasmEvalText(
        `(module
           (table (export "t") 10 eqref)
           (type $dummy (struct (field i32)))
           (func (export "set_eqref") (param i32) (param eqref)
             (table.set (local.get 0) (local.get 1)))
           (func (export "set_null") (param i32)
             (table.set (local.get 0) (ref.null eq)))
           (func (export "set_ref") (param i32) (param eqref)
             (table.set (local.get 0) (ref.cast (ref null $dummy) (local.get 1))))
           (func (export "make_struct") (result eqref)
             (struct.new $dummy (i32.const 37))))`);
    let a = ins.exports.make_struct();
    ins.exports.set_eqref(3, a);
    assertEq(ins.exports.t.get(3), a);
    ins.exports.set_null(3);
    assertEq(ins.exports.t.get(3), null);
    let b = ins.exports.make_struct();
    ins.exports.set_ref(5, b);
    assertEq(ins.exports.t.get(5), b);

    assertErrorMessage(() => ins.exports.set_eqref(10, a), WebAssembly.RuntimeError, /index out of bounds/);
    assertErrorMessage(() => ins.exports.set_eqref(-1, a), WebAssembly.RuntimeError, /index out of bounds/);
}

// table.grow on table of eqref with non-null ref value

{
    let ins = wasmEvalText(
        `(module
          (type $S (struct (field i32) (field f64)))
          (table (export "t") 2 eqref)
          (func (export "f") (result i32)
           (table.grow (struct.new $S (i32.const 0) (f64.const 3.14)) (i32.const 1))))`);
    assertEq(ins.exports.t.length, 2);
    assertEq(ins.exports.f(), 2);
    assertEq(ins.exports.t.length, 3);
    assertEq(typeof ins.exports.t.get(2), "object");
}