Skip to content

Commit df9ba05

Browse files
committed
JavaScriptScriptLanguage: add flavor methods
These methods report whether the script language is using the Nashorn flavor of JavaScript, or the Rhino flavor.
1 parent 95473cd commit df9ba05

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/main/java/org/scijava/plugins/scripting/javascript/JavaScriptScriptLanguage.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,28 @@ public JavaScriptScriptLanguage() {
5959
super("javascript");
6060
}
6161

62+
// -- JavaScriptScriptLanguage methods --
63+
64+
/**
65+
* Returns true iff this script language is using the <a
66+
* href="http://openjdk.java.net/projects/nashorn/">Nashorn</a> JavaScript
67+
* engine. This is the case for Java 8.
68+
*/
69+
public boolean isNashorn() {
70+
return getEngineName().contains("Nashorn");
71+
}
72+
73+
/**
74+
* Returns true iff this script language is using the <a
75+
* href="https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino"
76+
* >Rhino</a> JavaScript engine. This is the case for Java 6 and Java 7.
77+
*/
78+
public boolean isRhino() {
79+
return getEngineName().contains("Rhino");
80+
}
81+
82+
// -- ScriptEngineFactory methods --
83+
6284
@Override
6385
public ScriptEngine getScriptEngine() {
6486
final ScriptEngine engine = super.getScriptEngine();

0 commit comments

Comments
 (0)