3bae85000fdca406316197ff5efe87c1b51b7a9b
[platform/framework/web/lwnode.git] /
1 (module
2   (type $t (func (result i32)))
3
4   (func $nn (param $r (ref $t)) (result i32)
5     (block $l
6       (return (call_ref (br_on_null $l (local.get $r))))
7     )
8     (i32.const -1)
9   )
10   (func $n (param $r (ref null $t)) (result i32)
11     (block $l
12       (return (call_ref (br_on_null $l (local.get $r))))
13     )
14     (i32.const -1)
15   )
16
17   (elem func $f)
18   (func $f (result i32) (i32.const 7))
19
20   (func (export "nullable-null") (result i32) (call $n (ref.null $t)))
21   (func (export "nonnullable-f") (result i32) (call $nn (ref.func $f)))
22   (func (export "nullable-f") (result i32) (call $n (ref.func $f)))
23
24   (func (export "unreachable") (result i32)
25     (block $l
26       (return (call_ref (br_on_null $l (unreachable))))
27     )
28     (i32.const -1)
29   )
30 )
31
32 (assert_trap (invoke "unreachable") "unreachable")
33
34 (assert_return (invoke "nullable-null") (i32.const -1))
35 (assert_return (invoke "nonnullable-f") (i32.const 7))
36 (assert_return (invoke "nullable-f") (i32.const 7))
37
38 (assert_invalid
39   (module
40     (type $t (func (result i32)))
41     (func $g (param $r (ref $t)) (drop (br_on_null 0 (local.get $r))))
42     (func (call $g (ref.null $t)))
43   )
44   "type mismatch"
45 )
46
47 (module
48   (type $t (func))
49   (func (param $r (ref $t)) (drop (br_on_null 0 (local.get $r))))
50   (func (param $r (ref func)) (drop (br_on_null 0 (local.get $r))))
51   (func (param $r (ref extern)) (drop (br_on_null 0 (local.get $r))))
52 )
53
54
55 (module
56   (type $t (func (param i32) (result i32)))
57   (elem func $f)
58   (func $f (param i32) (result i32) (i32.mul (local.get 0) (local.get 0)))
59
60   (func $a (param $n i32) (param $r (ref null $t)) (result i32)
61     (block $l (result i32)
62       (return (call_ref (br_on_null $l (local.get $n) (local.get $r))))
63     )
64   )
65
66   (func (export "args-null") (param $n i32) (result i32)
67     (call $a (local.get $n) (ref.null $t))
68   )
69   (func (export "args-f") (param $n i32) (result i32)
70     (call $a (local.get $n) (ref.func $f))
71   )
72 )
73
74 (assert_return (invoke "args-null" (i32.const 3)) (i32.const 3))
75 (assert_return (invoke "args-f" (i32.const 3)) (i32.const 9))