eval(@JavaScriptResource) as string to prevent double obfuscation EvalResource
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Wed, 27 Apr 2016 18:14:25 +0200
branchEvalResource
changeset 1952693d35afc8c8
parent 1949 72ef454e3987
child 1953 5e8d764813f3
eval(@JavaScriptResource) as string to prevent double obfuscation
ko/kosample/pom.xml
rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java
     1.1 --- a/ko/kosample/pom.xml	Wed Apr 27 07:28:33 2016 +0200
     1.2 +++ b/ko/kosample/pom.xml	Wed Apr 27 18:14:25 2016 +0200
     1.3 @@ -20,7 +20,7 @@
     1.4      </modules>
     1.5      <properties>
     1.6          <bck2brwsr.version>${project.version}</bck2brwsr.version>
     1.7 -        <bck2brwsr.obfuscationlevel>MINIMAL</bck2brwsr.obfuscationlevel>
     1.8 +        <bck2brwsr.obfuscationlevel>FULL</bck2brwsr.obfuscationlevel>
     1.9          <jersey.version>2.13</jersey.version>
    1.10          <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    1.11      </properties>
     2.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java	Wed Apr 27 07:28:33 2016 +0200
     2.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java	Wed Apr 27 18:14:25 2016 +0200
     2.3 @@ -272,13 +272,13 @@
     2.4              throw new IOException("Can't find " + resource);
     2.5          }
     2.6          append("\n// resource from ").append(resource).append("\n");
     2.7 +        append("\neval(\"");
     2.8          readResource(emul, this);
     2.9 -        append("\n");
    2.10 +        append("\");\n");
    2.11      }
    2.12  
    2.13      private static void readResource(InputStream emul, Appendable out) throws IOException {
    2.14          try {
    2.15 -            int state = 0;
    2.16              for (;;) {
    2.17                  int ch = emul.read();
    2.18                  if (ch == -1) {
    2.19 @@ -287,7 +287,25 @@
    2.20                  if (ch < 0 || ch > 255) {
    2.21                      throw new IOException("Invalid char in emulation " + ch);
    2.22                  }
    2.23 -                out.append((char)ch);
    2.24 +                switch (ch) {
    2.25 +                    case '"':
    2.26 +                        out.append("\\\"");
    2.27 +                        break;
    2.28 +                    case '\\':
    2.29 +                        out.append("\\\\");
    2.30 +                        break;
    2.31 +                    case '\n':
    2.32 +                        out.append("\\n\"\n + \"");
    2.33 +                        break;
    2.34 +                    case '\t':
    2.35 +                        out.append("\\t");
    2.36 +                        break;
    2.37 +                    case '\r':
    2.38 +                        out.append("\\r");
    2.39 +                        break;
    2.40 +                    default:
    2.41 +                        out.append((char)ch);
    2.42 +                }
    2.43              }
    2.44          } finally {
    2.45              emul.close();