Debian Codegraph @

js/src/jit-test/tests/wasm/declared-segs.js

raw
1 // Declared segments parse and validate
2 wasmFullPass(`
3 (module
4 (func $f1)
5 (elem declare func $f1)
6 (elem declare funcref (ref.null func))
7 (func $run)
8 (export "run" (func $run))
9 )
10 `);
11
12 // Declared segments can be used with externref
13 wasmFullPass(`
14 (module
15 (elem declare externref (ref.null extern))
16 (func $run)
17 (export "run" (func $run))
18 )
19 `);
20
21 // Declared segments cannot be used at runtime
22 {
23 let inst = wasmEvalText(`
24 (module
25 (func $f1)
26 (table 1 1 funcref)
27 (elem $e1 declare func $f1)
28 (func (export "testfn") (table.init $e1 (i32.const 0) (i32.const 0) (i32.const 1)))
29 )
30 `);
31 assertErrorMessage(() => inst.exports.testfn(), WebAssembly.RuntimeError, /index out of bounds/);
32 }
33
34 // Declared segments can be dropped, although this has no effect
35 wasmEvalText(`
36 (module
37 (func $f1)
38 (table 1 1 funcref)
39 (elem $e1 declare func $f1)
40 (func $start (elem.drop $e1) (elem.drop $e1))
41 (start $start)
42 )
43 `)
44
45 // Declared segments don't cause initialization of a table
46 wasmAssert(`
47 (module
48 (func $f1)
49 (table 1 1 funcref)
50 (elem declare func $f1)
51 (func $at (param i32) (result i32)
52 local.get 0
53 table.get 0
54 ref.is_null
55 )
56 (export "at" (func $at))
57 )
58 `, [{type: 'i32', func: '$at', args: ['i32.const 0'], expected: '1'}]);