• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// META: global=window,dedicatedworker,jsshell
2// META: script=/wasm/jsapi/assertions.js
3
4function addxy(x, y) {
5    return x + y
6}
7
8test(() => {
9    assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
10    assert_function_name(WebAssembly.Function, "Function", "WebAssembly.Function");
11}, "name");
12
13test(() => {
14    assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
15    assert_function_length(WebAssembly.Function, 2, "WebAssembly.Function");
16}, "length");
17
18test(() => {
19    assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
20    assert_throws_js(TypeError, () => new WebAssembly.Function());
21    const argument = {parameters: [], results: []};
22    assert_throws_js(TypeError, () => new WebAssembly.Function(argument));
23}, "Too few arguments");
24
25test(() => {
26    assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
27    const arguments = [{parameters: ["i32", "i32"], results: ["i32"]}, addxy];
28    assert_throws_js(TypeError, () => WebAssembly.Function(...arguments));
29}, "Calling");
30
31test(() => {
32    assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
33    var fun = new WebAssembly.Function({parameters: ["i32", "i32"], results: ["i32"]}, addxy);
34    assert_true(fun instanceof WebAssembly.Function)
35}, "construct with JS function")
36
37test(() => {
38    assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
39    assert_throws_js(TypeError, () => new WebAssembly.Function({parameters: []}, addxy))
40}, "fail with missing results")
41
42test(() => {
43    assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
44    assert_throws_js(TypeError, () => new WebAssembly.Function({results: []}, addxy))
45}, "fail with missing parameters")
46
47test(() => {
48    assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
49    assert_throws_js(TypeError, () => new WebAssembly.Function({parameters: [1], results: [true]}, addxy))
50}, "fail with non-string parameters & results")
51
52test(() => {
53    assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
54    assert_throws_js(TypeError, () => new WebAssembly.Function({parameters: ["invalid"], results: ["invalid"]}, addxy))
55}, "fail with non-existent parameter and result type")
56
57test(() => {
58    assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
59    assert_throws_js(TypeError, () => new WebAssembly.Function({parameters: [], results: []}, 72))
60}, "fail with non-function object")
61
62test(() => {
63    assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
64    assert_throws_js(TypeError, () => new WebAssembly.Function({parameters: [], results: []}, {}))
65}, "fail to construct with non-callable object")
66