Tests: Import the call-indirect wpt wasm test

This found some broken wasm-js implementations, so let's make sure it
doesn't break again.
This commit is contained in:
Ali Mohammad Pur 2025-05-21 18:11:19 +02:00 committed by Tim Ledbetter
parent 83995ada1f
commit a3b913bf91
Notes: github-actions[bot] 2025-05-22 06:36:57 +00:00
4 changed files with 1255 additions and 0 deletions

View file

@ -0,0 +1,291 @@
Harness status: OK
Found 286 tests
286 Pass
Pass #1 Reinitialize the default imports
Pass #2 Test that WebAssembly compilation fails
Pass #3 Test that WebAssembly compilation fails
Pass #4 Test that WebAssembly compilation fails
Pass #5 Test that WebAssembly compilation fails
Pass #6 Test that WebAssembly compilation fails
Pass #7 Test that WebAssembly compilation fails
Pass #8 Test that WebAssembly compilation fails
Pass #9 Test that WebAssembly compilation fails
Pass #10 Test that WebAssembly compilation fails
Pass #11 Test that WebAssembly compilation fails
Pass #12 Test that WebAssembly compilation fails
Pass #13 Test that WebAssembly compilation fails
Pass #14 Test that WebAssembly compilation fails
Pass #15 Test that WebAssembly compilation fails
Pass #16 Test that WebAssembly compilation fails
Pass #17 Test that WebAssembly compilation fails
Pass #18 Test that WebAssembly compilation fails
Pass #19 Test that WebAssembly compilation fails
Pass #20 Test that WebAssembly compilation fails
Pass #21 Test that WebAssembly compilation fails
Pass #22 Test that WebAssembly compilation fails
Pass #23 Test that WebAssembly compilation fails
Pass #24 Test that WebAssembly compilation fails
Pass #25 Test that WebAssembly compilation fails
Pass #26 Test that WebAssembly compilation fails
Pass #27 Test that WebAssembly compilation fails
Pass #28 Test that WebAssembly compilation fails
Pass #29 Test that WebAssembly compilation fails
Pass #30 Test that WebAssembly compilation fails
Pass #31 Test that WebAssembly compilation fails
Pass #32 Test that WebAssembly compilation fails
Pass #33 Test that WebAssembly compilation fails
Pass #34 Test that WebAssembly compilation fails
Pass #35 Test that WebAssembly compilation fails
Pass #36 Test that WebAssembly compilation fails
Pass #37 Reinitialize the default imports
Pass #38 Test that WebAssembly instantiation succeeds
Pass #39 Test that a WebAssembly code returns a specific result
Pass #40 Test that WebAssembly instantiation succeeds
Pass #41 Run a WebAssembly test without special assertions
Pass #42 Test that WebAssembly instantiation succeeds
Pass #43 Run a WebAssembly test without special assertions
Pass #44 Test that WebAssembly instantiation succeeds
Pass #45 Run a WebAssembly test without special assertions
Pass #46 Test that WebAssembly instantiation succeeds
Pass #47 Run a WebAssembly test without special assertions
Pass #48 Test that WebAssembly instantiation succeeds
Pass #49 Run a WebAssembly test without special assertions
Pass #50 Test that a WebAssembly code returns a specific result
Pass #51 Test that WebAssembly instantiation succeeds
Pass #52 Run a WebAssembly test without special assertions
Pass #53 Test that WebAssembly instantiation succeeds
Pass #54 Run a WebAssembly test without special assertions
Pass #55 Test that WebAssembly instantiation succeeds
Pass #56 Run a WebAssembly test without special assertions
Pass #57 Test that a WebAssembly code returns a specific result
Pass #58 Test that WebAssembly instantiation succeeds
Pass #59 Run a WebAssembly test without special assertions
Pass #60 Test that WebAssembly instantiation succeeds
Pass #61 Run a WebAssembly test without special assertions
Pass #62 Test that WebAssembly instantiation succeeds
Pass #63 Run a WebAssembly test without special assertions
Pass #64 Test that WebAssembly instantiation succeeds
Pass #65 Run a WebAssembly test without special assertions
Pass #66 Test that WebAssembly instantiation succeeds
Pass #67 Run a WebAssembly test without special assertions
Pass #68 Test that WebAssembly instantiation succeeds
Pass #69 Run a WebAssembly test without special assertions
Pass #70 Test that WebAssembly instantiation succeeds
Pass #71 Run a WebAssembly test without special assertions
Pass #72 Test that WebAssembly instantiation succeeds
Pass #73 Run a WebAssembly test without special assertions
Pass #74 Test that WebAssembly instantiation succeeds
Pass #75 Run a WebAssembly test without special assertions
Pass #76 Test that WebAssembly instantiation succeeds
Pass #77 Run a WebAssembly test without special assertions
Pass #78 Test that WebAssembly instantiation succeeds
Pass #79 Run a WebAssembly test without special assertions
Pass #80 Test that WebAssembly instantiation succeeds
Pass #81 Test that a WebAssembly code traps
Pass #82 Test that WebAssembly instantiation succeeds
Pass #83 Test that a WebAssembly code traps
Pass #84 Test that WebAssembly instantiation succeeds
Pass #85 Test that a WebAssembly code traps
Pass #86 Test that WebAssembly instantiation succeeds
Pass #87 Test that a WebAssembly code traps
Pass #88 Test that WebAssembly instantiation succeeds
Pass #89 Test that a WebAssembly code traps
Pass #90 Test that WebAssembly instantiation succeeds
Pass #91 Run a WebAssembly test without special assertions
Pass #92 Test that WebAssembly instantiation succeeds
Pass #93 Run a WebAssembly test without special assertions
Pass #94 Test that WebAssembly instantiation succeeds
Pass #95 Run a WebAssembly test without special assertions
Pass #96 Test that WebAssembly instantiation succeeds
Pass #97 Run a WebAssembly test without special assertions
Pass #98 Test that WebAssembly instantiation succeeds
Pass #99 Test that a WebAssembly code traps
Pass #100 Test that WebAssembly instantiation succeeds
Pass #101 Test that a WebAssembly code traps
Pass #102 Test that a WebAssembly code returns a specific result
Pass #103 Test that a WebAssembly code returns a specific result
Pass #104 Test that a WebAssembly code returns a specific result
Pass #105 Test that a WebAssembly code returns a specific result
Pass #106 Test that a WebAssembly code traps
Pass #107 Test that a WebAssembly code traps
Pass #108 Test that WebAssembly instantiation succeeds
Pass #109 Run a WebAssembly test without special assertions
Pass #110 Test that WebAssembly instantiation succeeds
Pass #111 Run a WebAssembly test without special assertions
Pass #112 Test that WebAssembly instantiation succeeds
Pass #113 Run a WebAssembly test without special assertions
Pass #114 Test that WebAssembly instantiation succeeds
Pass #115 Run a WebAssembly test without special assertions
Pass #116 Test that WebAssembly instantiation succeeds
Pass #117 Test that a WebAssembly code traps
Pass #118 Test that WebAssembly instantiation succeeds
Pass #119 Test that a WebAssembly code traps
Pass #120 Test that WebAssembly instantiation succeeds
Pass #121 Run a WebAssembly test without special assertions
Pass #122 Test that WebAssembly instantiation succeeds
Pass #123 Run a WebAssembly test without special assertions
Pass #124 Test that WebAssembly instantiation succeeds
Pass #125 Run a WebAssembly test without special assertions
Pass #126 Test that WebAssembly instantiation succeeds
Pass #127 Run a WebAssembly test without special assertions
Pass #128 Test that WebAssembly instantiation succeeds
Pass #129 Test that a WebAssembly code traps
Pass #130 Test that WebAssembly instantiation succeeds
Pass #131 Test that a WebAssembly code traps
Pass #132 Test that WebAssembly instantiation succeeds
Pass #133 Run a WebAssembly test without special assertions
Pass #134 Test that WebAssembly instantiation succeeds
Pass #135 Run a WebAssembly test without special assertions
Pass #136 Test that WebAssembly instantiation succeeds
Pass #137 Run a WebAssembly test without special assertions
Pass #138 Test that WebAssembly instantiation succeeds
Pass #139 Run a WebAssembly test without special assertions
Pass #140 Test that a WebAssembly code returns a specific result
Pass #141 Test that a WebAssembly code returns a specific result
Pass #142 Test that a WebAssembly code returns a specific result
Pass #143 Test that a WebAssembly code returns a specific result
Pass #144 Test that WebAssembly instantiation succeeds
Pass #145 Run a WebAssembly test without special assertions
Pass #146 Test that WebAssembly instantiation succeeds
Pass #147 Run a WebAssembly test without special assertions
Pass #148 Test that WebAssembly instantiation succeeds
Pass #149 Run a WebAssembly test without special assertions
Pass #150 Test that WebAssembly instantiation succeeds
Pass #151 Run a WebAssembly test without special assertions
Pass #152 Test that WebAssembly instantiation succeeds
Pass #153 Run a WebAssembly test without special assertions
Pass #154 Test that WebAssembly instantiation succeeds
Pass #155 Run a WebAssembly test without special assertions
Pass #156 Test that WebAssembly instantiation succeeds
Pass #157 Run a WebAssembly test without special assertions
Pass #158 Test that WebAssembly instantiation succeeds
Pass #159 Run a WebAssembly test without special assertions
Pass #160 Test that WebAssembly instantiation succeeds
Pass #161 Run a WebAssembly test without special assertions
Pass #162 Test that WebAssembly instantiation succeeds
Pass #163 Run a WebAssembly test without special assertions
Pass #164 Test that WebAssembly instantiation succeeds
Pass #165 Run a WebAssembly test without special assertions
Pass #166 Test that WebAssembly instantiation succeeds
Pass #167 Run a WebAssembly test without special assertions
Pass #168 Test that WebAssembly instantiation succeeds
Pass #169 Run a WebAssembly test without special assertions
Pass #170 Test that a WebAssembly code returns a specific result
Pass #171 Test that a WebAssembly code returns a specific result
Pass #172 Test that a WebAssembly code returns a specific result
Pass #173 Test that a WebAssembly code returns a specific result
Pass #174 Test that a WebAssembly code returns a specific result
Pass #175 Test that WebAssembly instantiation succeeds
Pass #176 Run a WebAssembly test without special assertions
Pass #177 Test that WebAssembly instantiation succeeds
Pass #178 Run a WebAssembly test without special assertions
Pass #179 Test that WebAssembly instantiation succeeds
Pass #180 Run a WebAssembly test without special assertions
Pass #181 Test that WebAssembly instantiation succeeds
Pass #182 Run a WebAssembly test without special assertions
Pass #183 Test that WebAssembly instantiation succeeds
Pass #184 Run a WebAssembly test without special assertions
Pass #185 Test that WebAssembly instantiation succeeds
Pass #186 Run a WebAssembly test without special assertions
Pass #187 Test that WebAssembly instantiation succeeds
Pass #188 Run a WebAssembly test without special assertions
Pass #189 Test that WebAssembly instantiation succeeds
Pass #190 Run a WebAssembly test without special assertions
Pass #191 Test that WebAssembly instantiation succeeds
Pass #192 Run a WebAssembly test without special assertions
Pass #193 Test that WebAssembly instantiation succeeds
Pass #194 Run a WebAssembly test without special assertions
Pass #195 Test that a WebAssembly code returns a specific result
Pass #196 Test that a WebAssembly code returns a specific result
Pass #197 Test that a WebAssembly code returns a specific result
Pass #198 Test that a WebAssembly code returns a specific result
Pass #199 Test that a WebAssembly code returns a specific result
Pass #200 Test that a WebAssembly code returns a specific result
Pass #201 Test that a WebAssembly code returns a specific result
Pass #202 Test that a WebAssembly code returns a specific result
Pass #203 Test that a WebAssembly code exhauts the stack space
Pass #204 Test that a WebAssembly code exhauts the stack space
Pass #205 Test that a WebAssembly code returns a specific result
Pass #206 Test that a WebAssembly code returns a specific result
Pass #207 Test that a WebAssembly code returns a specific result
Pass #208 Test that a WebAssembly code returns a specific result
Pass #209 Test that WebAssembly instantiation succeeds
Pass #210 Run a WebAssembly test without special assertions
Pass #211 Test that a WebAssembly code returns a specific result
Pass #212 Test that WebAssembly instantiation succeeds
Pass #213 Run a WebAssembly test without special assertions
Pass #214 Test that a WebAssembly code returns a specific result
Pass #215 Test that a WebAssembly code returns a specific result
Pass #216 Test that a WebAssembly code returns a specific result
Pass #217 Test that a WebAssembly code returns a specific result
Pass #218 Test that a WebAssembly code returns a specific result
Pass #219 Test that a WebAssembly code returns a specific result
Pass #220 Test that WebAssembly instantiation succeeds
Pass #221 Run a WebAssembly test without special assertions
Pass #222 Test that WebAssembly instantiation succeeds
Pass #223 Run a WebAssembly test without special assertions
Pass #224 Test that WebAssembly instantiation succeeds
Pass #225 Run a WebAssembly test without special assertions
Pass #226 Test that WebAssembly instantiation succeeds
Pass #227 Run a WebAssembly test without special assertions
Pass #228 Test that a WebAssembly code returns a specific result
Pass #229 Test that WebAssembly instantiation succeeds
Pass #230 Run a WebAssembly test without special assertions
Pass #231 Test that a WebAssembly code returns a specific result
Pass #232 Test that a WebAssembly code returns a specific result
Pass #233 Test that a WebAssembly code returns a specific result
Pass #234 Test that a WebAssembly code returns a specific result
Pass #235 Test that a WebAssembly code returns a specific result
Pass #236 Test that WebAssembly instantiation succeeds
Pass #237 Run a WebAssembly test without special assertions
Pass #238 Test that WebAssembly instantiation succeeds
Pass #239 Test that a WebAssembly code returns a specific result
Pass #240 Test that a WebAssembly code returns a specific result
Pass #241 Test that a WebAssembly code traps
Pass #242 Test that a WebAssembly code returns a specific result
Pass #243 Test that a WebAssembly code returns a specific result
Pass #244 Test that a WebAssembly code returns a specific result
Pass #245 Test that a WebAssembly code traps
Pass #246 Test that a WebAssembly code returns a specific result
Pass #247 Test that a WebAssembly code returns a specific result
Pass #248 Test that a WebAssembly code traps
Pass #249 Test that a WebAssembly code traps
Pass #250 Test that a WebAssembly code traps
Pass #251 Test that WebAssembly compilation fails
Pass #252 Test that WebAssembly compilation fails
Pass #253 Test that WebAssembly compilation fails
Pass #254 Test that WebAssembly compilation fails
Pass #255 Test that WebAssembly compilation fails
Pass #256 Test that WebAssembly compilation fails
Pass #257 Test that WebAssembly compilation fails
Pass #258 Test that WebAssembly compilation fails
Pass #259 Test that WebAssembly compilation fails
Pass #260 Test that WebAssembly compilation fails
Pass #261 Test that WebAssembly compilation fails
Pass #262 Test that WebAssembly compilation fails
Pass #263 Test that WebAssembly compilation fails
Pass #264 Test that WebAssembly compilation fails
Pass #265 Test that WebAssembly compilation fails
Pass #266 Test that WebAssembly compilation fails
Pass #267 Test that WebAssembly compilation fails
Pass #268 Test that WebAssembly compilation fails
Pass #269 Test that WebAssembly compilation fails
Pass #270 Test that WebAssembly compilation fails
Pass #271 Test that WebAssembly compilation fails
Pass #272 Test that WebAssembly compilation fails
Pass #273 Test that WebAssembly compilation fails
Pass #274 Test that WebAssembly compilation fails
Pass #275 Test that WebAssembly compilation fails
Pass #276 Test that WebAssembly compilation fails
Pass #277 Test that WebAssembly compilation fails
Pass #278 Test that WebAssembly compilation fails
Pass #279 Test that WebAssembly compilation fails
Pass #280 Test that WebAssembly compilation fails
Pass #281 Test that WebAssembly compilation fails
Pass #282 Test that WebAssembly compilation fails
Pass #283 Test that WebAssembly compilation fails
Pass #284 Test that WebAssembly compilation fails
Pass #285 Test that WebAssembly compilation fails
Pass #286 Test that WebAssembly instantiation succeeds

