|
| 1 | +// META: global=window,dedicatedworker,jsshell |
| 2 | +// META: script=/wasm/jsapi/memory/assertions.js |
| 3 | + |
| 4 | +test(() => { |
| 5 | + const exn = new WebAssembly.Exception({ "parameters": [] }) |
| 6 | + const runtimeExn = new WebAssembly.RuntimeException(exn); |
| 7 | + assert_throws_js(TypeError, () => runtimeExn.getArg()); |
| 8 | + assert_throws_js(TypeError, () => runtimeExn.getArg(exn)); |
| 9 | +}, "Missing arguments"); |
| 10 | + |
| 11 | +test(() => { |
| 12 | + const invalidValues = [ |
| 13 | + undefined, |
| 14 | + null, |
| 15 | + true, |
| 16 | + "", |
| 17 | + Symbol(), |
| 18 | + 1, |
| 19 | + {} |
| 20 | + ]; |
| 21 | + const exn = new WebAssembly.Exception({ "parameters": [] }) |
| 22 | + const runtimeExn = new WebAssembly.RuntimeException(exn); |
| 23 | + for (argument of invalidValues) { |
| 24 | + assert_throws_js(TypeError, () => runtimeExn.getArg(argument, 0)); |
| 25 | + } |
| 26 | +}, "Invalid exception argument"); |
| 27 | + |
| 28 | +test(() => { |
| 29 | + const exn = new WebAssembly.Exception({ "parameters": [] }) |
| 30 | + const runtimeExn = new WebAssembly.RuntimeException(exn); |
| 31 | + assert_throws_js(RangeError, () => runtimeExn.getArg(exn, 1)); |
| 32 | +}, "Index out of bounds"); |
| 33 | + |
| 34 | +test(() => { |
| 35 | + const outOfRangeValues = [ |
| 36 | + undefined, |
| 37 | + NaN, |
| 38 | + Infinity, |
| 39 | + -Infinity, |
| 40 | + -1, |
| 41 | + 0x100000000, |
| 42 | + 0x1000000000, |
| 43 | + "0x100000000", |
| 44 | + { valueOf() { return 0x100000000; } }, |
| 45 | + ]; |
| 46 | + |
| 47 | + const exn = new WebAssembly.Exception({ "parameters": [] }) |
| 48 | + const runtimeExn = new WebAssembly.RuntimeException(exn); |
| 49 | + for (const value of outOfRangeValues) { |
| 50 | + assert_throws_js(TypeError, () => runtimeExn.getArg(exn, value)); |
| 51 | + } |
| 52 | +}, "Getting out-of-range argument"); |
| 53 | + |
| 54 | +test(() => { |
| 55 | + const exn = new WebAssembly.Exception({ "parameters": ["i32"] }) |
| 56 | + const runtimeExn = new WebAssembly.RuntimeException(exn, 42); |
| 57 | + assert_equals(runtimeExn.getArg(exn, 0), 42); |
| 58 | +}, "getArg"); |
0 commit comments