mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +01:00
Use its own compiler result for SpiderMonkey
This commit is contained in:
parent
cb65505596
commit
839a7fda89
@ -48,6 +48,8 @@ public class WasmRule extends TemporaryFolder {
|
|||||||
|
|
||||||
private final Class<?>[] classes;
|
private final Class<?>[] classes;
|
||||||
|
|
||||||
|
private JWebAssembly compiler;
|
||||||
|
|
||||||
private File wasmFile;
|
private File wasmFile;
|
||||||
|
|
||||||
private File watFile;
|
private File watFile;
|
||||||
@ -105,23 +107,23 @@ public class WasmRule extends TemporaryFolder {
|
|||||||
* if the compiling is failing
|
* if the compiling is failing
|
||||||
*/
|
*/
|
||||||
public void compile() throws WasmException {
|
public void compile() throws WasmException {
|
||||||
JWebAssembly wasm = new JWebAssembly();
|
compiler = new JWebAssembly();
|
||||||
for( Class<?> clazz : classes ) {
|
for( Class<?> clazz : classes ) {
|
||||||
URL url = clazz.getResource( '/' + clazz.getName().replace( '.', '/' ) + ".class" );
|
URL url = clazz.getResource( '/' + clazz.getName().replace( '.', '/' ) + ".class" );
|
||||||
wasm.addFile( url );
|
compiler.addFile( url );
|
||||||
}
|
}
|
||||||
wasm.setProperty( JWebAssembly.DEBUG_NAMES, "true" );
|
compiler.setProperty( JWebAssembly.DEBUG_NAMES, "true" );
|
||||||
assertEquals( "true", wasm.getProperty( JWebAssembly.DEBUG_NAMES ) );
|
assertEquals( "true", compiler.getProperty( JWebAssembly.DEBUG_NAMES ) );
|
||||||
|
|
||||||
// add the libraries that it can be scanned for annotations
|
// add the libraries that it can be scanned for annotations
|
||||||
final String[] libraries = System.getProperty("java.class.path").split(File.pathSeparator);
|
final String[] libraries = System.getProperty("java.class.path").split(File.pathSeparator);
|
||||||
for( String lib : libraries ) {
|
for( String lib : libraries ) {
|
||||||
if( lib.endsWith( ".jar" ) || lib.toLowerCase().contains( "jwebassembly-api" ) ) {
|
if( lib.endsWith( ".jar" ) || lib.toLowerCase().contains( "jwebassembly-api" ) ) {
|
||||||
wasm.addLibrary( new File(lib) );
|
compiler.addLibrary( new File(lib) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
textCompiled = wasm.compileToText();
|
textCompiled = compiler.compileToText();
|
||||||
try {
|
try {
|
||||||
create();
|
create();
|
||||||
|
|
||||||
@ -131,11 +133,9 @@ public class WasmRule extends TemporaryFolder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
wasmFile = newFile( "test.wasm" );
|
wasmFile = newFile( "test.wasm" );
|
||||||
wasm.compileToBinary( wasmFile );
|
compiler.compileToBinary( wasmFile );
|
||||||
|
|
||||||
nodeScript = createScript( "nodetest.js", "{test.wasm}", wasmFile.getName() );
|
nodeScript = createScript( "nodetest.js", "{test.wasm}", wasmFile.getName() );
|
||||||
spiderMonkeyScript = createScript( "SpiderMonkeyTest.js", "{test.wasm}", wasmFile.getName() );
|
|
||||||
spiderMonkeyWatScript = createScript( "SpiderMonkeyWatTest.js", "{test.wat}", watFile.getName() );
|
|
||||||
} catch( Throwable ex ) {
|
} catch( Throwable ex ) {
|
||||||
System.out.println( textCompiled );
|
System.out.println( textCompiled );
|
||||||
throwException( ex );
|
throwException( ex );
|
||||||
@ -326,10 +326,10 @@ public class WasmRule extends TemporaryFolder {
|
|||||||
try {
|
try {
|
||||||
switch( script ) {
|
switch( script ) {
|
||||||
case SpiderMonkey:
|
case SpiderMonkey:
|
||||||
processBuilder = spiderMonkeyCommand( spiderMonkeyScript );
|
processBuilder = spiderMonkeyCommand( true );
|
||||||
break;
|
break;
|
||||||
case SpiderMonkeyWat:
|
case SpiderMonkeyWat:
|
||||||
processBuilder = spiderMonkeyCommand( spiderMonkeyWatScript );
|
processBuilder = spiderMonkeyCommand( false );
|
||||||
break;
|
break;
|
||||||
case NodeJS:
|
case NodeJS:
|
||||||
processBuilder = nodeJsCommand( nodeScript );
|
processBuilder = nodeJsCommand( nodeScript );
|
||||||
@ -381,12 +381,33 @@ public class WasmRule extends TemporaryFolder {
|
|||||||
/**
|
/**
|
||||||
* Create a ProcessBuilder for spider monkey script shell.
|
* Create a ProcessBuilder for spider monkey script shell.
|
||||||
*
|
*
|
||||||
* @param script the file name of a *.js script
|
* @param binary true, if the WASM format should be test; false, if the WAT format should be tested.
|
||||||
* @return the value from the script
|
* @return the value from the script
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* if the download failed
|
* if the download failed
|
||||||
*/
|
*/
|
||||||
private ProcessBuilder spiderMonkeyCommand( File script ) throws IOException {
|
private ProcessBuilder spiderMonkeyCommand( boolean binary ) throws IOException {
|
||||||
|
File script;
|
||||||
|
try {
|
||||||
|
System.setProperty( "SpiderMonkey", "true" );
|
||||||
|
if( binary ) {
|
||||||
|
if( spiderMonkeyScript == null ) {
|
||||||
|
File file = newFile( "spiderMonkey.wasm" );
|
||||||
|
compiler.compileToBinary( file );
|
||||||
|
spiderMonkeyScript = createScript( "SpiderMonkeyTest.js", "{test.wasm}", file.getName() );
|
||||||
|
}
|
||||||
|
script = spiderMonkeyScript;
|
||||||
|
} else {
|
||||||
|
if( spiderMonkeyWatScript == null ) {
|
||||||
|
File file = newFile( "spiderMonkey.wat" );
|
||||||
|
compiler.compileToText( file );
|
||||||
|
spiderMonkeyWatScript = createScript( "SpiderMonkeyWatTest.js", "{test.wat}", file.getName() );
|
||||||
|
}
|
||||||
|
script = spiderMonkeyWatScript;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
System.clearProperty( "SpiderMonkey" );
|
||||||
|
}
|
||||||
return new ProcessBuilder( spiderMonkey.getCommand(), "--wasm-gc", script.getAbsolutePath() );
|
return new ProcessBuilder( spiderMonkey.getCommand(), "--wasm-gc", script.getAbsolutePath() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user