mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 02:44:47 +01:00
provide the wasm.exports to the JavaScript import functions for possible callbacks.
This commit is contained in:
parent
ec96a8c9f8
commit
3f4462064d
@ -2,7 +2,15 @@ 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" ) );
|
||||
|
||||
function callExport(instance) {
|
||||
// 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{
|
||||
@ -11,13 +19,10 @@ function callExport(instance) {
|
||||
result[method] = err.toString();
|
||||
}
|
||||
}
|
||||
// save the test result
|
||||
const original = redirect( "testresult.json" );
|
||||
putstr( JSON.stringify(result) );
|
||||
redirect( original );
|
||||
saveResults(result);
|
||||
}
|
||||
|
||||
WebAssembly.instantiate( wasm, wasmImports ).then(
|
||||
obj => callExport(obj.instance),
|
||||
WebAssembly.instantiate( wasm, wasmImports ).then(
|
||||
obj => callExport( obj.instance, wasmImports ),
|
||||
reason => console.log(reason)
|
||||
);
|
||||
|
@ -2,7 +2,15 @@ load( "{test}.wasm.js" );
|
||||
var wasm = wasmTextToBinary( read( "{test}.wat" ) );
|
||||
var testData = JSON.parse( read( "testdata.json" ) );
|
||||
|
||||
function callExport(instance) {
|
||||
// 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{
|
||||
@ -11,13 +19,10 @@ function callExport(instance) {
|
||||
result[method] = err.toString();
|
||||
}
|
||||
}
|
||||
// save the test result
|
||||
const original = redirect( "testresult.json" );
|
||||
putstr( JSON.stringify(result) );
|
||||
redirect( original );
|
||||
saveResults(result);
|
||||
}
|
||||
|
||||
WebAssembly.instantiate( wasm, wasmImports ).then(
|
||||
obj => callExport(obj.instance),
|
||||
obj => callExport( obj.instance, wasmImports ),
|
||||
reason => console.log(reason)
|
||||
);
|
||||
|
@ -12,7 +12,13 @@ var features = {'sat_float_to_int':true, 'sign_extension':true, 'exceptions':tru
|
||||
var wasm = wabt.parseWat(filename, text, features);
|
||||
wasm = wasm.toBinary({}).buffer;
|
||||
|
||||
function callExport(instance) {
|
||||
// save the test result
|
||||
function saveResults(result) {
|
||||
fs.writeFileSync( "testresult.json", JSON.stringify(result) );
|
||||
}
|
||||
|
||||
function callExport( instance, wasmImports ) {
|
||||
wasmImports.exports = instance.exports;
|
||||
var result = {};
|
||||
for (var method in testData) {
|
||||
try{
|
||||
@ -21,11 +27,10 @@ function callExport(instance) {
|
||||
result[method] = err.toString();
|
||||
}
|
||||
}
|
||||
// save the test result
|
||||
fs.writeFileSync( "testresult.json", JSON.stringify(result) );
|
||||
saveResults(result);
|
||||
}
|
||||
|
||||
WebAssembly.instantiate( wasm, wasmImports ).then(
|
||||
obj => callExport(obj.instance),
|
||||
obj => callExport( obj.instance, wasmImports ),
|
||||
reason => console.log(reason)
|
||||
);
|
||||
|
@ -7,7 +7,13 @@ var filename = '{test.wasm}';
|
||||
var wasm = fs.readFileSync(filename);
|
||||
var testData = JSON.parse( fs.readFileSync( "testdata.json", "utf8" ) );
|
||||
|
||||
function callExport(instance) {
|
||||
// save the test result
|
||||
function saveResults(result) {
|
||||
fs.writeFileSync( "testresult.json", JSON.stringify(result) );
|
||||
}
|
||||
|
||||
function callExport( instance, wasmImports ) {
|
||||
wasmImports.exports = instance.exports;
|
||||
var result = {};
|
||||
for (var method in testData) {
|
||||
try{
|
||||
@ -16,11 +22,10 @@ function callExport(instance) {
|
||||
result[method] = err.toString();
|
||||
}
|
||||
}
|
||||
// save the test result
|
||||
fs.writeFileSync( "testresult.json", JSON.stringify(result) );
|
||||
saveResults(result);
|
||||
}
|
||||
|
||||
WebAssembly.instantiate( wasm, wasmImports ).then(
|
||||
obj => callExport(obj.instance),
|
||||
obj => callExport( obj.instance, wasmImports ),
|
||||
reason => console.log(reason)
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user