Need the ability to cast to any type to successfully run tests on VM with exceptions support exceptions
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Sun, 09 Dec 2012 16:44:27 +0100
branchexceptions
changeset 292fc3f6ea5e246
parent 290 57dff70280c7
parent 291 c6f21b56a6cf
child 376 059cb07ac9b3
Need the ability to cast to any type to successfully run tests on VM with exceptions support
vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java
     1.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Sun Dec 09 16:32:29 2012 +0100
     1.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Sun Dec 09 16:44:27 2012 +0100
     1.3 @@ -770,9 +770,9 @@
     1.4                      final String type = jc.getClassName(indx);
     1.5                      if (!type.startsWith("[")) {
     1.6                          // no way to check arrays right now
     1.7 -                        out.append("if(s[s.length - 1].$instOf_")
     1.8 +                        out.append("if(s[s.length - 1] !== null && !s[s.length - 1].$instOf_")
     1.9                             .append(type.replace('/', '_'))
    1.10 -                           .append(" != 1) throw {};"); // XXX proper exception
    1.11 +                           .append(") throw {};"); // XXX proper exception
    1.12                      }
    1.13                      i += 2;
    1.14                      break;
     2.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethod.java	Sun Dec 09 16:32:29 2012 +0100
     2.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethod.java	Sun Dec 09 16:44:27 2012 +0100
     2.3 @@ -106,6 +106,11 @@
     2.4          throw new IllegalStateException();
     2.5      }
     2.6      
     2.7 +    public static String castNull(boolean n) {
     2.8 +        Object value = n ? null : "Ahoj";
     2.9 +        return (String)value;
    2.10 +    }
    2.11 +    
    2.12      public static String swtch(int what) {
    2.13          switch (what) {
    2.14              case 0: return "Jarda";
     3.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethodTest.java	Sun Dec 09 16:32:29 2012 +0100
     3.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethodTest.java	Sun Dec 09 16:44:27 2012 +0100
     3.3 @@ -238,6 +238,13 @@
     3.4          );
     3.5      }
     3.6      
     3.7 +    @Test public void checkNullCast() throws Exception {
     3.8 +        assertExec("Null can be cast to any type",
     3.9 +            StaticMethod.class, "castNull__Ljava_lang_String_2Z", 
    3.10 +            null, true
    3.11 +        );
    3.12 +    }
    3.13 +    
    3.14      private static CharSequence codeSeq;
    3.15      private static Invocable code;
    3.16