-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch the JavaScript engine used for testing from Nashorn to GraalJS
- Loading branch information
1 parent
9e3db7d
commit 6a0d1cc
Showing
4 changed files
with
57 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/test/java/com/nulabinc/zxcvbn/JSScriptEngineBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.nulabinc.zxcvbn; | ||
|
||
import com.oracle.truffle.js.scriptengine.GraalJSScriptEngine; | ||
import org.graalvm.polyglot.Context; | ||
import org.graalvm.polyglot.Engine; | ||
|
||
import javax.script.ScriptEngine; | ||
import javax.script.ScriptException; | ||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileReader; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
|
||
public class JSScriptEngineBuilder { | ||
|
||
public ScriptEngine build() { | ||
final GraalJSScriptEngine engine = GraalJSScriptEngine.create( | ||
Engine.newBuilder() | ||
.option("engine.WarnInterpreterOnly", "false") | ||
.build(), | ||
Context.newBuilder("js")); | ||
loadZxcvbnJs(engine); | ||
return engine; | ||
} | ||
|
||
private void loadZxcvbnJs(ScriptEngine engine) { | ||
try { | ||
//using the 4.4.1 release | ||
URL script = JSScriptEngineBuilder.class.getClassLoader().getResource("zxcvbn.js"); | ||
engine.eval(new FileReader(new File(script.toURI()))); | ||
} catch (URISyntaxException | FileNotFoundException | ScriptException e) { | ||
throw new RuntimeException("Cannot instantiate Javascript Engine", e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters