Debian Codegraph @

js/src/jit-test/tests/wasm/gc/ion-and-baseline.js

raw
1 // Attempt to test intercalls from ion to baseline and back.
2 //
3 // We get into this situation when the modules are compiled with different
4 // tiering policies, or one tiers up before the other, or (for now) one opts
5 // into gc and is baseline-compiled and the other does not and is ion-compiled.
6 // There are lots of variables here. Generally, a small module will be
7 // ion-compiled unless there's reason to baseline-compile it, so we're likely
8 // actually testing something here.
9 //
10 // Some logging with printf confirms that refmod is baseline-compiled and
11 // nonrefmod is ion-compiled at present, with --setpref=wasm_gc=true enabled.
12
13 var refmod = new WebAssembly.Module(wasmTextToBinary(
14 `(module
15 (import "" "tbl" (table $tbl 4 funcref))
16 (import "" "print" (func $print (param i32)))
17
18 ;; Just a dummy
19 (type $s (struct (field i32)))
20
21 (type $htype (func (param externref)))
22 (type $itype (func (result externref)))
23
24 (elem (i32.const 0) $f $g)
25
26 (func $f (param externref)
27 (call $print (i32.const 1)))
28
29 (func $g (result externref)
30 (call $print (i32.const 2))
31 (ref.null extern))
32
33 (func (export "test_h")
34 (call_indirect (type $htype) (ref.null extern) (i32.const 2)))
35
36 (func (export "test_i")
37 (drop (call_indirect (type $itype) (i32.const 3))))
38
39 )`));
40
41 var nonrefmod = new WebAssembly.Module(wasmTextToBinary(
42 `(module
43 (import "" "tbl" (table $tbl 4 funcref))
44 (import "" "print" (func $print (param i32)))
45
46 (type $ftype (func (param i32)))
47 (type $gtype (func (result i32)))
48
49 (elem (i32.const 2) $h $i)
50
51 ;; Should fail because of the signature mismatch: parameter
52 (func (export "test_f")
53 (call_indirect (type $ftype) (i32.const 37) (i32.const 0)))
54
55 ;; Should fail because of the signature mismatch: return value
56 (func (export "test_g")
57 (drop (call_indirect (type $gtype) (i32.const 1))))
58
59 (func $h (param i32)
60 (call $print (i32.const 2)))
61
62 (func $i (result i32)
63 (call $print (i32.const 3))
64 (i32.const 37))
65 )`));
66
67 var tbl = new WebAssembly.Table({initial:4, element:"anyfunc"});
68 var refins = new WebAssembly.Instance(refmod, {"":{print, tbl}}).exports;
69 var nonrefins = new WebAssembly.Instance(nonrefmod, {"":{print, tbl}}).exports;
70
71 assertErrorMessage(() => nonrefins.test_f(),
72 WebAssembly.RuntimeError,
73 /indirect call signature mismatch/);
74
75 assertErrorMessage(() => nonrefins.test_g(),
76 WebAssembly.RuntimeError,
77 /indirect call signature mismatch/);
78
79 assertErrorMessage(() => refins.test_h(),
80 WebAssembly.RuntimeError,
81 /indirect call signature mismatch/);
82
83 assertErrorMessage(() => refins.test_i(),
84 WebAssembly.RuntimeError,
85 /indirect call signature mismatch/);
86