11cb0ef41Sopenharmony_ci// META: global=window,dedicatedworker,jsshell
21cb0ef41Sopenharmony_ci// META: script=/wasm/jsapi/memory/assertions.js
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_citest(() => {
51cb0ef41Sopenharmony_ci  const tag = new WebAssembly.Tag({ parameters: [] });
61cb0ef41Sopenharmony_ci  const exn = new WebAssembly.Exception(tag, []);
71cb0ef41Sopenharmony_ci  assert_throws_js(TypeError, () => exn.getArg());
81cb0ef41Sopenharmony_ci  assert_throws_js(TypeError, () => exn.getArg(tag));
91cb0ef41Sopenharmony_ci}, "Missing arguments");
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_citest(() => {
121cb0ef41Sopenharmony_ci  const invalidValues = [undefined, null, true, "", Symbol(), 1, {}];
131cb0ef41Sopenharmony_ci  const tag = new WebAssembly.Tag({ parameters: [] });
141cb0ef41Sopenharmony_ci  const exn = new WebAssembly.Exception(tag, []);
151cb0ef41Sopenharmony_ci  for (argument of invalidValues) {
161cb0ef41Sopenharmony_ci    assert_throws_js(TypeError, () => exn.getArg(argument, 0));
171cb0ef41Sopenharmony_ci  }
181cb0ef41Sopenharmony_ci}, "Invalid exception argument");
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_citest(() => {
211cb0ef41Sopenharmony_ci  const tag = new WebAssembly.Tag({ parameters: [] });
221cb0ef41Sopenharmony_ci  const exn = new WebAssembly.Exception(tag, []);
231cb0ef41Sopenharmony_ci  assert_throws_js(RangeError, () => exn.getArg(tag, 1));
241cb0ef41Sopenharmony_ci}, "Index out of bounds");
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_citest(() => {
271cb0ef41Sopenharmony_ci  const outOfRangeValues = [
281cb0ef41Sopenharmony_ci    undefined,
291cb0ef41Sopenharmony_ci    NaN,
301cb0ef41Sopenharmony_ci    Infinity,
311cb0ef41Sopenharmony_ci    -Infinity,
321cb0ef41Sopenharmony_ci    -1,
331cb0ef41Sopenharmony_ci    0x100000000,
341cb0ef41Sopenharmony_ci    0x1000000000,
351cb0ef41Sopenharmony_ci    "0x100000000",
361cb0ef41Sopenharmony_ci    {
371cb0ef41Sopenharmony_ci      valueOf() {
381cb0ef41Sopenharmony_ci        return 0x100000000;
391cb0ef41Sopenharmony_ci      },
401cb0ef41Sopenharmony_ci    },
411cb0ef41Sopenharmony_ci  ];
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ci  const tag = new WebAssembly.Tag({ parameters: [] });
441cb0ef41Sopenharmony_ci  const exn = new WebAssembly.Exception(tag, []);
451cb0ef41Sopenharmony_ci  for (const value of outOfRangeValues) {
461cb0ef41Sopenharmony_ci    assert_throws_js(RangeError, () => exn.getArg(tag, value));
471cb0ef41Sopenharmony_ci  }
481cb0ef41Sopenharmony_ci}, "Getting out-of-range argument");
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_citest(() => {
511cb0ef41Sopenharmony_ci  const tag = new WebAssembly.Tag({ parameters: ["i32"] });
521cb0ef41Sopenharmony_ci  const exn = new WebAssembly.Exception(tag, [42]);
531cb0ef41Sopenharmony_ci  assert_equals(exn.getArg(tag, 0), 42);
541cb0ef41Sopenharmony_ci}, "getArg");
55