Skip to content

Commit d810afa

Browse files
committed
Only use Context.parse for syntax checking; CompiledScript may be evaluated in another Context.
1 parent 2ea6af7 commit d810afa

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

graal-js/src/com.oracle.truffle.js.scriptengine/src/com/oracle/truffle/js/scriptengine/GraalJSScriptEngine.java

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -412,18 +412,6 @@ private Object eval(Source source, ScriptContext scriptContext) throws ScriptExc
412412
}
413413
}
414414

415-
Object evalCompiledScript(Value compiledScript, ScriptContext scriptContext) throws ScriptException {
416-
GraalJSBindings engineBindings = getOrCreateGraalJSBindings(scriptContext);
417-
Context polyglotContext = engineBindings.getContext();
418-
updateDelegatingIOStreams(polyglotContext, scriptContext);
419-
try {
420-
engineBindings.importGlobalBindings(scriptContext);
421-
return compiledScript.execute().as(Object.class);
422-
} catch (PolyglotException e) {
423-
throw new ScriptException(e);
424-
}
425-
}
426-
427415
private GraalJSBindings getOrCreateGraalJSBindings(ScriptContext scriptContext) {
428416
Bindings engineB = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
429417
if (engineB instanceof GraalJSBindings) {
@@ -561,12 +549,7 @@ public CompiledScript compile(Reader reader) throws ScriptException {
561549
}
562550

563551
private CompiledScript compile(Source source) throws ScriptException {
564-
final Value compiledScript;
565-
try {
566-
compiledScript = getPolyglotContext().parse(source);
567-
} catch (PolyglotException e) {
568-
throw new ScriptException(e);
569-
}
552+
checkSyntax(source);
570553
return new CompiledScript() {
571554
@Override
572555
public ScriptEngine getEngine() {
@@ -575,11 +558,19 @@ public ScriptEngine getEngine() {
575558

576559
@Override
577560
public Object eval(ScriptContext ctx) throws ScriptException {
578-
return GraalJSScriptEngine.this.evalCompiledScript(compiledScript, ctx);
561+
return GraalJSScriptEngine.this.eval(source, ctx);
579562
}
580563
};
581564
}
582565

566+
private void checkSyntax(Source source) throws ScriptException {
567+
try {
568+
getPolyglotContext().parse(source);
569+
} catch (PolyglotException pex) {
570+
throw new ScriptException(pex);
571+
}
572+
}
573+
583574
private static class DelegatingInputStream extends InputStream implements Proxy {
584575

585576
private Reader reader;

0 commit comments

Comments
 (0)