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

24 lines
674 B
JavaScript
Raw Normal View History

2019-09-12 21:54:35 +02:00
load( "{test}.wasm.js" );
var wasm = wasmTextToBinary( read( "{test}.wat" ) );
var testData = JSON.parse( read( "testdata.json" ) );
2018-12-01 18:32:18 +01:00
function callExport(instance) {
var result = {};
for (var method in testData) {
try{
result[method] = instance.exports[method]( ...testData[method] ).toString();
}catch(err){
result[method] = err.toString();
}
2018-12-01 18:32:18 +01:00
}
// save the test result
const original = redirect( "testresult.json" );
putstr( JSON.stringify(result) );
redirect( original );
2018-12-01 18:32:18 +01:00
}
WebAssembly.instantiate( wasm, wasmImports ).then(
obj => callExport(obj.instance),
2018-12-01 18:32:18 +01:00
reason => console.log(reason)
);