You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by jt...@apache.org on 2019/04/02 07:30:33 UTC
[incubator-netbeans-html4j] 02/02: Graal.js RC15 needs to
explicitly request access to Java classes
This is an automated email from the ASF dual-hosted git repository.
jtulach pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-netbeans-html4j.git
commit 6f6d808da4e502dea2ce3470507fc04afef288a7
Author: Jaroslav Tulach <ja...@apidesign.org>
AuthorDate: Tue Apr 2 09:29:57 2019 +0200
Graal.js RC15 needs to explicitly request access to Java classes
---
.../net/java/html/boot/script/ScriptPresenter.java | 25 +++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)
diff --git a/boot-script/src/main/java/net/java/html/boot/script/ScriptPresenter.java b/boot-script/src/main/java/net/java/html/boot/script/ScriptPresenter.java
index dee6415..63af0e7 100644
--- a/boot-script/src/main/java/net/java/html/boot/script/ScriptPresenter.java
+++ b/boot-script/src/main/java/net/java/html/boot/script/ScriptPresenter.java
@@ -31,7 +31,9 @@ import java.util.Set;
import java.util.concurrent.Executor;
import java.util.logging.Level;
import java.util.logging.Logger;
+import javax.script.Bindings;
import javax.script.Invocable;
+import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
@@ -75,18 +77,31 @@ Presenter, Fn.FromJavaScript, Fn.ToJavaScript, Executor {
if (eng == null) {
eng = new ScriptEngineManager().getEngineByName("javascript");
}
+ IllegalStateException[] makingPolyglot = { null };
+ if (eng.getFactory().getNames().contains("Graal.js")) { // NOI18N
+ try {
+ Bindings bindings = eng.getBindings(ScriptContext.ENGINE_SCOPE);
+ bindings.put("polyglot.js.allowHostAccess", true); // NOI18N
+ } catch (IllegalStateException ex) {
+ makingPolyglot[0] = ex;
+ }
+ }
this.eng = eng;
this.exc = exc;
+ Object undef;
try {
- Object undef = new UndefinedCallback().undefined(eng);
- this.undefined = undef;
+ undef = new UndefinedCallback().undefined(eng);
if (sanitize) {
Sanitizer.clean(eng);
}
Sanitizer.defineAlert(eng);
} catch (ScriptException ex) {
+ if (makingPolyglot[0] != null) {
+ throw makingPolyglot[0];
+ }
throw new IllegalStateException(ex);
}
+ this.undefined = undef;
this.jsReady = new HashSet<>();
this.callback = new CallbackImpl();
}
@@ -420,14 +435,14 @@ Presenter, Fn.FromJavaScript, Fn.ToJavaScript, Executor {
undefined = obj;
}
- public Object undefined(ScriptEngine eng) {
+ public Object undefined(ScriptEngine eng) throws ScriptException {
undefined = this;
try {
Object fn = eng.eval("(function(js) { js.callback(undefined); })");
Invocable inv = (Invocable) eng;
inv.invokeMethod(fn, "call", null, this);
- } catch (NoSuchMethodException | ScriptException ex) {
- throw new IllegalStateException(ex);
+ } catch (NoSuchMethodException ex) {
+ throw new ScriptException(ex);
}
if (undefined == this) {
throw new IllegalStateException();
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists