Skip to content

Commit

Permalink
(fix) add python NameError support to dynamic polyglot context
Browse files Browse the repository at this point in the history
  • Loading branch information
ake2l committed Jan 19, 2024
1 parent c7bf2b5 commit b27c983
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,23 @@ synchronized public Value evalScript(Context context, String text, String langua
this.updatePolyglotLocalFromGlobal(context, language);
returnValue = polyglotCtx.eval(language, text);
} catch (org.graalvm.polyglot.PolyglotException e) {
if (e.getMessage().contains("is not defined")) {
if (e.getMessage().contains("ReferenceError: ")) {
String missingObject = e.getMessage().replace("ReferenceError: ", "").replace(" is not defined", "");
if (!Objects.equals(previousMissingObject, missingObject)) {
this.migrateBeneratorContext2GraalVM(context, language, missingObject);
returnValue = evalScript(context, text, language);
previousMissingObject = missingObject;
}
} else {
}
if (e.getMessage().contains(("NameError: "))) {
String missingObject = e.getMessage().replace("NameError: name '", "").replace("' is not defined", "");
if (!Objects.equals(previousMissingObject, missingObject)) {
this.migrateBeneratorContext2GraalVM(context, language, missingObject);
returnValue = evalScript(context, text, language);
previousMissingObject = missingObject;
}
}
else {
throw new ScriptException(e.getMessage(), null);
}
}
Expand Down

0 comments on commit b27c983

Please sign in to comment.