Need to implement FromJavaScript interface NbHtml4J
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Thu, 09 Jan 2014 21:21:34 +0100
branchNbHtml4J
changeset 142966358a11c016
parent 1428 dbd3ed861f5f
child 1430 08ba3c2b9eea
Need to implement FromJavaScript interface
ko/fx/src/test/java/org/apidesign/bck2brwsr/kofx/KnockoutFXTest.java
launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/fximpl/JVMBridge.java
     1.1 --- a/ko/fx/src/test/java/org/apidesign/bck2brwsr/kofx/KnockoutFXTest.java	Thu Jan 09 21:21:11 2014 +0100
     1.2 +++ b/ko/fx/src/test/java/org/apidesign/bck2brwsr/kofx/KnockoutFXTest.java	Thu Jan 09 21:21:34 2014 +0100
     1.3 @@ -64,30 +64,32 @@
     1.4          TyrusContext tc = new TyrusContext();
     1.5          Contexts.Builder b = Contexts.newBuilder().
     1.6              register(Technology.class, ko.knockout(), 10).
     1.7 -            register(Transfer.class, ko.transferViaOrgJSON(), 10);
     1.8 +            register(Transfer.class, ko.transfer(), 10);
     1.9          try {
    1.10              Class.forName("java.util.function.Function");
    1.11              // prefer WebView's WebSockets on JDK8
    1.12 -            b.register(WSTransfer.class, ko.websocketsViaBrowser(), 10);
    1.13 +            b.register(WSTransfer.class, ko.websockets(), 10);
    1.14          } catch (ClassNotFoundException ex) {
    1.15              // ok, JDK7 needs tyrus
    1.16              b.register(WSTransfer.class, tc, 20);
    1.17 +            b.register(Transfer.class, tc, 5);
    1.18          }
    1.19          return b.build();
    1.20      }
    1.21  
    1.22      @Override
    1.23      public Object createJSON(Map<String, Object> values) {
    1.24 -        JSONObject json = new JSONObject();
    1.25 +        Object json = createJSON();
    1.26          for (Map.Entry<String, Object> entry : values.entrySet()) {
    1.27 -            try {
    1.28 -                json.put(entry.getKey(), entry.getValue());
    1.29 -            } catch (JSONException ex) {
    1.30 -                throw new IllegalStateException(ex);
    1.31 -            }
    1.32 +            setProperty(json, entry.getKey(), entry.getValue());
    1.33          }
    1.34          return json;
    1.35      }
    1.36 +    
    1.37 +    @JavaScriptBody(args = {}, body = "return new Object();")
    1.38 +    private static native Object createJSON();
    1.39 +    @JavaScriptBody(args = { "json", "key", "value" }, body = "json[key] = value;")
    1.40 +    private static native void setProperty(Object json, String key, Object value);
    1.41  
    1.42      @Override
    1.43      @JavaScriptBody(args = { "s", "args" }, body = ""
     2.1 --- a/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/fximpl/JVMBridge.java	Thu Jan 09 21:21:11 2014 +0100
     2.2 +++ b/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/fximpl/JVMBridge.java	Thu Jan 09 21:21:34 2014 +0100
     2.3 @@ -81,7 +81,7 @@
     2.4      }
     2.5      
     2.6      private final class WebPresenter 
     2.7 -    implements FindResources, Fn.Presenter, Fn.ToJavaScript, Executor {
     2.8 +    implements FindResources, Fn.Presenter, Fn.ToJavaScript, Fn.FromJavaScript, Executor {
     2.9          @Override
    2.10          public void findResources(String name, Collection<? super URL> results, boolean oneIsEnough) {
    2.11              if (ldrs != null) for (ClassLoader l : ldrs) {
    2.12 @@ -134,6 +134,11 @@
    2.13          }
    2.14  
    2.15          @Override
    2.16 +        public Object toJava(Object js) {
    2.17 +            return checkArray(js);
    2.18 +        }
    2.19 +
    2.20 +        @Override
    2.21          public Object toJavaScript(Object toReturn) {
    2.22              if (toReturn instanceof Object[]) {
    2.23                  return convertArrays((Object[]) toReturn);