(call_indirect (type $empty)
local.get 0)
end
(; nothing threw ;)
i32.const -1 return
end
(; $handleUnknown ;)
drop
i32.const 3 return
end
(; $handleB ;)
drop return
end
(; $handleA ;)
drop return
)
)`).exports; // Throwing A results in 1 from the payload from the catch
assertEq(test(0), 1); // Throwing B results in 2 from the payload from the catch
assertEq(test(1), 2); // Throwing C results in 3 from the constant in the catch_all
assertEq(test(2), 3); // Not throwing anything gets -1 from the fallthrough
assertEq(test(3), -1);
}
// Test try_table catching exceptions without capturing the exnref
{
let {test} = wasmEvalText(`(module
(tag $A (param i32))
(tag $B (param i32))
(tag $C)
(call_indirect (type $empty)
local.get 0)
end
(; nothing threw ;)
i32.const -1 return
end
(; $handleUnknown ;)
i32.const 3 return
end
(; $handleB ;) return
end
(; $handleA ;) return
)
)`).exports; // Throwing A results in 1 from the payload from the catch
assertEq(test(0), 1); // Throwing B results in 2 from the payload from the catch
assertEq(test(1), 2); // Throwing C results in 3 from the constant in the catch_all
assertEq(test(2), 3); // Not throwing anything gets -1 from the fallthrough
assertEq(test(3), -1);
}
// Test try_table catching exceptions with various payloads
{
let maxResults1 = Array.from(Array(999).keys()); const TESTS = [
['i32', 'i32.const', [0]],
['i32 '.repeat(999), 'i32.const', maxResults1],
['i64', 'i64.const', [0]],
['i64 '.repeat(999), 'i64.const', maxResults1],
['f32', 'f32.const', [0]],
['f32 '.repeat(999), 'f32.const', maxResults1],
['f64', 'f64.const', [0]],
['f64 '.repeat(999), 'f64.const', maxResults1],
]; for (let [types, constructor, params] of TESTS) {
let {testCatch, testCatchRef} = wasmEvalText(`(module
(tag $E (param ${types}))
// Test try_table as target of a delegate
{
let {test} = wasmEvalText(`(module
(tag $E)
(func (export "test")
block $good
block $bad
try_table $a (catch_all $good) try try throw $E
delegate $a catch $E
br $bad
end
end
end
unreachable
end
)
)`).exports;
test();
}
// Try table cannot be target of rethrow
{
wasmFailValidateText(`(module
(func
try_table (catch_all 0) rethrow 0 end
)
)`, /rethrow target/);
}
// Test try_table catching and rethrowing JS exceptions
{
let tag = new WebAssembly.Tag({parameters: []});
let exn = new WebAssembly.Exception(tag, []);
let values = [...WasmExternrefValues, exn]; function throwJS(value) { throw value;
}
let {test} = wasmEvalText(`(module
(import"""tag" (tag $tag))
(import"""throwJS" (func $throwJS (param externref)))
(func $innerRethrow (param externref)
(block (result exnref)
try_table (catch_ref $tag 0) (catch_all_ref 0)
local.get 0
call $throwJS
end return
)
throw_ref
)
(func (export "test") (param externref)
(block (result exnref)
try_table (catch_ref $tag 0) (catch_all_ref 0)
local.get 0
call $innerRethrow
end return
)
throw_ref
)
)`, {"": {tag, throwJS}}).exports;
for (let value of values) { try {
test(value);
assertEq(true, false);
} catch (thrownValue) {
assertEq(thrownValue, value);
}
}
}
// WebAssembly.JSTag property is read-only and enumerable
WebAssembly.JSTag = null;
assertEq(WebAssembly.JSTag !== null, true);
assertEq(WebAssembly.propertyIsEnumerable('JSTag'), true);
// Test try_table catching JS exceptions and unpacking them using JSTag
{
let tag = WebAssembly.JSTag;
let values = [...WasmExternrefValues]; function throwJS(value) { throw value;
}
let {test} = wasmEvalText(`(module
(import"""tag" (tag $tag (param externref)))
(import"""throwJS" (func $throwJS (param externref)))
(func (export "test") (param externref) (result externref)
try_table (catch $tag 0)
local.get 0
call $throwJS
end
unreachable
)
)`, {"": {tag, throwJS}}).exports;
for (let value of values) {
assertEq(value, test(value));
}
}
// Test try_table catching JS exceptions using JSTag and unpacking them using JSTag
{
let tag = WebAssembly.JSTag;
let values = [...WasmExternrefValues]; function throwJS(value) { thrownew WebAssembly.Exception(tag, [value]);
}
let {test} = wasmEvalText(`(module
(import"""tag" (tag $tag (param externref)))
(import"""throwJS" (func $throwJS (param externref)))
(func (export "test") (param externref) (result externref)
try_table (catch $tag 0)
local.get 0
call $throwJS
end
unreachable
)
)`, {"": {tag, throwJS}}).exports;
for (let value of values) {
assertEq(value, test(value));
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.