我正在尝试从 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
如果我只是打印中的对象print("Response: " + response);
,它不会失败。但是,如果我尝试在 上调用任何方法response
,我会收到此错误(甚至toString()
或hashCode()
)。
我还有什么需要做的吗,或者这只是 SubstractVM native-image 中的一个错误,目前?
我的 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 命令:
native-image --language:js --report-unsupported-elements-at-runtime -jar my.jar