summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/wasm/jsapi/exception/getArg.tentative.any.js
blob: f0a568a857f0e733035675a0c0d97d7214ac5d61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// META: global=window,dedicatedworker,jsshell
// META: script=/wasm/jsapi/memory/assertions.js

test(() => {
  const tag = new WebAssembly.Tag({ parameters: [] });
  const exn = new WebAssembly.Exception(tag, []);
  assert_throws_js(TypeError, () => exn.getArg());
  assert_throws_js(TypeError, () => exn.getArg(tag));
}, "Missing arguments");

test(() => {
  const invalidValues = [undefined, null, true, "", Symbol(), 1, {}];
  const tag = new WebAssembly.Tag({ parameters: [] });
  const exn = new WebAssembly.Exception(tag, []);
  for (argument of invalidValues) {
    assert_throws_js(TypeError, () => exn.getArg(argument, 0));
  }
}, "Invalid exception argument");

test(() => {
  const tag = new WebAssembly.Tag({ parameters: [] });
  const exn = new WebAssembly.Exception(tag, []);
  assert_throws_js(RangeError, () => exn.getArg(tag, 1));
}, "Index out of bounds");

test(() => {
  const outOfRangeValues = [
    undefined,
    NaN,
    Infinity,
    -Infinity,
    -1,
    0x100000000,
    0x1000000000,
    "0x100000000",
    {
      valueOf() {
        return 0x100000000;
      },
    },
  ];

  const tag = new WebAssembly.Tag({ parameters: [] });
  const exn = new WebAssembly.Exception(tag, []);
  for (const value of outOfRangeValues) {
    assert_throws_js(RangeError, () => exn.getArg(tag, value));
  }
}, "Getting out-of-range argument");

test(() => {
  const tag = new WebAssembly.Tag({ parameters: ["i32"] });
  const exn = new WebAssembly.Exception(tag, [42]);
  assert_equals(exn.getArg(tag, 0), 42);
}, "getArg");