Extending the TCK with checks for proper behavior of JavaScriptBody annotations
authorJaroslav Tulach <jaroslav.tulach@netbeans.org>
Tue, 07 Jan 2014 08:48:40 +0100
changeset 4241d637fa8634b
parent 423 7fd820c6ea0f
child 425 6729b08befde
child 426 08161684667a
Extending the TCK with checks for proper behavior of JavaScriptBody annotations
boot-fx/pom.xml
boot-fx/src/test/java/org/apidesign/html/boot/fx/FxJavaScriptTst.java
boot/pom.xml
boot/src/main/java/org/apidesign/html/boot/spi/Fn.java
boot/src/main/java/org/netbeans/html/boot/impl/FnContext.java
boot/src/main/java/org/netbeans/html/boot/impl/FnUtils.java
json-tck/pom.xml
json-tck/src/main/java/net/java/html/js/tests/Bodies.java
json-tck/src/main/java/net/java/html/js/tests/Factorial.java
json-tck/src/main/java/net/java/html/js/tests/JavaScriptBodyTest.java
json-tck/src/main/java/net/java/html/js/tests/Sum.java
json-tck/src/main/java/net/java/html/json/tests/KnockoutTest.java
json-tck/src/main/java/org/apidesign/html/json/tck/JavaScriptTCK.java
json-tck/src/main/java/org/apidesign/html/json/tck/KnockoutTCK.java
     1.1 --- a/boot-fx/pom.xml	Tue Jan 07 08:44:50 2014 +0100
     1.2 +++ b/boot-fx/pom.xml	Tue Jan 07 08:48:40 2014 +0100
     1.3 @@ -65,6 +65,12 @@
     1.4        <scope>test</scope>
     1.5        <type>jar</type>
     1.6      </dependency>
     1.7 +    <dependency>
     1.8 +      <groupId>${project.groupId}</groupId>
     1.9 +      <artifactId>net.java.html.json.tck</artifactId>
    1.10 +      <version>${project.version}</version>
    1.11 +      <scope>test</scope>
    1.12 +    </dependency>
    1.13    </dependencies>
    1.14      <description>A presentation provider to show JavaFX WebView 
    1.15  when a Java/HTML based application is about to boot.</description>
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/boot-fx/src/test/java/org/apidesign/html/boot/fx/FxJavaScriptTst.java	Tue Jan 07 08:48:40 2014 +0100
     2.3 @@ -0,0 +1,55 @@
     2.4 +/**
     2.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     2.6 + *
     2.7 + * Copyright 2013-2013 Oracle and/or its affiliates. All rights reserved.
     2.8 + *
     2.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    2.10 + * Other names may be trademarks of their respective owners.
    2.11 + *
    2.12 + * The contents of this file are subject to the terms of either the GNU
    2.13 + * General Public License Version 2 only ("GPL") or the Common
    2.14 + * Development and Distribution License("CDDL") (collectively, the
    2.15 + * "License"). You may not use this file except in compliance with the
    2.16 + * License. You can obtain a copy of the License at
    2.17 + * http://www.netbeans.org/cddl-gplv2.html
    2.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    2.19 + * specific language governing permissions and limitations under the
    2.20 + * License.  When distributing the software, include this License Header
    2.21 + * Notice in each file and include the License file at
    2.22 + * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    2.23 + * particular file as subject to the "Classpath" exception as provided
    2.24 + * by Oracle in the GPL Version 2 section of the License file that
    2.25 + * accompanied this code. If applicable, add the following below the
    2.26 + * License Header, with the fields enclosed by brackets [] replaced by
    2.27 + * your own identifying information:
    2.28 + * "Portions Copyrighted [year] [name of copyright owner]"
    2.29 + *
    2.30 + * Contributor(s):
    2.31 + *
    2.32 + * The Original Software is NetBeans. The Initial Developer of the Original
    2.33 + * Software is Oracle. Portions Copyright 2013-2013 Oracle. All Rights Reserved.
    2.34 + *
    2.35 + * If you wish your version of this file to be governed by only the CDDL
    2.36 + * or only the GPL Version 2, indicate your decision by adding
    2.37 + * "[Contributor] elects to include this software in this distribution
    2.38 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
    2.39 + * single choice of license, a recipient has the option to distribute
    2.40 + * your version of this file under either the CDDL, the GPL Version 2 or
    2.41 + * to extend the choice of license to its licensees as provided above.
    2.42 + * However, if you add GPL Version 2 code and therefore, elected the GPL
    2.43 + * Version 2 license, then the option applies only if the new code is
    2.44 + * made subject to such option by the copyright holder.
    2.45 + */
    2.46 +package org.apidesign.html.boot.fx;
    2.47 +
    2.48 +import org.apidesign.html.json.tck.JavaScriptTCK;
    2.49 +
    2.50 +/**
    2.51 + *
    2.52 + * @author Jaroslav Tulach <jtulach@netbeans.org>
    2.53 + */
    2.54 +public final class FxJavaScriptTst extends JavaScriptTCK {
    2.55 +    public static Class[] tests() {
    2.56 +        return testClasses();
    2.57 +    }
    2.58 +}
     3.1 --- a/boot/pom.xml	Tue Jan 07 08:44:50 2014 +0100
     3.2 +++ b/boot/pom.xml	Tue Jan 07 08:48:40 2014 +0100
     3.3 @@ -33,8 +33,8 @@
     3.4              <artifactId>maven-compiler-plugin</artifactId>
     3.5              <version>2.3.2</version>
     3.6              <configuration>
     3.7 -               <source>1.7</source>
     3.8 -               <target>1.7</target>
     3.9 +               <source>1.6</source>
    3.10 +               <target>1.6</target>
    3.11              </configuration>
    3.12           </plugin>
    3.13        </plugins>
     4.1 --- a/boot/src/main/java/org/apidesign/html/boot/spi/Fn.java	Tue Jan 07 08:44:50 2014 +0100
     4.2 +++ b/boot/src/main/java/org/apidesign/html/boot/spi/Fn.java	Tue Jan 07 08:48:40 2014 +0100
     4.3 @@ -87,7 +87,7 @@
     4.4       * @return true, if proper presenter is used
     4.5       */
     4.6      public final boolean isValid() {
     4.7 -        return FnContext.currentPresenter() == presenter;
     4.8 +        return FnContext.currentPresenter(false) == presenter;
     4.9      }
    4.10      
    4.11      /** Helper method to check if the provided instance is valid function.
    4.12 @@ -112,7 +112,7 @@
    4.13       * @since 0.7
    4.14       */
    4.15      public static Fn define(Class<?> caller, String code, String... names) {
    4.16 -        return FnContext.currentPresenter().defineFn(code, names);
    4.17 +        return FnContext.currentPresenter(false).defineFn(code, names);
    4.18      }
    4.19      
    4.20      private static final Map<String,Set<Presenter>> LOADED = new HashMap<String, Set<Presenter>>();
    4.21 @@ -120,7 +120,7 @@
    4.22          return new Fn() {
    4.23              @Override
    4.24              public Object invoke(Object thiz, Object... args) throws Exception {
    4.25 -                final Presenter p = FnContext.currentPresenter();
    4.26 +                final Presenter p = FnContext.currentPresenter(false);
    4.27                  Set<Presenter> there = LOADED.get(resource);
    4.28                  if (there == null) {
    4.29                      there = new HashSet<Presenter>();
    4.30 @@ -146,7 +146,7 @@
    4.31       * @since 0.7
    4.32       */
    4.33      public static Presenter activePresenter() {
    4.34 -        return FnContext.currentPresenter();
    4.35 +        return FnContext.currentPresenter(true);
    4.36      }
    4.37      
    4.38      /** Activates given presenter. Used by the code generated by 
     5.1 --- a/boot/src/main/java/org/netbeans/html/boot/impl/FnContext.java	Tue Jan 07 08:44:50 2014 +0100
     5.2 +++ b/boot/src/main/java/org/netbeans/html/boot/impl/FnContext.java	Tue Jan 07 08:48:40 2014 +0100
     5.3 @@ -88,8 +88,12 @@
     5.4      }
     5.5  
     5.6      public static Fn.Presenter currentPresenter() {
     5.7 +        return currentPresenter(true);
     5.8 +    }
     5.9 +
    5.10 +    public static Fn.Presenter currentPresenter(boolean fail) {
    5.11          Fn.Presenter p = CURRENT.get();
    5.12 -        if (p == null) {
    5.13 +        if (p == null && fail) {
    5.14              throw new IllegalStateException("No current WebView context around!");
    5.15          }
    5.16          return p;
     6.1 --- a/boot/src/main/java/org/netbeans/html/boot/impl/FnUtils.java	Tue Jan 07 08:44:50 2014 +0100
     6.2 +++ b/boot/src/main/java/org/netbeans/html/boot/impl/FnUtils.java	Tue Jan 07 08:48:40 2014 +0100
     6.3 @@ -79,7 +79,8 @@
     6.4              return true;
     6.5          }
     6.6          Class<?> clazz;
     6.7 -        try (Closeable c = Fn.activate(new FnUtils())) {
     6.8 +        Closeable c = Fn.activate(new FnUtils());
     6.9 +        try {
    6.10              try {
    6.11                  clazz = Class.forName(Test.class.getName(), true, l);
    6.12              } catch (ClassNotFoundException ex) {
    6.13 @@ -89,6 +90,12 @@
    6.14              return Boolean.TRUE.equals(is);
    6.15          } catch (Exception ex) {
    6.16              return false;
    6.17 +        } finally {
    6.18 +            try {
    6.19 +                c.close();
    6.20 +            } catch (Exception ex) {
    6.21 +                return false;
    6.22 +            }
    6.23          }
    6.24      }
    6.25      
     7.1 --- a/json-tck/pom.xml	Tue Jan 07 08:44:50 2014 +0100
     7.2 +++ b/json-tck/pom.xml	Tue Jan 07 08:48:40 2014 +0100
     7.3 @@ -10,7 +10,7 @@
     7.4    <artifactId>net.java.html.json.tck</artifactId>
     7.5    <version>0.7-SNAPSHOT</version>
     7.6    <packaging>bundle</packaging>
     7.7 -  <name>TCK for JSON Model</name>
     7.8 +  <name>HTML for Java TCK</name>
     7.9    <url>http://maven.apache.org</url>
    7.10    <properties>
    7.11      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    7.12 @@ -57,6 +57,11 @@
    7.13        <artifactId>org-openide-util</artifactId>
    7.14        <scope>provided</scope>
    7.15      </dependency>
    7.16 +    <dependency>
    7.17 +      <groupId>${project.groupId}</groupId>
    7.18 +      <artifactId>net.java.html.boot</artifactId>
    7.19 +      <version>${project.version}</version>
    7.20 +    </dependency>
    7.21    </dependencies>
    7.22      <description>Test Compatibility Kit for anyone who wants to consume the net.java.html.json APIs and
    7.23  render their objects using own technology (e.g. own browser, MVVC, etc.).</description>
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/json-tck/src/main/java/net/java/html/js/tests/Bodies.java	Tue Jan 07 08:48:40 2014 +0100
     8.3 @@ -0,0 +1,90 @@
     8.4 +/**
     8.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     8.6 + *
     8.7 + * Copyright 2013-2013 Oracle and/or its affiliates. All rights reserved.
     8.8 + *
     8.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    8.10 + * Other names may be trademarks of their respective owners.
    8.11 + *
    8.12 + * The contents of this file are subject to the terms of either the GNU
    8.13 + * General Public License Version 2 only ("GPL") or the Common
    8.14 + * Development and Distribution License("CDDL") (collectively, the
    8.15 + * "License"). You may not use this file except in compliance with the
    8.16 + * License. You can obtain a copy of the License at
    8.17 + * http://www.netbeans.org/cddl-gplv2.html
    8.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    8.19 + * specific language governing permissions and limitations under the
    8.20 + * License.  When distributing the software, include this License Header
    8.21 + * Notice in each file and include the License file at
    8.22 + * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    8.23 + * particular file as subject to the "Classpath" exception as provided
    8.24 + * by Oracle in the GPL Version 2 section of the License file that
    8.25 + * accompanied this code. If applicable, add the following below the
    8.26 + * License Header, with the fields enclosed by brackets [] replaced by
    8.27 + * your own identifying information:
    8.28 + * "Portions Copyrighted [year] [name of copyright owner]"
    8.29 + *
    8.30 + * Contributor(s):
    8.31 + *
    8.32 + * The Original Software is NetBeans. The Initial Developer of the Original
    8.33 + * Software is Oracle. Portions Copyright 2013-2013 Oracle. All Rights Reserved.
    8.34 + *
    8.35 + * If you wish your version of this file to be governed by only the CDDL
    8.36 + * or only the GPL Version 2, indicate your decision by adding
    8.37 + * "[Contributor] elects to include this software in this distribution
    8.38 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
    8.39 + * single choice of license, a recipient has the option to distribute
    8.40 + * your version of this file under either the CDDL, the GPL Version 2 or
    8.41 + * to extend the choice of license to its licensees as provided above.
    8.42 + * However, if you add GPL Version 2 code and therefore, elected the GPL
    8.43 + * Version 2 license, then the option applies only if the new code is
    8.44 + * made subject to such option by the copyright holder.
    8.45 + */
    8.46 +package net.java.html.js.tests;
    8.47 +
    8.48 +import java.util.concurrent.Callable;
    8.49 +import net.java.html.js.JavaScriptBody;
    8.50 +
    8.51 +/**
    8.52 + *
    8.53 + * @author Jaroslav Tulach <jtulach@netbeans.org>
    8.54 + */
    8.55 +final class Bodies {
    8.56 +    @JavaScriptBody(args = { "a", "b" }, body = "return a + b;")
    8.57 +    public static native int sum(int a, int b);
    8.58 +    
    8.59 +    @JavaScriptBody(args = {"r"}, javacall = true, body = "r.@java.lang.Runnable::run()();")
    8.60 +    static native void callback(Runnable r);
    8.61 +
    8.62 +    @JavaScriptBody(args = {"c"}, javacall = true, body = "return c.@java.util.concurrent.Callable::call()();")
    8.63 +    static native Object callback(Callable<Boolean> c);
    8.64 +    
    8.65 +    @JavaScriptBody(args = { "v" }, body = "return v;")
    8.66 +    public static native Object id(Object v);
    8.67 +    
    8.68 +    @JavaScriptBody(args = { "v" }, body = "return { 'x' : v };")
    8.69 +    public static native Object instance(int v);
    8.70 +    
    8.71 +    @JavaScriptBody(args = "o", body = "o.x++;")
    8.72 +    public static native void incrementX(Object o);
    8.73 +
    8.74 +    @JavaScriptBody(args = "o", body = "return o.x;")
    8.75 +    public static native int readX(Object o);
    8.76 +
    8.77 +    @JavaScriptBody(args = { "c" }, javacall = true, body = 
    8.78 +        "return c.@net.java.html.js.tests.Sum::sum(II)(40, 2);"
    8.79 +    )
    8.80 +    public static native int sumIndirect(Sum c);
    8.81 +    
    8.82 +    @JavaScriptBody(args = { "arr", "index" }, body = "return arr[index];")
    8.83 +    public static native Object select(Object[] arr, int index);
    8.84 +
    8.85 +    @JavaScriptBody(args = { "arr" }, body = "return arr.length;")
    8.86 +    public static native int length(Object[] arr);
    8.87 +
    8.88 +    @JavaScriptBody(args = { "arr", "i", "value" }, body = "arr[i] = value;")
    8.89 +    public static native void modify(String[] arr, int i, String value);
    8.90 +    
    8.91 +    @JavaScriptBody(args = {}, body = "return true;")
    8.92 +    public static native boolean truth();
    8.93 +}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/json-tck/src/main/java/net/java/html/js/tests/Factorial.java	Tue Jan 07 08:48:40 2014 +0100
     9.3 @@ -0,0 +1,62 @@
     9.4 +/**
     9.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     9.6 + *
     9.7 + * Copyright 2013-2013 Oracle and/or its affiliates. All rights reserved.
     9.8 + *
     9.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    9.10 + * Other names may be trademarks of their respective owners.
    9.11 + *
    9.12 + * The contents of this file are subject to the terms of either the GNU
    9.13 + * General Public License Version 2 only ("GPL") or the Common
    9.14 + * Development and Distribution License("CDDL") (collectively, the
    9.15 + * "License"). You may not use this file except in compliance with the
    9.16 + * License. You can obtain a copy of the License at
    9.17 + * http://www.netbeans.org/cddl-gplv2.html
    9.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    9.19 + * specific language governing permissions and limitations under the
    9.20 + * License.  When distributing the software, include this License Header
    9.21 + * Notice in each file and include the License file at
    9.22 + * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    9.23 + * particular file as subject to the "Classpath" exception as provided
    9.24 + * by Oracle in the GPL Version 2 section of the License file that
    9.25 + * accompanied this code. If applicable, add the following below the
    9.26 + * License Header, with the fields enclosed by brackets [] replaced by
    9.27 + * your own identifying information:
    9.28 + * "Portions Copyrighted [year] [name of copyright owner]"
    9.29 + *
    9.30 + * Contributor(s):
    9.31 + *
    9.32 + * The Original Software is NetBeans. The Initial Developer of the Original
    9.33 + * Software is Oracle. Portions Copyright 2013-2013 Oracle. All Rights Reserved.
    9.34 + *
    9.35 + * If you wish your version of this file to be governed by only the CDDL
    9.36 + * or only the GPL Version 2, indicate your decision by adding
    9.37 + * "[Contributor] elects to include this software in this distribution
    9.38 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
    9.39 + * single choice of license, a recipient has the option to distribute
    9.40 + * your version of this file under either the CDDL, the GPL Version 2 or
    9.41 + * to extend the choice of license to its licensees as provided above.
    9.42 + * However, if you add GPL Version 2 code and therefore, elected the GPL
    9.43 + * Version 2 license, then the option applies only if the new code is
    9.44 + * made subject to such option by the copyright holder.
    9.45 + */
    9.46 +package net.java.html.js.tests;
    9.47 +
    9.48 +import net.java.html.js.JavaScriptBody;
    9.49 +
    9.50 +/**
    9.51 + *
    9.52 + * @author Jaroslav Tulach <jtulach@netbeans.org>
    9.53 + */
    9.54 +public final class Factorial {
    9.55 +    int minusOne(int i) {
    9.56 +        return i - 1;
    9.57 +    }
    9.58 +
    9.59 +    @JavaScriptBody(args = { "i" }, javacall = true,body = 
    9.60 +        "if (i <= 1) return 1;\n"
    9.61 +      + "var im1 = this.@net.java.html.js.tests.Factorial::minusOne(I)(i);\n"
    9.62 +      + "return this.@net.java.html.js.tests.Factorial::factorial(I)(im1) * i;"
    9.63 +    )
    9.64 +    native int factorial(int n);
    9.65 +}
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/json-tck/src/main/java/net/java/html/js/tests/JavaScriptBodyTest.java	Tue Jan 07 08:48:40 2014 +0100
    10.3 @@ -0,0 +1,204 @@
    10.4 +/**
    10.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    10.6 + *
    10.7 + * Copyright 2013-2013 Oracle and/or its affiliates. All rights reserved.
    10.8 + *
    10.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
   10.10 + * Other names may be trademarks of their respective owners.
   10.11 + *
   10.12 + * The contents of this file are subject to the terms of either the GNU
   10.13 + * General Public License Version 2 only ("GPL") or the Common
   10.14 + * Development and Distribution License("CDDL") (collectively, the
   10.15 + * "License"). You may not use this file except in compliance with the
   10.16 + * License. You can obtain a copy of the License at
   10.17 + * http://www.netbeans.org/cddl-gplv2.html
   10.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   10.19 + * specific language governing permissions and limitations under the
   10.20 + * License.  When distributing the software, include this License Header
   10.21 + * Notice in each file and include the License file at
   10.22 + * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
   10.23 + * particular file as subject to the "Classpath" exception as provided
   10.24 + * by Oracle in the GPL Version 2 section of the License file that
   10.25 + * accompanied this code. If applicable, add the following below the
   10.26 + * License Header, with the fields enclosed by brackets [] replaced by
   10.27 + * your own identifying information:
   10.28 + * "Portions Copyrighted [year] [name of copyright owner]"
   10.29 + *
   10.30 + * Contributor(s):
   10.31 + *
   10.32 + * The Original Software is NetBeans. The Initial Developer of the Original
   10.33 + * Software is Oracle. Portions Copyright 2013-2013 Oracle. All Rights Reserved.
   10.34 + *
   10.35 + * If you wish your version of this file to be governed by only the CDDL
   10.36 + * or only the GPL Version 2, indicate your decision by adding
   10.37 + * "[Contributor] elects to include this software in this distribution
   10.38 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
   10.39 + * single choice of license, a recipient has the option to distribute
   10.40 + * your version of this file under either the CDDL, the GPL Version 2 or
   10.41 + * to extend the choice of license to its licensees as provided above.
   10.42 + * However, if you add GPL Version 2 code and therefore, elected the GPL
   10.43 + * Version 2 license, then the option applies only if the new code is
   10.44 + * made subject to such option by the copyright holder.
   10.45 + */
   10.46 +package net.java.html.js.tests;
   10.47 +
   10.48 +import java.util.concurrent.Callable;
   10.49 +import org.apidesign.html.json.tck.KOTest;
   10.50 +
   10.51 +/**
   10.52 + *
   10.53 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   10.54 + */
   10.55 +public class JavaScriptBodyTest {
   10.56 +    @KOTest public void sumTwoNumbers() {
   10.57 +        int res = Bodies.sum(5, 3);
   10.58 +        assert res == 8 : "Expecting 8: " + res;
   10.59 +    }
   10.60 +    
   10.61 +    @KOTest public void accessJsObject() {
   10.62 +        Object o = Bodies.instance(10);
   10.63 +        int ten = Bodies.readX(o);
   10.64 +        assert ten == 10 : "Expecting ten: " + ten;
   10.65 +    }
   10.66 +
   10.67 +    @KOTest public void callWithNoReturnType() {
   10.68 +        Object o = Bodies.instance(10);
   10.69 +        Bodies.incrementX(o);
   10.70 +        int ten = Bodies.readX(o);
   10.71 +        assert ten == 11 : "Expecting eleven: " + ten;
   10.72 +    }
   10.73 +    
   10.74 +    @KOTest public void callbackToRunnable() {
   10.75 +        R run = new R();
   10.76 +        Bodies.callback(run);
   10.77 +        assert run.cnt == 1 : "Can call even private implementation classes: " + run.cnt;
   10.78 +    }
   10.79 +
   10.80 +    @KOTest public void computeInARunnable() {
   10.81 +        final int[] sum = new int[2];
   10.82 +        class First implements Runnable {
   10.83 +            @Override public void run() {
   10.84 +                sum[0] = Bodies.sum(22, 20);
   10.85 +                sum[1] = Bodies.sum(32, 10);
   10.86 +            }
   10.87 +        }
   10.88 +        Bodies.callback(new First());
   10.89 +        assert sum[0] == 42 : "Computed OK " + sum[0];
   10.90 +        assert sum[1] == 42 : "Computed OK too: " + sum[1];
   10.91 +    }
   10.92 +    
   10.93 +    @KOTest public void doubleCallbackToRunnable() {
   10.94 +        final R run = new R();
   10.95 +        final R r2 = new R();
   10.96 +        class First implements Runnable {
   10.97 +            @Override public void run() {
   10.98 +                Bodies.callback(run);
   10.99 +                Bodies.callback(r2);
  10.100 +            }
  10.101 +        }
  10.102 +        Bodies.callback(new First());
  10.103 +        assert run.cnt == 1 : "Can call even private implementation classes: " + run.cnt;
  10.104 +        assert r2.cnt == 1 : "Can call even private implementation classes: " + r2.cnt;
  10.105 +    }
  10.106 +    
  10.107 +    @KOTest public void identity() {
  10.108 +        Object p = new Object();
  10.109 +        Object r = Bodies.id(p);
  10.110 +        assert r == p : "The object is the same";
  10.111 +    }
  10.112 +
  10.113 +    @KOTest public void encodingString() {
  10.114 +        Object p = "Ji\n\"Hi\"\nHon";
  10.115 +        Object r = Bodies.id(p);
  10.116 +        assert p.equals(r) : "The object is the same: " + p + " != " + r;
  10.117 +    }
  10.118 +
  10.119 +    @KOTest public void nullIsNull() {
  10.120 +        Object p = null;
  10.121 +        Object r = Bodies.id(p);
  10.122 +        assert r == p : "The null is the same";
  10.123 +    }
  10.124 +    
  10.125 +    @KOTest public void callbackWithResult() {
  10.126 +        Callable<Boolean> c = new C();
  10.127 +        Object b = Bodies.callback(c);
  10.128 +        assert b == Boolean.TRUE : "Should return true";
  10.129 +    }
  10.130 +    
  10.131 +    @KOTest public void callbackWithParameters() {
  10.132 +        int res = Bodies.sumIndirect(new Sum());
  10.133 +        assert res == 42 : "Expecting 42";
  10.134 +    }
  10.135 +    
  10.136 +    @KOTest public void selectFromJavaArray() {
  10.137 +        String[] arr = { "Ahoj", "World" };
  10.138 +        Object res = Bodies.select(arr, 1);
  10.139 +        assert "World".equals(res) : "Expecting World, but was: " + res;
  10.140 +    }
  10.141 +
  10.142 +    @KOTest public void lengthOfJavaArray() {
  10.143 +        String[] arr = { "Ahoj", "World" };
  10.144 +        int res = Bodies.length(arr);
  10.145 +        assert res == 2 : "Expecting 2, but was: " + res;
  10.146 +    }
  10.147 +
  10.148 +    @KOTest public void javaArrayInOut() {
  10.149 +        String[] arr = { "Ahoj", "World" };
  10.150 +        Object res = Bodies.id(arr);
  10.151 +        assert res == arr : "Expecting same array, but was: " + res;
  10.152 +    }
  10.153 +
  10.154 +//  Modifying an array is a complex operation in the bridge:    
  10.155 +//    
  10.156 +//    @KOTest public void modifyJavaArray() {
  10.157 +//        String[] arr = { "Ahoj", "World" };
  10.158 +//        Bodies.modify(arr, 0, "Hello");
  10.159 +//        assert "Hello".equals(arr[0]) : "Expecting World, but was: " + arr[0];
  10.160 +//    }
  10.161 +
  10.162 +    @KOTest public void truth() {
  10.163 +        assert Bodies.truth() : "True is true";
  10.164 +    }
  10.165 +    
  10.166 +    @KOTest public void factorial2() {
  10.167 +        assert new Factorial().factorial(2) == 2;
  10.168 +    }
  10.169 +    
  10.170 +    @KOTest public void factorial3() {
  10.171 +        assert new Factorial().factorial(3) == 6;
  10.172 +    }
  10.173 +    
  10.174 +    @KOTest public void factorial4() {
  10.175 +        assert new Factorial().factorial(4) == 24;
  10.176 +    }
  10.177 +    
  10.178 +    @KOTest public void factorial5() {
  10.179 +        assert new Factorial().factorial(5) == 120;
  10.180 +    }
  10.181 +    
  10.182 +    @KOTest public void factorial6() {
  10.183 +        assert new Factorial().factorial(6) == 720;
  10.184 +    }
  10.185 +    
  10.186 +    private static class R implements Runnable {
  10.187 +        int cnt;
  10.188 +        private final Thread initThread;
  10.189 +        
  10.190 +        public R() {
  10.191 +            initThread = Thread.currentThread();
  10.192 +        }
  10.193 +
  10.194 +        @Override
  10.195 +        public void run() {
  10.196 +            assert initThread == Thread.currentThread() : "Expecting to run in " + initThread + " but running in " + Thread.currentThread();
  10.197 +            cnt++;
  10.198 +        }
  10.199 +    }
  10.200 +    
  10.201 +    private static class C implements Callable<Boolean> {
  10.202 +        @Override
  10.203 +        public Boolean call() throws Exception {
  10.204 +            return Boolean.TRUE;
  10.205 +        }
  10.206 +    }
  10.207 +}
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/json-tck/src/main/java/net/java/html/js/tests/Sum.java	Tue Jan 07 08:48:40 2014 +0100
    11.3 @@ -0,0 +1,53 @@
    11.4 +/**
    11.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    11.6 + *
    11.7 + * Copyright 2013-2013 Oracle and/or its affiliates. All rights reserved.
    11.8 + *
    11.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
   11.10 + * Other names may be trademarks of their respective owners.
   11.11 + *
   11.12 + * The contents of this file are subject to the terms of either the GNU
   11.13 + * General Public License Version 2 only ("GPL") or the Common
   11.14 + * Development and Distribution License("CDDL") (collectively, the
   11.15 + * "License"). You may not use this file except in compliance with the
   11.16 + * License. You can obtain a copy of the License at
   11.17 + * http://www.netbeans.org/cddl-gplv2.html
   11.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   11.19 + * specific language governing permissions and limitations under the
   11.20 + * License.  When distributing the software, include this License Header
   11.21 + * Notice in each file and include the License file at
   11.22 + * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
   11.23 + * particular file as subject to the "Classpath" exception as provided
   11.24 + * by Oracle in the GPL Version 2 section of the License file that
   11.25 + * accompanied this code. If applicable, add the following below the
   11.26 + * License Header, with the fields enclosed by brackets [] replaced by
   11.27 + * your own identifying information:
   11.28 + * "Portions Copyrighted [year] [name of copyright owner]"
   11.29 + *
   11.30 + * Contributor(s):
   11.31 + *
   11.32 + * The Original Software is NetBeans. The Initial Developer of the Original
   11.33 + * Software is Oracle. Portions Copyright 2013-2013 Oracle. All Rights Reserved.
   11.34 + *
   11.35 + * If you wish your version of this file to be governed by only the CDDL
   11.36 + * or only the GPL Version 2, indicate your decision by adding
   11.37 + * "[Contributor] elects to include this software in this distribution
   11.38 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
   11.39 + * single choice of license, a recipient has the option to distribute
   11.40 + * your version of this file under either the CDDL, the GPL Version 2 or
   11.41 + * to extend the choice of license to its licensees as provided above.
   11.42 + * However, if you add GPL Version 2 code and therefore, elected the GPL
   11.43 + * Version 2 license, then the option applies only if the new code is
   11.44 + * made subject to such option by the copyright holder.
   11.45 + */
   11.46 +package net.java.html.js.tests;
   11.47 +
   11.48 +/**
   11.49 + *
   11.50 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   11.51 + */
   11.52 +public final class Sum {
   11.53 +    public int sum(int a, int b) {
   11.54 +        return a + b;
   11.55 +    }
   11.56 +}
    12.1 --- a/json-tck/src/main/java/net/java/html/json/tests/KnockoutTest.java	Tue Jan 07 08:44:50 2014 +0100
    12.2 +++ b/json-tck/src/main/java/net/java/html/json/tests/KnockoutTest.java	Tue Jan 07 08:48:40 2014 +0100
    12.3 @@ -302,9 +302,10 @@
    12.4              + "</ul>\n"
    12.5          );
    12.6          try {
    12.7 -            KnockoutModel m = Models.bind(new KnockoutModel(), newContext());
    12.8 +            final BrwsrCtx c = newContext();
    12.9 +            KnockoutModel m = Models.bind(new KnockoutModel(), c);
   12.10  
   12.11 -            final Person first = Models.bind(new Person(), newContext());
   12.12 +            final Person first = Models.bind(new Person(), c);
   12.13              first.setFirstName("first");
   12.14              m.getPeople().add(first);
   12.15  
   12.16 @@ -313,7 +314,7 @@
   12.17              int cnt = countChildren("ul");
   12.18              assert cnt == 1 : "One child, but was " + cnt;
   12.19  
   12.20 -            final Person second = Models.bind(new Person(), newContext());
   12.21 +            final Person second = Models.bind(new Person(), c);
   12.22              second.setFirstName("second");
   12.23              m.getPeople().add(second);
   12.24  
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/json-tck/src/main/java/org/apidesign/html/json/tck/JavaScriptTCK.java	Tue Jan 07 08:48:40 2014 +0100
    13.3 @@ -0,0 +1,67 @@
    13.4 +/**
    13.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    13.6 + *
    13.7 + * Copyright 2013-2013 Oracle and/or its affiliates. All rights reserved.
    13.8 + *
    13.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
   13.10 + * Other names may be trademarks of their respective owners.
   13.11 + *
   13.12 + * The contents of this file are subject to the terms of either the GNU
   13.13 + * General Public License Version 2 only ("GPL") or the Common
   13.14 + * Development and Distribution License("CDDL") (collectively, the
   13.15 + * "License"). You may not use this file except in compliance with the
   13.16 + * License. You can obtain a copy of the License at
   13.17 + * http://www.netbeans.org/cddl-gplv2.html
   13.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   13.19 + * specific language governing permissions and limitations under the
   13.20 + * License.  When distributing the software, include this License Header
   13.21 + * Notice in each file and include the License file at
   13.22 + * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
   13.23 + * particular file as subject to the "Classpath" exception as provided
   13.24 + * by Oracle in the GPL Version 2 section of the License file that
   13.25 + * accompanied this code. If applicable, add the following below the
   13.26 + * License Header, with the fields enclosed by brackets [] replaced by
   13.27 + * your own identifying information:
   13.28 + * "Portions Copyrighted [year] [name of copyright owner]"
   13.29 + *
   13.30 + * Contributor(s):
   13.31 + *
   13.32 + * The Original Software is NetBeans. The Initial Developer of the Original
   13.33 + * Software is Oracle. Portions Copyright 2013-2013 Oracle. All Rights Reserved.
   13.34 + *
   13.35 + * If you wish your version of this file to be governed by only the CDDL
   13.36 + * or only the GPL Version 2, indicate your decision by adding
   13.37 + * "[Contributor] elects to include this software in this distribution
   13.38 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
   13.39 + * single choice of license, a recipient has the option to distribute
   13.40 + * your version of this file under either the CDDL, the GPL Version 2 or
   13.41 + * to extend the choice of license to its licensees as provided above.
   13.42 + * However, if you add GPL Version 2 code and therefore, elected the GPL
   13.43 + * Version 2 license, then the option applies only if the new code is
   13.44 + * made subject to such option by the copyright holder.
   13.45 + */
   13.46 +package org.apidesign.html.json.tck;
   13.47 +
   13.48 +import net.java.html.js.tests.JavaScriptBodyTest;
   13.49 +import org.apidesign.html.boot.spi.Fn;
   13.50 +
   13.51 +/** Subclass this class, implements is abstract methods (if any).
   13.52 + *
   13.53 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   13.54 + * @sine 0.7
   13.55 + */
   13.56 +public abstract class JavaScriptTCK {
   13.57 +    /** Gives you list of classes included in the TCK. Their test methods
   13.58 +     * are annotated by {@link KOTest} annotation. The methods are public
   13.59 +     * instance methods that take no arguments. The method should be 
   13.60 +     * invoke in a presenter context {@link Fn#activate(org.apidesign.html.boot.spi.Fn.Presenter)}.
   13.61 +     * 
   13.62 +     * @return classes with methods annotated by {@link KOTest} annotation
   13.63 +     */
   13.64 +    protected static Class<?>[] testClasses() {
   13.65 +        return new Class[] { 
   13.66 +            JavaScriptBodyTest.class
   13.67 +        };
   13.68 +    }
   13.69 +    
   13.70 +}
    14.1 --- a/json-tck/src/main/java/org/apidesign/html/json/tck/KnockoutTCK.java	Tue Jan 07 08:44:50 2014 +0100
    14.2 +++ b/json-tck/src/main/java/org/apidesign/html/json/tck/KnockoutTCK.java	Tue Jan 07 08:48:40 2014 +0100
    14.3 @@ -109,7 +109,7 @@
    14.4       * are annotated by {@link KOTest} annotation. The methods are public
    14.5       * instance methods that take no arguments.
    14.6       * 
    14.7 -     * @return classes with methods annotated by {@link BrwsrTest} annotation
    14.8 +     * @return classes with methods annotated by {@link KOTest} annotation
    14.9       */
   14.10      protected static Class<?>[] testClasses() {
   14.11          return new Class[] {