Debian Codegraph @

tests/cli/legacy-exceptions/throw.wast

raw
1 ;; RUN: wast --assert default,no-test-folded --snapshot tests/snapshots % -f legacy-exceptions
2
3 ;; Test throw instruction.
4
5 (module
6 (tag $e0)
7 (tag $e-i32 (param i32))
8 (tag $e-f32 (param f32))
9 (tag $e-i64 (param i64))
10 (tag $e-f64 (param f64))
11 (tag $e-i32-i32 (param i32 i32))
12
13 (func $throw-if (export "throw-if") (param i32) (result i32)
14 (local.get 0)
15 (i32.const 0) (if (i32.ne) (then (throw $e0)))
16 (i32.const 0)
17 )
18
19 (func (export "throw-param-f32") (param f32) (local.get 0) (throw $e-f32))
20
21 (func (export "throw-param-i64") (param i64) (local.get 0) (throw $e-i64))
22
23 (func (export "throw-param-f64") (param f64) (local.get 0) (throw $e-f64))
24
25 (func $throw-1-2 (i32.const 1) (i32.const 2) (throw $e-i32-i32))
26 (func (export "test-throw-1-2")
27 try
28 call $throw-1-2
29 catch $e-i32-i32
30 i32.const 2
31 i32.ne
32 if
33 unreachable
34 end
35 i32.const 1
36 i32.ne
37 if
38 unreachable
39 end
40 end
41 )
42 )
43
44 (assert_return (invoke "throw-if" (i32.const 0)) (i32.const 0))
45 (assert_exception (invoke "throw-if" (i32.const 10)))
46 (assert_exception (invoke "throw-if" (i32.const -1)))
47
48 (assert_exception (invoke "throw-param-f32" (f32.const 5.0)))
49 (assert_exception (invoke "throw-param-i64" (i64.const 5)))
50 (assert_exception (invoke "throw-param-f64" (f64.const 5.0)))
51
52 (assert_return (invoke "test-throw-1-2"))
53
54 (assert_invalid (module (func (throw 0))) "unknown tag 0")
55 (assert_invalid (module (tag (param i32)) (func (throw 0)))
56 "type mismatch")
57 (assert_invalid (module (tag (param i32)) (func (i64.const 5) (throw 0)))
58 "type mismatch")