tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

tables-generalized-struct.js (1791B)


      1 // table.set in bounds with i32 x eqref - works, no value generated
      2 // table.set with (ref null T) - works
      3 // table.set with null - works
      4 // table.set out of bounds - fails
      5 
      6 {
      7    let ins = wasmEvalText(
      8        `(module
      9           (table (export "t") 10 eqref)
     10           (type $dummy (struct (field i32)))
     11           (func (export "set_eqref") (param i32) (param eqref)
     12             (table.set (local.get 0) (local.get 1)))
     13           (func (export "set_null") (param i32)
     14             (table.set (local.get 0) (ref.null eq)))
     15           (func (export "set_ref") (param i32) (param eqref)
     16             (table.set (local.get 0) (ref.cast (ref null $dummy) (local.get 1))))
     17           (func (export "make_struct") (result eqref)
     18             (struct.new $dummy (i32.const 37))))`);
     19    let a = ins.exports.make_struct();
     20    ins.exports.set_eqref(3, a);
     21    assertEq(ins.exports.t.get(3), a);
     22    ins.exports.set_null(3);
     23    assertEq(ins.exports.t.get(3), null);
     24    let b = ins.exports.make_struct();
     25    ins.exports.set_ref(5, b);
     26    assertEq(ins.exports.t.get(5), b);
     27 
     28    assertErrorMessage(() => ins.exports.set_eqref(10, a), WebAssembly.RuntimeError, /index out of bounds/);
     29    assertErrorMessage(() => ins.exports.set_eqref(-1, a), WebAssembly.RuntimeError, /index out of bounds/);
     30 }
     31 
     32 // table.grow on table of eqref with non-null ref value
     33 
     34 {
     35    let ins = wasmEvalText(
     36        `(module
     37          (type $S (struct (field i32) (field f64)))
     38          (table (export "t") 2 eqref)
     39          (func (export "f") (result i32)
     40           (table.grow (struct.new $S (i32.const 0) (f64.const 3.14)) (i32.const 1))))`);
     41    assertEq(ins.exports.t.length, 2);
     42    assertEq(ins.exports.f(), 2);
     43    assertEq(ins.exports.t.length, 3);
     44    assertEq(typeof ins.exports.t.get(2), "object");
     45 }