Check types of primitive values and their wrappers passed to JavaScript and what type they have UniversalKO
authorJaroslav Tulach <jaroslav.tulach@netbeans.org>
Wed, 08 Jan 2014 16:46:42 +0100
branchUniversalKO
changeset 436e48fbed169c1
parent 435 ff846f5f2f66
child 437 280f69ca06ec
Check types of primitive values and their wrappers passed to JavaScript and what type they have
json-tck/src/main/java/net/java/html/js/tests/Bodies.java
json-tck/src/main/java/net/java/html/js/tests/JavaScriptBodyTest.java
     1.1 --- a/json-tck/src/main/java/net/java/html/js/tests/Bodies.java	Wed Jan 08 15:50:50 2014 +0100
     1.2 +++ b/json-tck/src/main/java/net/java/html/js/tests/Bodies.java	Wed Jan 08 16:46:42 2014 +0100
     1.3 @@ -85,8 +85,11 @@
     1.4      @JavaScriptBody(args = { "arr" }, body = "return arr.length;")
     1.5      public static native int length(Object[] arr);
     1.6      
     1.7 -    @JavaScriptBody(args = { "o" }, body = "return typeof o;")
     1.8 -    public static native String typeof(Object o);
     1.9 +    @JavaScriptBody(args = { "o", "vo" }, body = "if (vo) o = o.valueOf(); return typeof o;")
    1.10 +    public static native String typeof(Object o, boolean useValueOf);
    1.11 +
    1.12 +    @JavaScriptBody(args = { "b" }, body = "return typeof b;")
    1.13 +    public static native String typeof(boolean b);
    1.14  
    1.15      @JavaScriptBody(args = { "o" }, body = "return Array.isArray(o);")
    1.16      public static native boolean isArray(Object o);
     2.1 --- a/json-tck/src/main/java/net/java/html/js/tests/JavaScriptBodyTest.java	Wed Jan 08 15:50:50 2014 +0100
     2.2 +++ b/json-tck/src/main/java/net/java/html/js/tests/JavaScriptBodyTest.java	Wed Jan 08 16:46:42 2014 +0100
     2.3 @@ -74,6 +74,55 @@
     2.4          Bodies.callback(run);
     2.5          assert run.cnt == 1 : "Can call even private implementation classes: " + run.cnt;
     2.6      }
     2.7 +    
     2.8 +    @KOTest public void typeOfCharacter() {
     2.9 +        String charType = Bodies.typeof('a', false);
    2.10 +        assert "number".equals(charType) : "Expecting number type: " + charType;
    2.11 +    }
    2.12 +    @KOTest public void typeOfBoolean() {
    2.13 +        String booleanType = Bodies.typeof(true, false);
    2.14 +        assert "boolean".equals(booleanType) : "Expecting boolean type: " + booleanType;
    2.15 +    }
    2.16 +
    2.17 +    @KOTest public void typeOfPrimitiveBoolean() {
    2.18 +        String booleanType = Bodies.typeof(true);
    2.19 +        assert "boolean".equals(booleanType) : "Expecting boolean type: " + booleanType;
    2.20 +    }
    2.21 +
    2.22 +    @KOTest public void typeOfInteger() {
    2.23 +        String intType = Bodies.typeof(1, false);
    2.24 +        assert "number".equals(intType) : "Expecting number type: " + intType;
    2.25 +    }
    2.26 +
    2.27 +    @KOTest public void typeOfString() {
    2.28 +        String strType = Bodies.typeof("Ahoj", false);
    2.29 +        assert "string".equals(strType) : "Expecting string type: " + strType;
    2.30 +    }
    2.31 +
    2.32 +    @KOTest public void typeOfDouble() {
    2.33 +        String doubleType = Bodies.typeof(0.33, false);
    2.34 +        assert "number".equals(doubleType) : "Expecting number type: " + doubleType;
    2.35 +    }
    2.36 +    
    2.37 +    @KOTest public void typeOfBooleanValueOf() {
    2.38 +        String booleanType = Bodies.typeof(true, true);
    2.39 +        assert "boolean".equals(booleanType) : "Expecting boolean type: " + booleanType;
    2.40 +    }
    2.41 +
    2.42 +    @KOTest public void typeOfIntegerValueOf() {
    2.43 +        String intType = Bodies.typeof(1, true);
    2.44 +        assert "number".equals(intType) : "Expecting number type: " + intType;
    2.45 +    }
    2.46 +
    2.47 +    @KOTest public void typeOfStringValueOf() {
    2.48 +        String strType = Bodies.typeof("Ahoj", true);
    2.49 +        assert "string".equals(strType) : "Expecting string type: " + strType;
    2.50 +    }
    2.51 +
    2.52 +    @KOTest public void typeOfDoubleValueOf() {
    2.53 +        String doubleType = Bodies.typeof(0.33, true);
    2.54 +        assert "number".equals(doubleType) : "Expecting number type: " + doubleType;
    2.55 +    }
    2.56  
    2.57      @KOTest public void computeInARunnable() {
    2.58          final int[] sum = new int[2];