mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 10:44:47 +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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -24,10 +24,17 @@ import java.util.Collection;
|
||||
public enum ScriptEngine {
|
||||
NodeJS,
|
||||
SpiderMonkey,
|
||||
NodeWast;
|
||||
NodeWat,
|
||||
SpiderMonkeyWat,
|
||||
;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
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 nodeWastScript;
|
||||
private File nodeWatScript;
|
||||
|
||||
private File spiderMonkeyWatScript;
|
||||
|
||||
private boolean failed;
|
||||
|
||||
@ -113,7 +115,8 @@ public class WasmRule extends TemporaryFolder {
|
||||
|
||||
nodeScript = createScript( "nodetest.js" );
|
||||
spiderMonkeyScript = createScript( "SpiderMonkeyTest.js" );
|
||||
nodeWastScript = createScript( "WatTest.js" );
|
||||
nodeWatScript = createScript( "WatTest.js" );
|
||||
spiderMonkeyWatScript = createScript( "SpiderMonkeyWatTest.js" );
|
||||
|
||||
//create dummy files to prevent error messages
|
||||
FileOutputStream jsonPackage = new FileOutputStream( new File( getRoot(), "package.json" ) );
|
||||
@ -253,13 +256,16 @@ public class WasmRule extends TemporaryFolder {
|
||||
try {
|
||||
switch( script ) {
|
||||
case SpiderMonkey:
|
||||
processBuilder = spiderMonkeyCommand();
|
||||
processBuilder = spiderMonkeyCommand( spiderMonkeyScript );
|
||||
break;
|
||||
case SpiderMonkeyWat:
|
||||
processBuilder = spiderMonkeyCommand( spiderMonkeyWatScript );
|
||||
break;
|
||||
case NodeJS:
|
||||
processBuilder = nodeJsCommand( nodeScript );
|
||||
break;
|
||||
case NodeWast:
|
||||
processBuilder = nodeJsCommand( nodeWastScript );
|
||||
case NodeWat:
|
||||
processBuilder = nodeJsCommand( nodeWatScript );
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException( script.toString() );
|
||||
@ -304,8 +310,8 @@ public class WasmRule extends TemporaryFolder {
|
||||
* @throws IOException
|
||||
* if the download failed
|
||||
*/
|
||||
private ProcessBuilder spiderMonkeyCommand() throws IOException {
|
||||
return new ProcessBuilder( spiderMonkey.getCommand(), "--wasm-gc", spiderMonkeyScript.getAbsolutePath() );
|
||||
private ProcessBuilder spiderMonkeyCommand( File script ) throws IOException {
|
||||
return new ProcessBuilder( spiderMonkey.getCommand(), "--wasm-gc", script.getAbsolutePath() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user