Debian Codegraph @

internal/integration_test/spectest/exception-handling/testdata/throw.wast

raw
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 (export "throw-polymorphic") (throw $e0) (throw $e-i32))
24
25 (func (export "throw-polymorphic-block") (block (result i32) (throw $e0)) (throw $e-i32))
26
27 (func $throw-1-2 (i32.const 1) (i32.const 2) (throw $e-i32-i32))
28 (func (export "test-throw-1-2")
29 (block $h (result i32 i32)
30 (try_table (catch $e-i32-i32 $h) (call $throw-1-2))
31 (return)
32 )
33 (if (i32.ne (i32.const 2)) (then (unreachable)))
34 (if (i32.ne (i32.const 1)) (then (unreachable)))
35 )
36 )
37
38 (assert_return (invoke "throw-if" (i32.const 0)) (i32.const 0))
39 (assert_exception (invoke "throw-if" (i32.const 10)))
40 (assert_exception (invoke "throw-if" (i32.const -1)))
41
42 (assert_exception (invoke "throw-param-f32" (f32.const 5.0)))
43 (assert_exception (invoke "throw-param-i64" (i64.const 5)))
44 (assert_exception (invoke "throw-param-f64" (f64.const 5.0)))
45
46 (assert_exception (invoke "throw-polymorphic"))
47 (assert_exception (invoke "throw-polymorphic-block"))
48
49 (assert_return (invoke "test-throw-1-2"))
50
51 (assert_invalid (module (func (throw 0))) "unknown tag 0")
52 (assert_invalid (module (tag (param i32)) (func (throw 0)))
53 "type mismatch: instruction requires [i32] but stack has []")
54 (assert_invalid (module (tag (param i32)) (func (i64.const 5) (throw 0)))
55 "type mismatch: instruction requires [i32] but stack has [i64]")