From 3f4462064de3e9b11d6375991ff14e42a25fc035 Mon Sep 17 00:00:00 2001 From: Volker Berlin Date: Sat, 2 Nov 2019 18:09:35 +0100 Subject: [PATCH] provide the wasm.exports to the JavaScript import functions for possible callbacks. --- .../jwebassembly/SpiderMonkeyTest.js | 19 ++++++++++++------- .../jwebassembly/SpiderMonkeyWatTest.js | 17 +++++++++++------ test/de/inetsoftware/jwebassembly/WatTest.js | 13 +++++++++---- test/de/inetsoftware/jwebassembly/nodetest.js | 13 +++++++++---- 4 files changed, 41 insertions(+), 21 deletions(-) diff --git a/test/de/inetsoftware/jwebassembly/SpiderMonkeyTest.js b/test/de/inetsoftware/jwebassembly/SpiderMonkeyTest.js index 2e30baa..7a34c6e 100644 --- a/test/de/inetsoftware/jwebassembly/SpiderMonkeyTest.js +++ b/test/de/inetsoftware/jwebassembly/SpiderMonkeyTest.js @@ -2,7 +2,15 @@ load( "{test.wasm}.js" ); var wasm = read( "{test.wasm}", "binary" ); // https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Shell_global_objects var testData = JSON.parse( read( "testdata.json" ) ); -function callExport(instance) { +// save the test result +function saveResults(result) { + const original = redirect( "testresult.json" ); + putstr( JSON.stringify(result) ); + redirect( original ); +} + +function callExport( instance, wasmImports ) { + wasmImports.exports = instance.exports; var result = {}; for (var method in testData) { try{ @@ -11,13 +19,10 @@ function callExport(instance) { result[method] = err.toString(); } } - // save the test result - const original = redirect( "testresult.json" ); - putstr( JSON.stringify(result) ); - redirect( original ); + saveResults(result); } -WebAssembly.instantiate( wasm, wasmImports ).then( - obj => callExport(obj.instance), +WebAssembly.instantiate( wasm, wasmImports ).then( + obj => callExport( obj.instance, wasmImports ), reason => console.log(reason) ); diff --git a/test/de/inetsoftware/jwebassembly/SpiderMonkeyWatTest.js b/test/de/inetsoftware/jwebassembly/SpiderMonkeyWatTest.js index 077afb1..b933d0d 100644 --- a/test/de/inetsoftware/jwebassembly/SpiderMonkeyWatTest.js +++ b/test/de/inetsoftware/jwebassembly/SpiderMonkeyWatTest.js @@ -2,7 +2,15 @@ load( "{test}.wasm.js" ); var wasm = wasmTextToBinary( read( "{test}.wat" ) ); var testData = JSON.parse( read( "testdata.json" ) ); -function callExport(instance) { +// save the test result +function saveResults(result) { + const original = redirect( "testresult.json" ); + putstr( JSON.stringify(result) ); + redirect( original ); +} + +function callExport( instance, wasmImports ) { + wasmImports.exports = instance.exports; var result = {}; for (var method in testData) { try{ @@ -11,13 +19,10 @@ function callExport(instance) { result[method] = err.toString(); } } - // save the test result - const original = redirect( "testresult.json" ); - putstr( JSON.stringify(result) ); - redirect( original ); + saveResults(result); } WebAssembly.instantiate( wasm, wasmImports ).then( - obj => callExport(obj.instance), + obj => callExport( obj.instance, wasmImports ), reason => console.log(reason) ); diff --git a/test/de/inetsoftware/jwebassembly/WatTest.js b/test/de/inetsoftware/jwebassembly/WatTest.js index 90939ab..8d6ea74 100644 --- a/test/de/inetsoftware/jwebassembly/WatTest.js +++ b/test/de/inetsoftware/jwebassembly/WatTest.js @@ -12,7 +12,13 @@ var features = {'sat_float_to_int':true, 'sign_extension':true, 'exceptions':tru var wasm = wabt.parseWat(filename, text, features); wasm = wasm.toBinary({}).buffer; -function callExport(instance) { +// save the test result +function saveResults(result) { + fs.writeFileSync( "testresult.json", JSON.stringify(result) ); +} + +function callExport( instance, wasmImports ) { + wasmImports.exports = instance.exports; var result = {}; for (var method in testData) { try{ @@ -21,11 +27,10 @@ function callExport(instance) { result[method] = err.toString(); } } - // save the test result - fs.writeFileSync( "testresult.json", JSON.stringify(result) ); + saveResults(result); } WebAssembly.instantiate( wasm, wasmImports ).then( - obj => callExport(obj.instance), + obj => callExport( obj.instance, wasmImports ), reason => console.log(reason) ); diff --git a/test/de/inetsoftware/jwebassembly/nodetest.js b/test/de/inetsoftware/jwebassembly/nodetest.js index 0ab1f63..3573ab0 100644 --- a/test/de/inetsoftware/jwebassembly/nodetest.js +++ b/test/de/inetsoftware/jwebassembly/nodetest.js @@ -7,7 +7,13 @@ var filename = '{test.wasm}'; var wasm = fs.readFileSync(filename); var testData = JSON.parse( fs.readFileSync( "testdata.json", "utf8" ) ); -function callExport(instance) { +// save the test result +function saveResults(result) { + fs.writeFileSync( "testresult.json", JSON.stringify(result) ); +} + +function callExport( instance, wasmImports ) { + wasmImports.exports = instance.exports; var result = {}; for (var method in testData) { try{ @@ -16,11 +22,10 @@ function callExport(instance) { result[method] = err.toString(); } } - // save the test result - fs.writeFileSync( "testresult.json", JSON.stringify(result) ); + saveResults(result); } WebAssembly.instantiate( wasm, wasmImports ).then( - obj => callExport(obj.instance), + obj => callExport( obj.instance, wasmImports ), reason => console.log(reason) );