JWebAssembly/test/de/inetsoftware/jwebassembly/SpiderMonkeyWatTest.js

30 lines
875 B
JavaScript
Raw Permalink Normal View History

2019-09-12 21:54:35 +02:00
load( "{test}.wasm.js" );
var wasm = wasmTextToBinary( read( "{test}.wat" ) );
2020-05-31 11:09:58 +02:00
// os.file.writeTypedArrayToFile( "debug.wasm", wasm );
var testData = JSON.parse( read( "testdata.json" ) );
2018-12-01 18:32:18 +01:00
// 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{
2019-10-20 14:43:05 +02:00
result[method] = String(instance.exports[method]( ...testData[method] ));
}catch(err){
result[method] = err.toString() + '\n' + err.stack;
}
2018-12-01 18:32:18 +01:00
}
saveResults(result);
2018-12-01 18:32:18 +01:00
}
WebAssembly.instantiate( wasm, wasmImports ).then(
obj => callExport( obj.instance, wasmImports ),
2018-12-01 18:32:18 +01:00
reason => console.log(reason)
);