24 lines
758 B
JavaScript
Raw Normal View History

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" ) );
2017-04-04 20:51:10 +02:00
2017-04-08 20:16:39 +02:00
function callExport(instance) {
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();
}
2017-04-08 20:16:39 +02:00
}
// save the test result
const original = redirect( "testresult.json" );
putstr( JSON.stringify(result) );
redirect( original );
2017-04-08 20:16:39 +02:00
}
2017-04-04 20:51:10 +02:00
WebAssembly.instantiate( wasm, wasmImports ).then(
obj => callExport(obj.instance),
2017-04-04 20:51:10 +02:00
reason => console.log(reason)
);