Skip to content

Commit 1cdafa7

Browse files
authored
Add unfolded versions of the legacy (v3) exception-handling tests (#1672)
1 parent bf282bb commit 1cdafa7

File tree

17 files changed

+2678
-1
lines changed

17 files changed

+2678
-1
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
;; Test rethrow instruction.
2+
3+
(module
4+
(tag $e0)
5+
(tag $e1)
6+
7+
(func (export "catch-rethrow-0")
8+
try
9+
throw $e0
10+
catch $e0
11+
rethrow 0
12+
end
13+
)
14+
15+
(func (export "catch-rethrow-1") (param i32) (result i32)
16+
try (result i32)
17+
throw $e0
18+
catch $e0
19+
local.get 0
20+
i32.eqz
21+
if
22+
rethrow 1
23+
end
24+
i32.const 23
25+
end
26+
)
27+
28+
(func (export "catchall-rethrow-0")
29+
try
30+
throw $e0
31+
catch_all
32+
rethrow 0
33+
end
34+
)
35+
36+
(func (export "catchall-rethrow-1") (param i32) (result i32)
37+
try (result i32)
38+
throw $e0
39+
catch_all
40+
local.get 0
41+
i32.eqz
42+
if
43+
rethrow 1
44+
end
45+
i32.const 23
46+
end
47+
)
48+
49+
(func (export "rethrow-nested") (param i32) (result i32)
50+
try (result i32)
51+
throw $e1
52+
catch $e1
53+
try (result i32)
54+
throw $e0
55+
catch $e0
56+
local.get 0
57+
i32.const 0
58+
i32.eq
59+
if
60+
rethrow 1
61+
end
62+
local.get 0
63+
i32.const 1
64+
i32.eq
65+
if
66+
rethrow 2
67+
end
68+
i32.const 23
69+
end
70+
end
71+
)
72+
73+
(func (export "rethrow-recatch") (param i32) (result i32)
74+
try (result i32)
75+
throw $e0
76+
catch $e0
77+
try (result i32)
78+
local.get 0
79+
i32.eqz
80+
if
81+
rethrow 2
82+
end
83+
i32.const 42
84+
catch $e0
85+
i32.const 23
86+
end
87+
end
88+
)
89+
90+
(func (export "rethrow-stack-polymorphism")
91+
try
92+
throw $e0
93+
catch $e0
94+
i32.const 1
95+
rethrow 0
96+
end
97+
)
98+
)
99+
100+
(assert_exception (invoke "catch-rethrow-0"))
101+
102+
(assert_exception (invoke "catch-rethrow-1" (i32.const 0)))
103+
(assert_return (invoke "catch-rethrow-1" (i32.const 1)) (i32.const 23))
104+
105+
(assert_exception (invoke "catchall-rethrow-0"))
106+
107+
(assert_exception (invoke "catchall-rethrow-1" (i32.const 0)))
108+
(assert_return (invoke "catchall-rethrow-1" (i32.const 1)) (i32.const 23))
109+
(assert_exception (invoke "rethrow-nested" (i32.const 0)))
110+
(assert_exception (invoke "rethrow-nested" (i32.const 1)))
111+
(assert_return (invoke "rethrow-nested" (i32.const 2)) (i32.const 23))
112+
113+
(assert_return (invoke "rethrow-recatch" (i32.const 0)) (i32.const 23))
114+
(assert_return (invoke "rethrow-recatch" (i32.const 1)) (i32.const 42))
115+
116+
(assert_exception (invoke "rethrow-stack-polymorphism"))
117+
118+
(assert_invalid (module (func (rethrow 0))) "invalid rethrow label")
119+
(assert_invalid (module (func (block (rethrow 0)))) "invalid rethrow label")
120+
(assert_invalid (module (func
121+
try
122+
rethrow 0
123+
delegate 0))
124+
"invalid rethrow label")
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
;; Test throw instruction.
2+
3+
(module
4+
(tag $e0)
5+
(tag $e-i32 (param i32))
6+
(tag $e-f32 (param f32))
7+
(tag $e-i64 (param i64))
8+
(tag $e-f64 (param f64))
9+
(tag $e-i32-i32 (param i32 i32))
10+
11+
(func $throw-if (export "throw-if") (param i32) (result i32)
12+
(local.get 0)
13+
(i32.const 0) (if (i32.ne) (then (throw $e0)))
14+
(i32.const 0)
15+
)
16+
17+
(func (export "throw-param-f32") (param f32) (local.get 0) (throw $e-f32))
18+
19+
(func (export "throw-param-i64") (param i64) (local.get 0) (throw $e-i64))
20+
21+
(func (export "throw-param-f64") (param f64) (local.get 0) (throw $e-f64))
22+
23+
(func $throw-1-2 (i32.const 1) (i32.const 2) (throw $e-i32-i32))
24+
(func (export "test-throw-1-2")
25+
try
26+
call $throw-1-2
27+
catch $e-i32-i32
28+
i32.const 2
29+
i32.ne
30+
if
31+
unreachable
32+
end
33+
i32.const 1
34+
i32.ne
35+
if
36+
unreachable
37+
end
38+
end
39+
)
40+
)
41+
42+
(assert_return (invoke "throw-if" (i32.const 0)) (i32.const 0))
43+
(assert_exception (invoke "throw-if" (i32.const 10)))
44+
(assert_exception (invoke "throw-if" (i32.const -1)))
45+
46+
(assert_exception (invoke "throw-param-f32" (f32.const 5.0)))
47+
(assert_exception (invoke "throw-param-i64" (i64.const 5)))
48+
(assert_exception (invoke "throw-param-f64" (f64.const 5.0)))
49+
50+
(assert_return (invoke "test-throw-1-2"))
51+
52+
(assert_invalid (module (func (throw 0))) "unknown tag 0")
53+
(assert_invalid (module (tag (param i32)) (func (throw 0)))
54+
"type mismatch: instruction requires [i32] but stack has []")
55+
(assert_invalid (module (tag (param i32)) (func (i64.const 5) (throw 0)))
56+
"type mismatch: instruction requires [i32] but stack has [i64]")

0 commit comments

Comments
 (0)