provide the wasm.exports to the JavaScript import functions for possible callbacks.

This commit is contained in:
Volker Berlin 2019-11-02 18:09:35 +01:00
parent ec96a8c9f8
commit 3f4462064d
4 changed files with 41 additions and 21 deletions

View File

@ -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)
);

View File

@ -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)
);

View File

@ -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)
);

View File

@ -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)
);