Debian Codegraph @

js/src/jit-test/tests/wasm/spec/exception-handling/ref_func.wast.js

raw
1 /* Copyright 2021 Mozilla Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 // ./test/core/ref_func.wast
17
18 // ./test/core/ref_func.wast:1
19 let $0 = instantiate(`(module
20 (func (export "f") (param $$x i32) (result i32) (local.get $$x))
21 )`);
22
23 // ./test/core/ref_func.wast:4
24 register($0, `M`);
25
26 // ./test/core/ref_func.wast:6
27 let $1 = instantiate(`(module
28 (func $$f (import "M" "f") (param i32) (result i32))
29 (func $$g (param $$x i32) (result i32)
30 (i32.add (local.get $$x) (i32.const 1))
31 )
32
33 (global funcref (ref.func $$f))
34 (global funcref (ref.func $$g))
35 (global $$v (mut funcref) (ref.func $$f))
36
37 (global funcref (ref.func $$gf1))
38 (global funcref (ref.func $$gf2))
39 (func (drop (ref.func $$ff1)) (drop (ref.func $$ff2)))
40 (elem declare func $$gf1 $$ff1)
41 (elem declare funcref (ref.func $$gf2) (ref.func $$ff2))
42 (func $$gf1)
43 (func $$gf2)
44 (func $$ff1)
45 (func $$ff2)
46
47 (func (export "is_null-f") (result i32)
48 (ref.is_null (ref.func $$f))
49 )
50 (func (export "is_null-g") (result i32)
51 (ref.is_null (ref.func $$g))
52 )
53 (func (export "is_null-v") (result i32)
54 (ref.is_null (global.get $$v))
55 )
56
57 (func (export "set-f") (global.set $$v (ref.func $$f)))
58 (func (export "set-g") (global.set $$v (ref.func $$g)))
59
60 (table $$t 1 funcref)
61 (elem declare func $$f $$g)
62
63 (func (export "call-f") (param $$x i32) (result i32)
64 (table.set $$t (i32.const 0) (ref.func $$f))
65 (call_indirect $$t (param i32) (result i32) (local.get $$x) (i32.const 0))
66 )
67 (func (export "call-g") (param $$x i32) (result i32)
68 (table.set $$t (i32.const 0) (ref.func $$g))
69 (call_indirect $$t (param i32) (result i32) (local.get $$x) (i32.const 0))
70 )
71 (func (export "call-v") (param $$x i32) (result i32)
72 (table.set $$t (i32.const 0) (global.get $$v))
73 (call_indirect $$t (param i32) (result i32) (local.get $$x) (i32.const 0))
74 )
75 )`);
76
77 // ./test/core/ref_func.wast:56
78 assert_return(() => invoke($1, `is_null-f`, []), [value("i32", 0)]);
79
80 // ./test/core/ref_func.wast:57
81 assert_return(() => invoke($1, `is_null-g`, []), [value("i32", 0)]);
82
83 // ./test/core/ref_func.wast:58
84 assert_return(() => invoke($1, `is_null-v`, []), [value("i32", 0)]);
85
86 // ./test/core/ref_func.wast:60
87 assert_return(() => invoke($1, `call-f`, [4]), [value("i32", 4)]);
88
89 // ./test/core/ref_func.wast:61
90 assert_return(() => invoke($1, `call-g`, [4]), [value("i32", 5)]);
91
92 // ./test/core/ref_func.wast:62
93 assert_return(() => invoke($1, `call-v`, [4]), [value("i32", 4)]);
94
95 // ./test/core/ref_func.wast:63
96 invoke($1, `set-g`, []);
97
98 // ./test/core/ref_func.wast:64
99 assert_return(() => invoke($1, `call-v`, [4]), [value("i32", 5)]);
100
101 // ./test/core/ref_func.wast:65
102 invoke($1, `set-f`, []);
103
104 // ./test/core/ref_func.wast:66
105 assert_return(() => invoke($1, `call-v`, [4]), [value("i32", 4)]);
106
107 // ./test/core/ref_func.wast:68
108 assert_invalid(
109 () => instantiate(`(module
110 (func $$f (import "M" "f") (param i32) (result i32))
111 (func $$g (import "M" "g") (param i32) (result i32))
112 (global funcref (ref.func 7))
113 )`),
114 `unknown function 7`,
115 );
116
117 // ./test/core/ref_func.wast:80
118 let $2 = instantiate(`(module
119 (func $$f1)
120 (func $$f2)
121 (func $$f3)
122 (func $$f4)
123 (func $$f5)
124 (func $$f6)
125
126 (table $$t 1 funcref)
127
128 (global funcref (ref.func $$f1))
129 (export "f" (func $$f2))
130 (elem (table $$t) (i32.const 0) func $$f3)
131 (elem (table $$t) (i32.const 0) funcref (ref.func $$f4))
132 (elem func $$f5)
133 (elem funcref (ref.func $$f6))
134
135 (func
136 (ref.func $$f1)
137 (ref.func $$f2)
138 (ref.func $$f3)
139 (ref.func $$f4)
140 (ref.func $$f5)
141 (ref.func $$f6)
142 (return)
143 )
144 )`);
145
146 // ./test/core/ref_func.wast:108
147 assert_invalid(
148 () => instantiate(`(module (func $$f (drop (ref.func $$f))))`),
149 `undeclared function reference`,
150 );
151
152 // ./test/core/ref_func.wast:112
153 assert_invalid(
154 () => instantiate(`(module (start $$f) (func $$f (drop (ref.func $$f))))`),
155 `undeclared function reference`,
156 );