Better to not do any processign as '...*/*...' string can break our simple check. Keep comments in and let obfuscator remove them
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Sun, 30 Nov 2014 16:21:27 +0100
changeset 17325ab1cb07a530
parent 1731 212379f827b6
child 1733 955520296b08
Better to not do any processign as '...*/*...' string can break our simple check. Keep comments in and let obfuscator remove them
rt/emul/compacttest/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/HtmlAnnotationsTest.java
rt/emul/compacttest/src/test/resources/org/apidesign/bck2brwsr/vmtest/impl/htmlannotations.js
rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java
     1.1 --- a/rt/emul/compacttest/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/HtmlAnnotationsTest.java	Thu Nov 27 20:31:17 2014 +0100
     1.2 +++ b/rt/emul/compacttest/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/HtmlAnnotationsTest.java	Sun Nov 30 16:21:27 2014 +0100
     1.3 @@ -31,7 +31,7 @@
     1.4      
     1.5      private void assertMulNotDefinedForTheFirstTime() {
     1.6          if (firstCheck++ == 0) {
     1.7 -            Object mul = windowMul();
     1.8 +            Object mul = window("mul");
     1.9              assert mul == null : "htmlannotations.js should not be processed before first call to HtmlAnnotations class";
    1.10          }
    1.11      }
    1.12 @@ -70,6 +70,14 @@
    1.13          assertEquals(HtmlAnnotations.onError(instance, 42.0), 42.0);
    1.14      }
    1.15      
    1.16 +    @BrwsrTest public void quotedStar() throws Exception {
    1.17 +        assertMulNotDefinedForTheFirstTime();
    1.18 +        HtmlAnnotations.empty();
    1.19 +        Object fn = window("all");
    1.20 +        String msg = invoke(fn);
    1.21 +        assert "*/*".equals(msg) : "String '*/*' as expected: " + msg;
    1.22 +    }
    1.23 +    
    1.24      private static void assertEquals(double real, double exp) {
    1.25          if (real - exp < 0.01) {
    1.26              return;
    1.27 @@ -81,8 +89,10 @@
    1.28          assert obj != null : msg;
    1.29      }
    1.30      
    1.31 -    @JavaScriptBody(args = {}, body = "return window.mul ? window.mul : null;")
    1.32 -    private static native Object windowMul();
    1.33 +    @JavaScriptBody(args = { "n" }, body = "return window[n] ? window[n] : null;")
    1.34 +    private static native Object window(String name);
    1.35 +    @JavaScriptBody(args = { "fn" }, body = "return fn();")
    1.36 +    private static native String invoke(Object fn);
    1.37      
    1.38      @Factory public static Object[] create() {
    1.39          return VMTest.create(HtmlAnnotationsTest.class);
     2.1 --- a/rt/emul/compacttest/src/test/resources/org/apidesign/bck2brwsr/vmtest/impl/htmlannotations.js	Thu Nov 27 20:31:17 2014 +0100
     2.2 +++ b/rt/emul/compacttest/src/test/resources/org/apidesign/bck2brwsr/vmtest/impl/htmlannotations.js	Sun Nov 30 16:21:27 2014 +0100
     2.3 @@ -17,4 +17,6 @@
     2.4   */
     2.5  
     2.6  function mul(x, y) { return x * y; }
     2.7 +function all() { return '*/*'; }
     2.8  window.mul = mul;
     2.9 +window.all = all;
     3.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java	Thu Nov 27 20:31:17 2014 +0100
     3.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java	Sun Nov 30 16:21:27 2014 +0100
     3.3 @@ -263,7 +263,9 @@
     3.4          if (emul == null) {
     3.5              throw new IOException("Can't find " + resource);
     3.6          }
     3.7 +        append("\n// resource from ").append(resource).append("\n");
     3.8          readResource(emul, this);
     3.9 +        append("\n");
    3.10      }
    3.11  
    3.12      private static void readResource(InputStream emul, Appendable out) throws IOException {
    3.13 @@ -277,35 +279,7 @@
    3.14                  if (ch < 0 || ch > 255) {
    3.15                      throw new IOException("Invalid char in emulation " + ch);
    3.16                  }
    3.17 -                switch (state) {
    3.18 -                    case 0: 
    3.19 -                        if (ch == '/') {
    3.20 -                            state = 1;
    3.21 -                        } else {
    3.22 -                            out.append((char)ch);
    3.23 -                        }
    3.24 -                        break;
    3.25 -                    case 1:
    3.26 -                        if (ch == '*') {
    3.27 -                            state = 2;
    3.28 -                        } else {
    3.29 -                            out.append('/').append((char)ch);
    3.30 -                            state = 0;
    3.31 -                        }
    3.32 -                        break;
    3.33 -                    case 2:
    3.34 -                        if (ch == '*') {
    3.35 -                            state = 3;
    3.36 -                        }
    3.37 -                        break;
    3.38 -                    case 3:
    3.39 -                        if (ch == '/') {
    3.40 -                            state = 0;
    3.41 -                        } else {
    3.42 -                            state = 2;
    3.43 -                        }
    3.44 -                        break;
    3.45 -                }
    3.46 +                out.append((char)ch);
    3.47              }
    3.48          } finally {
    3.49              emul.close();