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