Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions test/harness/async_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ const EXPECT_INVALID = false;

/* DATA **********************************************************************/

let hostrefs = {};
let hostsym = Symbol("hostref");
function hostref(s) {
if (! (s in hostrefs)) hostrefs[s] = {[hostsym]: s};
return hostrefs[s];
}
function eq_ref(x, y) {
return x === y ? 1 : 0;
}
let externrefs = {};
let externsym = Symbol("externref");
function externref(s) {
Expand Down Expand Up @@ -86,6 +95,8 @@ function reinitializeRegistry() {

chain = chain.then(_ => {
let spectest = {
hostref: hostref,
eq_ref: eq_ref,
externref: externref,
is_externref: is_externref,
is_funcref: is_funcref,
Expand Down Expand Up @@ -182,22 +193,22 @@ function assert_invalid_custom(bytes) {

const assert_malformed_custom = assert_invalid_custom;

function instance(bytes, imports, valid = true) {
function instance(module, 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])
chain = Promise.all([module, imports, chain])
.then(values => {
let imports = values[0] ? values[0] : registry;
return WebAssembly.instantiate(binary(bytes), imports);
let imports = values[1] ? values[1] : registry;
return WebAssembly.instantiate(values[0], imports);
})
.then(
pair => {
inst => {
uniqueTest(_ => {
assert_true(valid, loc);
}, test);
return pair.instance;
return inst;
},
error => {
uniqueTest(_ => {
Expand Down
18 changes: 14 additions & 4 deletions test/harness/sync_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ const EXPECT_INVALID = false;

/* DATA **********************************************************************/

let hostrefs = {};
let hostsym = Symbol("hostref");
function hostref(s) {
if (! (s in hostrefs)) hostrefs[s] = {[hostsym]: s};
return hostrefs[s];
}
function eq_ref(x, y) {
return x === y ? 1 : 0;
}
let externrefs = {};
let externsym = Symbol("externref");
function externref(s) {
Expand Down Expand Up @@ -96,6 +105,8 @@ function reinitializeRegistry() {
return;

let spectest = {
hostref: hostref,
eq_ref: eq_ref,
externref: externref,
is_externref: is_externref,
is_funcref: is_funcref,
Expand Down Expand Up @@ -203,7 +214,7 @@ function assert_invalid_custom(bytes) {

const assert_malformed_custom = assert_invalid_custom;

function instance(bytes, imports = registry, valid = true) {
function instance(mod, imports = registry, valid = true) {
if (imports instanceof Result) {
if (imports.isError())
return imports;
Expand All @@ -212,10 +223,9 @@ function instance(bytes, imports = registry, valid = true) {

let err = null;

let m, i;
let i;
try {
let m = module(bytes);
i = new WebAssembly.Instance(m, imports);
i = new WebAssembly.Instance(mod, imports);
} catch(e) {
err = e;
}
Expand Down