The presenters are supposed to be singlethreaded so we need an executor to pass requests into
1.1 --- a/boot-script/src/main/java/net/java/html/boot/script/ScriptPresenter.java Wed Jun 04 14:57:22 2014 +0200
1.2 +++ b/boot-script/src/main/java/net/java/html/boot/script/ScriptPresenter.java Wed Jun 04 15:18:05 2014 +0200
1.3 @@ -74,8 +74,10 @@
1.4 implements Presenter, Fn.FromJavaScript, Fn.ToJavaScript, Executor {
1.5 private static final Logger LOG = Logger.getLogger(ScriptPresenter.class.getName());
1.6 private final ScriptEngine eng;
1.7 + private final Executor exc;
1.8
1.9 - public ScriptPresenter() {
1.10 + public ScriptPresenter(Executor exc) {
1.11 + this.exc = exc;
1.12 try {
1.13 eng = new ScriptEngineManager().getEngineByName("javascript");
1.14 eng.eval("function alert(msg) { Packages.java.lang.System.out.println(msg); };");
1.15 @@ -209,12 +211,22 @@
1.16 }
1.17
1.18 @Override
1.19 - public void execute(Runnable command) {
1.20 - try (Closeable c = Fn.activate(this)) {
1.21 + public void execute(final Runnable command) {
1.22 + if (Fn.activePresenter() == this) {
1.23 command.run();
1.24 - } catch (IOException ex) {
1.25 - throw new IllegalStateException(ex);
1.26 + return;
1.27 }
1.28 +
1.29 + class Wrap implements Runnable {
1.30 + public void run() {
1.31 + try (Closeable c = Fn.activate(ScriptPresenter.this)) {
1.32 + command.run();
1.33 + } catch (IOException ex) {
1.34 + throw new IllegalStateException(ex);
1.35 + }
1.36 + }
1.37 + }
1.38 + exc.execute(new Wrap());
1.39 }
1.40
1.41 private class FnImpl extends Fn {
2.1 --- a/boot-script/src/test/java/net/java/html/boot/script/Jsr223JavaScriptTest.java Wed Jun 04 14:57:22 2014 +0200
2.2 +++ b/boot-script/src/test/java/net/java/html/boot/script/Jsr223JavaScriptTest.java Wed Jun 04 15:18:05 2014 +0200
2.3 @@ -65,7 +65,7 @@
2.4 }
2.5
2.6 @Factory public static Object[] compatibilityTests() throws Exception {
2.7 - final BrowserBuilder bb = BrowserBuilder.newBrowser(new ScriptPresenter()).
2.8 + final BrowserBuilder bb = BrowserBuilder.newBrowser(new ScriptPresenter(SingleCase.JS)).
2.9 loadClass(Jsr223JavaScriptTest.class).
2.10 loadPage("empty.html").
2.11 invoke("initialized");
3.1 --- a/boot-script/src/test/java/net/java/html/boot/script/SingleCase.java Wed Jun 04 14:57:22 2014 +0200
3.2 +++ b/boot-script/src/test/java/net/java/html/boot/script/SingleCase.java Wed Jun 04 15:18:05 2014 +0200
3.3 @@ -59,7 +59,7 @@
3.4 * @author Jaroslav Tulach <jtulach@netbeans.org>
3.5 */
3.6 public final class SingleCase implements ITest, IHookable, Runnable {
3.7 - private static final Executor JS = Executors.newSingleThreadExecutor();
3.8 + static final Executor JS = Executors.newSingleThreadExecutor();
3.9 private final Fn.Presenter p;
3.10 private final Method m;
3.11 private Object result;
4.1 --- a/boot-script/src/test/java/net/java/html/boot/script/ko4j/KOCase.java Wed Jun 04 14:57:22 2014 +0200
4.2 +++ b/boot-script/src/test/java/net/java/html/boot/script/ko4j/KOCase.java Wed Jun 04 15:18:05 2014 +0200
4.3 @@ -57,7 +57,7 @@
4.4 * @author Jaroslav Tulach <jtulach@netbeans.org>
4.5 */
4.6 public final class KOCase implements ITest, Runnable {
4.7 - private static final Executor JS = Executors.newSingleThreadExecutor();
4.8 + static final Executor JS = Executors.newSingleThreadExecutor();
4.9 private final Fn.Presenter p;
4.10 private final Method m;
4.11 private Object result;
5.1 --- a/boot-script/src/test/java/net/java/html/boot/script/ko4j/KnockoutEnvJSTest.java Wed Jun 04 14:57:22 2014 +0200
5.2 +++ b/boot-script/src/test/java/net/java/html/boot/script/ko4j/KnockoutEnvJSTest.java Wed Jun 04 15:18:05 2014 +0200
5.3 @@ -53,6 +53,7 @@
5.4 import java.net.URL;
5.5 import java.net.URLConnection;
5.6 import java.util.ArrayList;
5.7 +import java.util.Collections;
5.8 import java.util.List;
5.9 import java.util.Map;
5.10 import java.util.concurrent.Executor;
5.11 @@ -99,7 +100,7 @@
5.12
5.13 baseUri = DynamicHTTP.initServer();
5.14
5.15 - final ScriptPresenter p = new ScriptPresenter();
5.16 + final ScriptPresenter p = new ScriptPresenter(KOCase.JS);
5.17 InputStream is = KnockoutEnvJSTest.class.getResourceAsStream("env.nashorn.1.2-debug.js");
5.18 p.loadScript(new InputStreamReader(is));
5.19 is.close();