mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +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 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" ) );
|
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 = {};
|
var result = {};
|
||||||
for (var method in testData) {
|
for (var method in testData) {
|
||||||
try{
|
try{
|
||||||
@ -11,13 +19,10 @@ function callExport(instance) {
|
|||||||
result[method] = err.toString();
|
result[method] = err.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// save the test result
|
saveResults(result);
|
||||||
const original = redirect( "testresult.json" );
|
|
||||||
putstr( JSON.stringify(result) );
|
|
||||||
redirect( original );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WebAssembly.instantiate( wasm, wasmImports ).then(
|
WebAssembly.instantiate( wasm, wasmImports ).then(
|
||||||
obj => callExport(obj.instance),
|
obj => callExport( obj.instance, wasmImports ),
|
||||||
reason => console.log(reason)
|
reason => console.log(reason)
|
||||||
);
|
);
|
||||||
|
@ -2,7 +2,15 @@ load( "{test}.wasm.js" );
|
|||||||
var wasm = wasmTextToBinary( read( "{test}.wat" ) );
|
var wasm = wasmTextToBinary( read( "{test}.wat" ) );
|
||||||
var testData = JSON.parse( read( "testdata.json" ) );
|
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 = {};
|
var result = {};
|
||||||
for (var method in testData) {
|
for (var method in testData) {
|
||||||
try{
|
try{
|
||||||
@ -11,13 +19,10 @@ function callExport(instance) {
|
|||||||
result[method] = err.toString();
|
result[method] = err.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// save the test result
|
saveResults(result);
|
||||||
const original = redirect( "testresult.json" );
|
|
||||||
putstr( JSON.stringify(result) );
|
|
||||||
redirect( original );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WebAssembly.instantiate( wasm, wasmImports ).then(
|
WebAssembly.instantiate( wasm, wasmImports ).then(
|
||||||
obj => callExport(obj.instance),
|
obj => callExport( obj.instance, wasmImports ),
|
||||||
reason => console.log(reason)
|
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);
|
var wasm = wabt.parseWat(filename, text, features);
|
||||||
wasm = wasm.toBinary({}).buffer;
|
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 = {};
|
var result = {};
|
||||||
for (var method in testData) {
|
for (var method in testData) {
|
||||||
try{
|
try{
|
||||||
@ -21,11 +27,10 @@ function callExport(instance) {
|
|||||||
result[method] = err.toString();
|
result[method] = err.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// save the test result
|
saveResults(result);
|
||||||
fs.writeFileSync( "testresult.json", JSON.stringify(result) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WebAssembly.instantiate( wasm, wasmImports ).then(
|
WebAssembly.instantiate( wasm, wasmImports ).then(
|
||||||
obj => callExport(obj.instance),
|
obj => callExport( obj.instance, wasmImports ),
|
||||||
reason => console.log(reason)
|
reason => console.log(reason)
|
||||||
);
|
);
|
||||||
|
@ -7,7 +7,13 @@ var filename = '{test.wasm}';
|
|||||||
var wasm = fs.readFileSync(filename);
|
var wasm = fs.readFileSync(filename);
|
||||||
var testData = JSON.parse( fs.readFileSync( "testdata.json", "utf8" ) );
|
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 = {};
|
var result = {};
|
||||||
for (var method in testData) {
|
for (var method in testData) {
|
||||||
try{
|
try{
|
||||||
@ -16,11 +22,10 @@ function callExport(instance) {
|
|||||||
result[method] = err.toString();
|
result[method] = err.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// save the test result
|
saveResults(result);
|
||||||
fs.writeFileSync( "testresult.json", JSON.stringify(result) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WebAssembly.instantiate( wasm, wasmImports ).then(
|
WebAssembly.instantiate( wasm, wasmImports ).then(
|
||||||
obj => callExport(obj.instance),
|
obj => callExport( obj.instance, wasmImports ),
|
||||||
reason => console.log(reason)
|
reason => console.log(reason)
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user