View file

@ -0,0 +1,16 @@
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>WebAssembly Web Platform Test</title>
</head>
<body>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="./js/harness/async_index.js"></script>
<div id=log></div>
<script src="./js/call_indirect.wast.js"></script>
</body>
</html>

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,429 @@
/*
* Copyright 2018 WebAssembly Community Group participants
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
"use strict";
let testNum = (function() {
let count = 1;
return function() {
return `#${count++} `;
};
})();
function uniqueTest(func, desc) {
test(func, testNum() + desc);
}
// WPT's assert_throw uses a list of predefined, hardcoded known errors. Since
// it is not aware of the WebAssembly error types (yet), implement our own
// version.
function assertThrows(func, err) {
let caught = false;
try {
func();
} catch (e) {
assert_true(
e instanceof err,
`expected ${err.name}, observed ${e.constructor.name}`
);
caught = true;
}
assert_true(caught, testNum() + "assertThrows must catch any error.");
}
/******************************************************************************
***************************** WAST HARNESS ************************************
******************************************************************************/
const EXPECT_INVALID = false;
/* DATA **********************************************************************/
let externrefs = {};
let externsym = Symbol("externref");
function externref(s) {
if (! (s in externrefs)) externrefs[s] = {[externsym]: s};
return externrefs[s];
}
function is_externref(x) {
return (x !== null && externsym in x) ? 1 : 0;
}
function is_funcref(x) {
return typeof x === "function" ? 1 : 0;
}
function eq_externref(x, y) {
return x === y ? 1 : 0;
}
function eq_funcref(x, y) {
return x === y ? 1 : 0;
}
// Default imports.
var registry = {};
// All tests run asynchronously and return their results as promises. To ensure
// that all tests execute in the correct order, we chain the promises together
// so that a test is only executed when all previous tests have finished their
// execution.
let chain = Promise.resolve();
// Resets the registry between two different WPT tests.
function reinitializeRegistry() {
if (typeof WebAssembly === "undefined") return;
chain = chain.then(_ => {
let spectest = {
externref: externref,
is_externref: is_externref,
is_funcref: is_funcref,
eq_externref: eq_externref,
eq_funcref: eq_funcref,
print: console.log.bind(console),
print_i32: console.log.bind(console),
print_i64: console.log.bind(console),
print_i32_f32: console.log.bind(console),
print_f64_f64: console.log.bind(console),
print_f32: console.log.bind(console),
print_f64: console.log.bind(console),
global_i32: 666,
global_i64: 666n,
global_f32: 666.6,
global_f64: 666.6,
table: new WebAssembly.Table({
initial: 10,
maximum: 20,
element: "anyfunc"
}),
memory: new WebAssembly.Memory({ initial: 1, maximum: 2 })
};
let handler = {
get(target, prop) {
return prop in target ? target[prop] : {};
}
};
registry = new Proxy({ spectest }, handler);
});
// This function is called at the end of every generated js test file. By
// adding the chain as a promise_test here we make sure that the WPT harness
// waits for all tests in the chain to finish.
promise_test(_ => chain, testNum() + "Reinitialize the default imports");
}
reinitializeRegistry();
/* WAST POLYFILL *************************************************************/
function binary(bytes) {
let buffer = new ArrayBuffer(bytes.length);
let view = new Uint8Array(buffer);
for (let i = 0; i < bytes.length; ++i) {
view[i] = bytes.charCodeAt(i);
}
return buffer;
}
/**
* Returns a compiled module, or throws if there was an error at compilation.
*/
function module(bytes, valid = true) {
const test = valid
? "Test that WebAssembly compilation succeeds"
: "Test that WebAssembly compilation fails";
const loc = new Error().stack.toString().replace("Error", "");
let buffer = binary(bytes);
let validated = WebAssembly.validate(buffer);
uniqueTest(_ => {
assert_equals(valid, validated);
}, test);
chain = chain.then(_ => WebAssembly.compile(buffer)).then(
module => {
uniqueTest(_ => {
assert_true(valid, loc);
}, test);
return module;
},
error => {
uniqueTest(_ => {
assert_true(
!valid,
`WebAssembly.compile failed unexpectedly with ${error} at {loc}`
);
}, test);
}
);
return chain;
}
function assert_invalid(bytes) {
module(bytes, EXPECT_INVALID);
}
const assert_malformed = assert_invalid;
function instance(bytes, imports, valid = true) {
const test = valid
? "Test that WebAssembly instantiation succeeds"
: "Test that WebAssembly instantiation fails";
const loc = new Error().stack.toString().replace("Error", "");
chain = Promise.all([imports, chain])
.then(values => {
let imports = values[0] ? values[0] : registry;
return WebAssembly.instantiate(binary(bytes), imports);
})
.then(
pair => {
uniqueTest(_ => {
assert_true(valid, loc);
}, test);
return pair.instance;
},
error => {
uniqueTest(_ => {
assert_true(
!valid,
`unexpected instantiation error, observed ${error} ${loc}`
);
}, test);
return error;
}
);
return chain;
}
function exports(instance) {
return instance.then(inst => {
return { module: inst.exports, spectest: registry.spectest };
});
}
function call(instance, name, args) {
return Promise.all([instance, chain]).then(values => {
return values[0].exports[name](...args);
});
}
function run(action) {
const test = "Run a WebAssembly test without special assertions";
const loc = new Error().stack.toString().replace("Error", "");
chain = Promise.all([chain, action()])
.then(
_ => {
uniqueTest(_ => {}, test);
},
error => {
uniqueTest(_ => {
assert_true(
false,
`unexpected runtime error, observed ${error} ${loc}`
);
}, "run");
}
)
// Clear all exceptions, so that subsequent tests get executed.
.catch(_ => {});
}
function assert_trap(action) {
const test = "Test that a WebAssembly code traps";
const loc = new Error().stack.toString().replace("Error", "");
chain = Promise.all([chain, action()])
.then(
result => {
uniqueTest(_ => {
assert_true(false, loc);
}, test);
},
error => {
uniqueTest(_ => {
assert_true(
error instanceof WebAssembly.RuntimeError,
`expected runtime error, observed ${error} ${loc}`
);
}, test);
}
)
// Clear all exceptions, so that subsequent tests get executed.
.catch(_ => {});
}
function assert_return(action, ...expected) {
const test = "Test that a WebAssembly code returns a specific result";
const loc = new Error().stack.toString().replace("Error", "");
chain = Promise.all([action(), chain])
.then(
values => {
uniqueTest(_ => {
let actual = values[0];
if (actual === undefined) {
actual = [];
} else if (!Array.isArray(actual)) {
actual = [actual];
}
if (actual.length !== expected.length) {
throw new Error(expected.length + " value(s) expected, got " + actual.length);
}
for (let i = 0; i < actual.length; ++i) {
switch (expected[i]) {
case "nan:canonical":
case "nan:arithmetic":
case "nan:any":
// Note that JS can't reliably distinguish different NaN values,
// so there's no good way to test that it's a canonical NaN.
assert_true(Number.isNaN(actual[i]), `expected NaN, observed ${actual[i]}.`);
return;
case "ref.func":
assert_true(typeof actual[i] === "function", `expected Wasm function, got ${actual[i]}`);
return;
case "ref.extern":
assert_true(actual[i] !== null, `expected Wasm reference, got ${actual[i]}`);
return;
default:
assert_equals(actual[i], expected[i], loc);
}
}
}, test);
},
error => {
uniqueTest(_ => {
assert_true(
false,
`unexpected runtime error, observed ${error} ${loc}`
);
}, test);
}
)
// Clear all exceptions, so that subsequent tests get executed.
.catch(_ => {});
}
let StackOverflow;
try {
(function f() {
1 + f();
})();
} catch (e) {
StackOverflow = e.constructor;
}
function assert_exhaustion(action) {
const test = "Test that a WebAssembly code exhauts the stack space";
const loc = new Error().stack.toString().replace("Error", "");
chain = Promise.all([action(), chain])
.then(
_ => {
uniqueTest(_ => {
assert_true(false, loc);
}, test);
},
error => {
uniqueTest(_ => {
assert_true(
error instanceof StackOverflow,
`expected runtime error, observed ${error} ${loc}`
);
}, test);
}
)
// Clear all exceptions, so that subsequent tests get executed.
.catch(_ => {});
}
function assert_unlinkable(bytes) {
const test = "Test that a WebAssembly module is unlinkable";
const loc = new Error().stack.toString().replace("Error", "");
instance(bytes, registry, EXPECT_INVALID)
.then(
result => {
uniqueTest(_ => {
assert_true(
result instanceof WebAssembly.LinkError,
`expected link error, observed ${result} ${loc}`
);
}, test);
},
_ => {
uniqueTest(_ => {
assert_true(false, loc);
}, test);
}
)
// Clear all exceptions, so that subsequent tests get executed.
.catch(_ => {});
}
function assert_uninstantiable(bytes) {
const test = "Test that a WebAssembly module is uninstantiable";
const loc = new Error().stack.toString().replace("Error", "");
instance(bytes, registry, EXPECT_INVALID)
.then(
result => {
uniqueTest(_ => {
assert_true(
result instanceof WebAssembly.RuntimeError,
`expected link error, observed ${result} ${loc}`
);
}, test);
},
_ => {
uniqueTest(_ => {
assert_true(false, loc);
}, test);
}
)
// Clear all exceptions, so that subsequent tests get executed.
.catch(_ => {});
}
function register(name, instance) {
const test =
"Test that the exports of a WebAssembly module can be registered";
const loc = new Error().stack.toString().replace("Error", "");
let stack = new Error();
chain = Promise.all([instance, chain])
.then(
values => {
registry[name] = values[0].exports;
},
_ => {
uniqueTest(_ => {
assert_true(false, loc);
}, test);
}
)
// Clear all exceptions, so that subsequent tests get executed.
.catch(_ => {});
}
function get(instance, name) {
const test = "Test that an export of a WebAssembly instance can be acquired";
const loc = new Error().stack.toString().replace("Error", "");
chain = Promise.all([instance, chain]).then(
values => {
let v = values[0].exports[name];
return (v instanceof WebAssembly.Global) ? v.value : v;
},
_ => {
uniqueTest(_ => {
assert_true(false, loc);
}, test);
}
);
return chain;
}