From b7d5254eb2db197138b03d75bbc565ac1e41def8 Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Tue, 10 Jun 2025 00:33:20 +0000 Subject: [PATCH] Update async_index.js and sync_index.js Aafter f83f8101ddb98da50b01f31e6b1f9dbaaf122679 the arguments to instance() are always a module object rather than the bytes. --- test/harness/async_index.js | 23 +++++++++++++++++------ test/harness/sync_index.js | 18 ++++++++++++++---- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/test/harness/async_index.js b/test/harness/async_index.js index 5812f347fd..8a01b21211 100644 --- a/test/harness/async_index.js +++ b/test/harness/async_index.js @@ -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) { @@ -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, @@ -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(_ => { diff --git a/test/harness/sync_index.js b/test/harness/sync_index.js index 069c97dff2..5c4549be2e 100644 --- a/test/harness/sync_index.js +++ b/test/harness/sync_index.js @@ -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) { @@ -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, @@ -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; @@ -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; }