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
The following commit(s) were added to refs/heads/master by this push: new 83c4ba8 Run the test in environment with Java interop 83c4ba8 is described below commit 83c4ba845d51378de201ee1812b99a402f2c5b7c Author: Jaroslav Tulach <jaroslav.tul...@apidesign.org> AuthorDate: Sun Dec 16 15:42:09 2018 +0100 Run the test in environment with Java interop --- .../net/java/html/boot/script/ScriptPresenter.java | 83 +++------------------- .../html/boot/script/Jsr223JavaScriptTest.java | 22 +++++- 2 files changed, 30 insertions(+), 75 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 af9b2ec..289e625 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 @@ -83,12 +83,7 @@ Presenter, Fn.FromJavaScript, Fn.ToJavaScript, Executor { eng.eval("function alert(msg) { Packages.java.lang.System.out.println(msg); };"); eng.eval("function confirm(msg) { Packages.java.lang.System.out.println(msg); return true; };"); eng.eval("function prompt(msg, txt) { Packages.java.lang.System.out.println(msg + ':' + txt); return txt; };"); - Object undef; - if (JDK7) { - undef = new JDK7Callback().undefined(eng); - } else { - undef = ((Object[])eng.eval("Java.to([undefined])"))[0]; - } + Object undef = new UndefinedCallback().undefined(eng); this.undefined = undef; } catch (ScriptException ex) { throw new IllegalStateException(ex); @@ -418,86 +413,26 @@ Presenter, Fn.FromJavaScript, Fn.ToJavaScript, Executor { } } - private static final class JDK7Callback implements ObjectOutput { + private static final class UndefinedCallback extends Callback { private Object undefined; @Override - public void writeObject(Object obj) throws IOException { + public void callback(Object obj) { undefined = obj; } - @Override - public void write(int b) throws IOException { - } - - @Override - public void write(byte[] b) throws IOException { - } - - @Override - public void write(byte[] b, int off, int len) throws IOException { - } - - @Override - public void flush() throws IOException { - } - - @Override - public void close() throws IOException { - } - - @Override - public void writeBoolean(boolean v) throws IOException { - } - - @Override - public void writeByte(int v) throws IOException { - } - - @Override - public void writeShort(int v) throws IOException { - } - - @Override - public void writeChar(int v) throws IOException { - } - - @Override - public void writeInt(int v) throws IOException { - } - - @Override - public void writeLong(long v) throws IOException { - } - - @Override - public void writeFloat(float v) throws IOException { - } - - @Override - public void writeDouble(double v) throws IOException { - } - - @Override - public void writeBytes(String s) throws IOException { - } - - @Override - public void writeChars(String s) throws IOException { - } - - @Override - public void writeUTF(String s) throws IOException { - } - public Object undefined(ScriptEngine eng) { + undefined = this; try { - eng.eval("function isJDK7Undefined(js) { js.writeObject(undefined); }"); + Object fn = eng.eval("(function(js) { js.callback(undefined); })"); Invocable inv = (Invocable) eng; - inv.invokeFunction("isJDK7Undefined", this); + inv.invokeMethod(fn, "call", null, this); } catch (NoSuchMethodException | ScriptException ex) { throw new IllegalStateException(ex); } + if (undefined == this) { + throw new IllegalStateException(); + } return undefined; } } diff --git a/boot-script/src/test/java/net/java/html/boot/script/Jsr223JavaScriptTest.java b/boot-script/src/test/java/net/java/html/boot/script/Jsr223JavaScriptTest.java index 053291b..d405490 100644 --- a/boot-script/src/test/java/net/java/html/boot/script/Jsr223JavaScriptTest.java +++ b/boot-script/src/test/java/net/java/html/boot/script/Jsr223JavaScriptTest.java @@ -23,10 +23,13 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import java.util.concurrent.Executors; +import javax.script.ScriptEngine; +import javax.script.ScriptEngineManager; import net.java.html.boot.BrowserBuilder; import org.netbeans.html.boot.spi.Fn; import org.netbeans.html.json.tck.KOTest; import org.testng.Assert; +import static org.testng.Assert.assertEquals; import org.testng.annotations.Factory; /** @@ -41,7 +44,24 @@ public class Jsr223JavaScriptTest { } @Factory public static Object[] compatibilityTests() throws Exception { - final BrowserBuilder bb = BrowserBuilder.newBrowser(new ScriptPresenter(SingleCase.JS)). + ScriptEngine engine = new ScriptEngineManager().getEngineByName("javascript"); + Object left = engine.eval( + "(function() {\n" + + " var names = Object.getOwnPropertyNames(this);\n" + + " for (var i = 0; i < names.length; i++) {\n" + + " var n = names[i];\n" + + " if (n === 'Object') continue;\n" + + " if (n === 'Number') continue;\n" + + " if (n === 'Boolean') continue;\n" + + " if (n === 'Array') continue;\n" + + " delete this[n];\n" + + " }\n" + + " return Object.getOwnPropertyNames(this).toString();\n" + + "})()\n" + + "" + ); + assertEquals(left.toString().toLowerCase().indexOf("java"), -1, "No Java symbols " + left); + final BrowserBuilder bb = BrowserBuilder.newBrowser(new ScriptPresenter(engine, SingleCase.JS)). loadClass(Jsr223JavaScriptTest.class). loadPage("empty.html"). invoke("initialized"); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org For additional commands, e-mail: commits-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists