31 lines
856 B
JavaScript
Raw Normal View History

2017-04-04 20:51:10 +02:00
#!/usr/bin/env node
var wasm = read( "spiderMonkey.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
var dependencies = {
"global": {},
"env": {}
};
dependencies["global.Math"] = Math;
2017-04-08 20:16:39 +02: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();
}
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, dependencies ).then(
obj => callExport(obj.instance),
2017-04-04 20:51:10 +02:00
reason => console.log(reason)
);