我正在尝试从 GraalVM 本机映像中的 Java 代码运行 JS 脚本。
Java 代码如下所示:
try (Context context = Context.create("js")) {
Value bindings = context.getBindings("js");
bindings.putMember("response", response);
bindings.putMember("UTF8", StandardCharsets.UTF_8);
context.eval("js", script);
} catch (PolyglotException e) {
error("Error: " + e, 10);
}
JS 代码只是尝试response通过调用对象的方法来使用该对象,例如:
print("Status code: " + response.getStatusCode());
这在 GraalVM 中运行时有效,但在创建本机映像时,它失败并显示以下错误:
INVOKE on JavaObject[...] failed due to: Message not supported: INVOKE
如果我只是像 in 那样打印对象print("Response: " + response);,它不会失败。但是,如果我尝试在 上调用任何方法response,则会收到此错误(偶数toString()或hashCode())。
目前还有什么我需要做的吗,或者这只是 SubstractVM 本机图像中的一个错误?
我的 GraalVM 版本:
java version "1.8.0_172"
Java(TM) SE Runtime Environment (build 1.8.0_172-b11)
GraalVM 1.0.0-rc4 (build 25.71-b01-internal-jvmci-0.45, mixed mode)
我正在使用的本机图像命令:
native-image --language:js --report-unsupported-elements-at-runtime -jar my.jar
相关分类