-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from PlaceholderAPI/fix/issue-#73
fix for #73
- Loading branch information
Showing
3 changed files
with
15 additions
and
13 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
17 changes: 8 additions & 9 deletions
17
...ain/java/com/extendedclip/papi/expansion/javascript/evaluator/NashornScriptEvaluator.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 |
---|---|---|
@@ -1,29 +1,28 @@ | ||
package com.extendedclip.papi.expansion.javascript.evaluator; | ||
|
||
import org.openjdk.nashorn.api.scripting.NashornScriptEngineFactory; | ||
|
||
import javax.script.Bindings; | ||
import javax.script.ScriptContext; | ||
import javax.script.ScriptEngine; | ||
import javax.script.ScriptException; | ||
import java.util.Map; | ||
|
||
public final class NashornScriptEvaluator implements ScriptEvaluator { | ||
private final NashornScriptEngineFactory scriptEngineFactory; | ||
|
||
private final ScriptEngine scriptEngine; | ||
private final Map<String, Object> bindings; | ||
|
||
public NashornScriptEvaluator(final NashornScriptEngineFactory scriptEngineFactory, final Map<String, Object> bindings) { | ||
this.scriptEngineFactory = scriptEngineFactory; | ||
public NashornScriptEvaluator(final ScriptEngine scriptEngine, final Map<String, Object> bindings) { | ||
this.scriptEngine = scriptEngine; | ||
this.bindings = bindings; | ||
} | ||
|
||
@Override | ||
public Object execute(final Map<String, Object> additionalBindings, final String script) throws EvaluatorException, ScriptException { | ||
final ScriptEngine engine = scriptEngineFactory.getScriptEngine("--no-java"); | ||
final Bindings globalBindings = engine.getBindings(ScriptContext.ENGINE_SCOPE); | ||
final Bindings globalBindings = scriptEngine.getBindings(ScriptContext.ENGINE_SCOPE); | ||
globalBindings.putAll(bindings); | ||
globalBindings.putAll(additionalBindings); | ||
engine.setBindings(globalBindings, ScriptContext.GLOBAL_SCOPE); | ||
return engine.eval(script); | ||
scriptEngine.setBindings(globalBindings, ScriptContext.ENGINE_SCOPE); | ||
return scriptEngine.eval(script); | ||
} | ||
|
||
} |
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