2019-09-08 13:40:24 +02:00
|
|
|
load( "{test.wasm}.js" );
|
|
|
|
var wasm = read( "{test.wasm}", "binary" ); // https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Shell_global_objects
|
2019-06-17 19:00:16 +02:00
|
|
|
var testData = JSON.parse( read( "testdata.json" ) );
|
2017-04-04 20:51:10 +02:00
|
|
|
|
2019-11-02 18:09:35 +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;
|
2019-06-17 19:00:16 +02:00
|
|
|
var result = {};
|
|
|
|
for (var method in testData) {
|
|
|
|
try{
|
2019-10-20 14:43:05 +02:00
|
|
|
result[method] = String(instance.exports[method]( ...testData[method] ));
|
2019-06-17 19:00:16 +02:00
|
|
|
}catch(err){
|
2020-02-28 10:00:44 +01:00
|
|
|
result[method] = err.toString() + '\n' + err.stack;
|
2019-06-17 19:00:16 +02:00
|
|
|
}
|
2017-04-08 20:16:39 +02:00
|
|
|
}
|
2019-11-02 18:09:35 +01:00
|
|
|
saveResults(result);
|
2017-04-08 20:16:39 +02:00
|
|
|
}
|
2017-04-04 20:51:10 +02:00
|
|
|
|
2019-11-02 18:09:35 +01:00
|
|
|
WebAssembly.instantiate( wasm, wasmImports ).then(
|
|
|
|
obj => callExport( obj.instance, wasmImports ),
|
2017-04-04 20:51:10 +02:00
|
|
|
reason => console.log(reason)
|
|
|
|
);
|