summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/wasm/function-references/br-non-null.js
blob: 6d359105fbddb1a073dbac49e579df09a384aa92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// |jit-test| skip-if: !wasmGcEnabled()

// br_on_non_null from constant
wasmValidateText(`(module
  (func
    block (result (ref extern))
      ref.null extern
      br_on_non_null 0
      return
    end
    drop
  )
)`);

// br_on_non_null from parameter
wasmValidateText(`(module
  (func (param externref) (result (ref extern))
    local.get 0
    br_on_non_null 0
    unreachable
  )
)`);

// br_on_null with multiple results
wasmValidateText(`(module
  (func (param (ref null extern) (ref extern)) (result i32 i32 i32 (ref extern))
    i32.const 0
    i32.const 1
    i32.const 2
    local.get 0
    br_on_non_null 0
    local.get 1
  )
)`);

// no block type
wasmFailValidateText(`(module
  (func
    block
      ref.null extern
      br_on_non_null 0
    end
  )
)`, /type mismatch: target block type expected to be \[_, ref\]/);

// in dead code
wasmValidateText(`(module
  (type $t (func))
  (func (result funcref)
    ref.null $t
    return
    br_on_non_null 0
  )
)`);

wasmFailValidateText(`(module
  (func
    return
    br_on_non_null 0
  )
)`, /type mismatch: target block type expected to be \[_, ref\]/);

// Test the branch takes the correct path and results are passed correctly
let {ifNull} = wasmEvalText(`(module
  (func (export "ifNull") (param externref externref) (result externref)
    local.get 0
    br_on_non_null 0
    local.get 1
  )
)`).exports;

const DefaultTestVal = "default!test";
assertEq(ifNull(null, DefaultTestVal), DefaultTestVal);
for (let val of WasmNonNullExternrefValues) {
  assertEq(ifNull(val, DefaultTestVal), val);
}