(module
(func (export "select_simple") (result i32)
;; load two values onto the stack
i32.const 10
i32.const 20
;; change to `1` (true) to get the first value (`10`)
i32.const 0
select
)
(func (export "select_externref") (param $value externref) (param $condition i32) (result externref)
;; this is "select t", the explicitly typed variant
ref.null extern
local.get $value
local.get $condition
select (result externref)
)
)
var url = "{%wasm-url%}";
await WebAssembly.instantiateStreaming(
fetch(url)
).then(result => {
const { select_simple, select_externref } = result.instance.exports;
console.log(select_simple());
// if the second parameter is zero, returns the first paramater (which may be an arbitrary JS value)
const map = new Map();
console.log(select_externref(map, 0)); // logs Map {}
console.log(select_externref(map, -1)); // logs null
});