mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +01:00
prepare wat test via SpiderMonkey
This commit is contained in:
parent
07d78774a5
commit
392b3ef66f
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017 Volker Berlin (i-net software)
|
* Copyright 2017 - 2018 Volker Berlin (i-net software)
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -24,10 +24,17 @@ import java.util.Collection;
|
|||||||
public enum ScriptEngine {
|
public enum ScriptEngine {
|
||||||
NodeJS,
|
NodeJS,
|
||||||
SpiderMonkey,
|
SpiderMonkey,
|
||||||
NodeWast;
|
NodeWat,
|
||||||
|
SpiderMonkeyWat,
|
||||||
|
;
|
||||||
|
|
||||||
public static Collection<ScriptEngine[]> testParams() {
|
public static Collection<ScriptEngine[]> testParams() {
|
||||||
ScriptEngine[][] val = {{ScriptEngine.SpiderMonkey},{ScriptEngine.NodeJS},{ScriptEngine.NodeWast}};
|
ScriptEngine[][] val = { //
|
||||||
|
{ ScriptEngine.SpiderMonkey }, //
|
||||||
|
{ ScriptEngine.NodeJS }, //
|
||||||
|
{ ScriptEngine.NodeWat }, //
|
||||||
|
// { ScriptEngine.SpiderMonkeyWat },//
|
||||||
|
};
|
||||||
return Arrays.asList(val);
|
return Arrays.asList(val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
28
test/de/inetsoftware/jwebassembly/SpiderMonkeyWatTest.js
Normal file
28
test/de/inetsoftware/jwebassembly/SpiderMonkeyWatTest.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
var filename = '{test.wat}';
|
||||||
|
var ret = wasmTextToBinary(read(filename));
|
||||||
|
|
||||||
|
function instantiate(bytes, imports) {
|
||||||
|
return WebAssembly.compile(bytes).then(
|
||||||
|
m => new WebAssembly.Instance(m, imports), reason => console.log(reason) );
|
||||||
|
}
|
||||||
|
|
||||||
|
var dependencies = {
|
||||||
|
"global": {},
|
||||||
|
"env": {}
|
||||||
|
};
|
||||||
|
dependencies["global.Math"] = Math;
|
||||||
|
|
||||||
|
function callExport(instance) {
|
||||||
|
try{
|
||||||
|
console.log( instance.exports[scriptArgs[0]]( ...scriptArgs.slice(1) ) );
|
||||||
|
}catch(err){
|
||||||
|
console.log(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
instantiate( ret, dependencies ).then(
|
||||||
|
instance => callExport(instance),
|
||||||
|
reason => console.log(reason)
|
||||||
|
);
|
@ -54,7 +54,9 @@ public class WasmRule extends TemporaryFolder {
|
|||||||
|
|
||||||
private File spiderMonkeyScript;
|
private File spiderMonkeyScript;
|
||||||
|
|
||||||
private File nodeWastScript;
|
private File nodeWatScript;
|
||||||
|
|
||||||
|
private File spiderMonkeyWatScript;
|
||||||
|
|
||||||
private boolean failed;
|
private boolean failed;
|
||||||
|
|
||||||
@ -113,7 +115,8 @@ public class WasmRule extends TemporaryFolder {
|
|||||||
|
|
||||||
nodeScript = createScript( "nodetest.js" );
|
nodeScript = createScript( "nodetest.js" );
|
||||||
spiderMonkeyScript = createScript( "SpiderMonkeyTest.js" );
|
spiderMonkeyScript = createScript( "SpiderMonkeyTest.js" );
|
||||||
nodeWastScript = createScript( "WatTest.js" );
|
nodeWatScript = createScript( "WatTest.js" );
|
||||||
|
spiderMonkeyWatScript = createScript( "SpiderMonkeyWatTest.js" );
|
||||||
|
|
||||||
//create dummy files to prevent error messages
|
//create dummy files to prevent error messages
|
||||||
FileOutputStream jsonPackage = new FileOutputStream( new File( getRoot(), "package.json" ) );
|
FileOutputStream jsonPackage = new FileOutputStream( new File( getRoot(), "package.json" ) );
|
||||||
@ -253,13 +256,16 @@ public class WasmRule extends TemporaryFolder {
|
|||||||
try {
|
try {
|
||||||
switch( script ) {
|
switch( script ) {
|
||||||
case SpiderMonkey:
|
case SpiderMonkey:
|
||||||
processBuilder = spiderMonkeyCommand();
|
processBuilder = spiderMonkeyCommand( spiderMonkeyScript );
|
||||||
|
break;
|
||||||
|
case SpiderMonkeyWat:
|
||||||
|
processBuilder = spiderMonkeyCommand( spiderMonkeyWatScript );
|
||||||
break;
|
break;
|
||||||
case NodeJS:
|
case NodeJS:
|
||||||
processBuilder = nodeJsCommand( nodeScript );
|
processBuilder = nodeJsCommand( nodeScript );
|
||||||
break;
|
break;
|
||||||
case NodeWast:
|
case NodeWat:
|
||||||
processBuilder = nodeJsCommand( nodeWastScript );
|
processBuilder = nodeJsCommand( nodeWatScript );
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException( script.toString() );
|
throw new IllegalStateException( script.toString() );
|
||||||
@ -304,8 +310,8 @@ public class WasmRule extends TemporaryFolder {
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
* if the download failed
|
* if the download failed
|
||||||
*/
|
*/
|
||||||
private ProcessBuilder spiderMonkeyCommand() throws IOException {
|
private ProcessBuilder spiderMonkeyCommand( File script ) throws IOException {
|
||||||
return new ProcessBuilder( spiderMonkey.getCommand(), "--wasm-gc", spiderMonkeyScript.getAbsolutePath() );
|
return new ProcessBuilder( spiderMonkey.getCommand(), "--wasm-gc", script.getAbsolutePath() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user