Skip to content

Commit e3a6e6b

Browse files
authored
[test] Update async_index.js and sync_index.js (#1917)
Aafter f83f810 the arguments to instance() are always a module object rather than the bytes.
1 parent a0a8df7 commit e3a6e6b

2 files changed

Lines changed: 31 additions & 10 deletions

File tree

test/harness/async_index.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ const EXPECT_INVALID = false;
5252

5353
/* DATA **********************************************************************/
5454

55+
let hostrefs = {};
56+
let hostsym = Symbol("hostref");
57+
function hostref(s) {
58+
if (! (s in hostrefs)) hostrefs[s] = {[hostsym]: s};
59+
return hostrefs[s];
60+
}
61+
function eq_ref(x, y) {
62+
return x === y ? 1 : 0;
63+
}
5564
let externrefs = {};
5665
let externsym = Symbol("externref");
5766
function externref(s) {
@@ -86,6 +95,8 @@ function reinitializeRegistry() {
8695

8796
chain = chain.then(_ => {
8897
let spectest = {
98+
hostref: hostref,
99+
eq_ref: eq_ref,
89100
externref: externref,
90101
is_externref: is_externref,
91102
is_funcref: is_funcref,
@@ -182,22 +193,22 @@ function assert_invalid_custom(bytes) {
182193

183194
const assert_malformed_custom = assert_invalid_custom;
184195

185-
function instance(bytes, imports, valid = true) {
196+
function instance(module, imports, valid = true) {
186197
const test = valid
187198
? "Test that WebAssembly instantiation succeeds"
188199
: "Test that WebAssembly instantiation fails";
189200
const loc = new Error().stack.toString().replace("Error", "");
190-
chain = Promise.all([imports, chain])
201+
chain = Promise.all([module, imports, chain])
191202
.then(values => {
192-
let imports = values[0] ? values[0] : registry;
193-
return WebAssembly.instantiate(binary(bytes), imports);
203+
let imports = values[1] ? values[1] : registry;
204+
return WebAssembly.instantiate(values[0], imports);
194205
})
195206
.then(
196-
pair => {
207+
inst => {
197208
uniqueTest(_ => {
198209
assert_true(valid, loc);
199210
}, test);
200-
return pair.instance;
211+
return inst;
201212
},
202213
error => {
203214
uniqueTest(_ => {

test/harness/sync_index.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ const EXPECT_INVALID = false;
6666

6767
/* DATA **********************************************************************/
6868

69+
let hostrefs = {};
70+
let hostsym = Symbol("hostref");
71+
function hostref(s) {
72+
if (! (s in hostrefs)) hostrefs[s] = {[hostsym]: s};
73+
return hostrefs[s];
74+
}
75+
function eq_ref(x, y) {
76+
return x === y ? 1 : 0;
77+
}
6978
let externrefs = {};
7079
let externsym = Symbol("externref");
7180
function externref(s) {
@@ -96,6 +105,8 @@ function reinitializeRegistry() {
96105
return;
97106

98107
let spectest = {
108+
hostref: hostref,
109+
eq_ref: eq_ref,
99110
externref: externref,
100111
is_externref: is_externref,
101112
is_funcref: is_funcref,
@@ -203,7 +214,7 @@ function assert_invalid_custom(bytes) {
203214

204215
const assert_malformed_custom = assert_invalid_custom;
205216

206-
function instance(bytes, imports = registry, valid = true) {
217+
function instance(mod, imports = registry, valid = true) {
207218
if (imports instanceof Result) {
208219
if (imports.isError())
209220
return imports;
@@ -212,10 +223,9 @@ function instance(bytes, imports = registry, valid = true) {
212223

213224
let err = null;
214225

215-
let m, i;
226+
let i;
216227
try {
217-
let m = module(bytes);
218-
i = new WebAssembly.Instance(m, imports);
228+
i = new WebAssembly.Instance(mod, imports);
219229
} catch(e) {
220230
err = e;
221231
}

0 commit comments

Comments
 (0)