• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// META: global=window,dedicatedworker,jsshell
2// META: script=/wasm/jsapi/assertions.js
3
4function addNumbers(x, y, z) {
5    return x+y+z;
6}
7
8function doNothing() {}
9
10function assert_function(functype, func) {
11    var wasmFunc = new WebAssembly.Function(functype, func);
12    assert_equals(functype.parameters.length, wasmFunc.type().parameters.length);
13    for(let i = 0; i < functype.parameters.length; i++) {
14        assert_equals(functype.parameters[i], wasmFunc.type().parameters[i]);
15    }
16    assert_equals(functype.results.length, wasmFunc.type().results.length);
17    for(let i = 0; i < functype.results.length; i++) {
18        assert_equals(functype.results[i], wasmFunc.type().results[i]);
19    }
20}
21
22test(() => {
23    assert_function({results: [], parameters: []}, doNothing);
24}, "Check empty results and parameters")
25
26test(() => {
27    assert_function({results: ["f64"], parameters: ["i32", "i64", "f32"]}, addNumbers)
28}, "Check all types")
29