mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 02:44:47 +01:00
29 lines
905 B
JavaScript
29 lines
905 B
JavaScript
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" ) );
|
|
|
|
// 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{
|
|
result[method] = String(instance.exports[method]( ...testData[method] ));
|
|
}catch(err){
|
|
result[method] = err.toString() + '\n' + err.stack;
|
|
}
|
|
}
|
|
saveResults(result);
|
|
}
|
|
|
|
WebAssembly.instantiate( wasm, wasmImports ).then(
|
|
obj => callExport( obj.instance, wasmImports ),
|
|
reason => console.log(reason)
|
|
);
|