Created
December 26, 2018 09:16
-
-
Save okrean/5d6978bac15f257b90f581f371769935 to your computer and use it in GitHub Desktop.
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
function test(jsArray) { | |
print(jsArray); | |
jsArray.forEach(function(a) { | |
print("- " + a); | |
}); | |
jsArray.push(3); | |
} |
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
public static final String jsSource = "src/main/resources/any.js"; | |
public static void main(String[] args) { | |
ScriptEngine engine = new ScriptEngineManager().getEngineByName("graal.js"); | |
Path file = Paths.get(jsSource); | |
try (BufferedReader in = Files.newBufferedReader(file)) { | |
engine.eval(in); | |
} catch (ScriptException | IOException e) { | |
System.out.println(e); | |
return; | |
} | |
Invocable inv = (Invocable) engine; | |
List jsArray = new ArrayList(); | |
jsArray.add(1); | |
jsArray.add(2); | |
try { | |
inv.invokeFunction("test", jsArray); | |
} catch (NoSuchMethodException | ScriptException e) { | |
System.out.println(e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it prints:
[1, 2]
javax.script.ScriptException: org.graalvm.polyglot.PolyglotException: TypeError: INVOKE on JavaObject[[1, 2] (java.util.ArrayList)] failed due to: Unknown identifier: push