1// META: global=window,dedicatedworker,jsshell
2// META: script=/wasm/jsapi/assertions.js
3
4test(() => {
5  assert_function_name(
6    WebAssembly.Exception,
7    "Exception",
8    "WebAssembly.Exception"
9  );
10}, "name");
11
12test(() => {
13  assert_function_length(WebAssembly.Exception, 1, "WebAssembly.Exception");
14}, "length");
15
16test(() => {
17  assert_throws_js(TypeError, () => new WebAssembly.Exception());
18}, "No arguments");
19
20test(() => {
21  const tag = new WebAssembly.Tag({ parameters: [] });
22  assert_throws_js(TypeError, () => WebAssembly.Exception(tag));
23}, "Calling");
24
25test(() => {
26  const invalidArguments = [
27    undefined,
28    null,
29    false,
30    true,
31    "",
32    "test",
33    Symbol(),
34    1,
35    NaN,
36    {},
37  ];
38  for (const invalidArgument of invalidArguments) {
39    assert_throws_js(
40      TypeError,
41      () => new WebAssembly.Exception(invalidArgument),
42      `new Exception(${format_value(invalidArgument)})`
43    );
44  }
45}, "Invalid descriptor argument");
46
47test(() => {
48  const typesAndArgs = [
49    ["i32", 123n],
50    ["i32", Symbol()],
51    ["f32", 123n],
52    ["f64", 123n],
53    ["i64", undefined],
54  ];
55  for (const typeAndArg of typesAndArgs) {
56    const tag = new WebAssembly.Tag({ parameters: [typeAndArg[0]] });
57    assert_throws_js(
58      TypeError,
59      () => new WebAssembly.Exception(tag, typeAndArg[1])
60    );
61  }
62}, "Invalid exception argument");
63