| 1 |
// br_on_non_null from constant |
| 2 |
wasmValidateText(`(module |
| 3 |
(func |
| 4 |
block (result (ref extern)) |
| 5 |
ref.null extern |
| 6 |
br_on_non_null 0 |
| 7 |
return |
| 8 |
end |
| 9 |
drop |
| 10 |
) |
| 11 |
)`); |
| 12 |
|
| 13 |
// br_on_non_null from parameter |
| 14 |
wasmValidateText(`(module |
| 15 |
(func (param externref) (result (ref extern)) |
| 16 |
local.get 0 |
| 17 |
br_on_non_null 0 |
| 18 |
unreachable |
| 19 |
) |
| 20 |
)`); |
| 21 |
|
| 22 |
// br_on_null with multiple results |
| 23 |
wasmValidateText(`(module |
| 24 |
(func (param (ref null extern) (ref extern)) (result i32 i32 i32 (ref extern)) |
| 25 |
i32.const 0 |
| 26 |
i32.const 1 |
| 27 |
i32.const 2 |
| 28 |
local.get 0 |
| 29 |
br_on_non_null 0 |
| 30 |
local.get 1 |
| 31 |
) |
| 32 |
)`); |
| 33 |
|
| 34 |
// no block type |
| 35 |
wasmFailValidateText(`(module |
| 36 |
(func |
| 37 |
block |
| 38 |
ref.null extern |
| 39 |
br_on_non_null 0 |
| 40 |
end |
| 41 |
) |
| 42 |
)`, /type mismatch: target block type expected to be \[_, ref\]/); |
| 43 |
|
| 44 |
// in dead code |
| 45 |
wasmValidateText(`(module |
| 46 |
(type $t (func)) |
| 47 |
(func (result funcref) |
| 48 |
ref.null $t |
| 49 |
return |
| 50 |
br_on_non_null 0 |
| 51 |
) |
| 52 |
)`); |
| 53 |
|
| 54 |
wasmFailValidateText(`(module |
| 55 |
(func |
| 56 |
return |
| 57 |
br_on_non_null 0 |
| 58 |
) |
| 59 |
)`, /type mismatch: target block type expected to be \[_, ref\]/); |
| 60 |
|
| 61 |
// Test the branch takes the correct path and results are passed correctly |
| 62 |
let {ifNull} = wasmEvalText(`(module |
| 63 |
(func (export "ifNull") (param externref externref) (result externref) |
| 64 |
local.get 0 |
| 65 |
br_on_non_null 0 |
| 66 |
local.get 1 |
| 67 |
) |
| 68 |
)`).exports; |
| 69 |
|
| 70 |
const DefaultTestVal = "default!test"; |
| 71 |
assertEq(ifNull(null, DefaultTestVal), DefaultTestVal); |
| 72 |
for (let val of WasmNonNullExternrefValues) { |
| 73 |
assertEq(ifNull(val, DefaultTestVal), val); |
| 74 |
} |