Only eval @JavaScriptBody resources, no other ones as those usually refer to internals of the VM
1.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java Wed Apr 27 18:14:25 2016 +0200
1.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java Thu Apr 28 05:54:52 2016 +0200
1.3 @@ -245,7 +245,7 @@
1.4 while (resource.startsWith("/")) {
1.5 resource = resource.substring(1);
1.6 }
1.7 - requireResourceImpl(resource);
1.8 + requireResourceImpl(false, resource);
1.9 asBinary.remove(resource);
1.10 }
1.11 scripts = new StringArray();
1.12 @@ -266,18 +266,24 @@
1.13 }
1.14 }
1.15
1.16 - final void requireResourceImpl(String resource) throws IOException {
1.17 + final void requireResourceImpl(boolean useEval, String resource) throws IOException {
1.18 InputStream emul = resources.get(resource);
1.19 if (emul == null) {
1.20 throw new IOException("Can't find " + resource);
1.21 }
1.22 append("\n// resource from ").append(resource).append("\n");
1.23 - append("\neval(\"");
1.24 - readResource(emul, this);
1.25 - append("\");\n");
1.26 + append("\n");
1.27 + if (useEval) {
1.28 + append("eval(\"");
1.29 + }
1.30 + readResource(useEval, emul, this);
1.31 + if (useEval) {
1.32 + append("\");");
1.33 + }
1.34 + append("\n");
1.35 }
1.36
1.37 - private static void readResource(InputStream emul, Appendable out) throws IOException {
1.38 + private static void readResource(boolean escape, InputStream emul, Appendable out) throws IOException {
1.39 try {
1.40 for (;;) {
1.41 int ch = emul.read();
1.42 @@ -287,24 +293,28 @@
1.43 if (ch < 0 || ch > 255) {
1.44 throw new IOException("Invalid char in emulation " + ch);
1.45 }
1.46 - switch (ch) {
1.47 - case '"':
1.48 - out.append("\\\"");
1.49 - break;
1.50 - case '\\':
1.51 - out.append("\\\\");
1.52 - break;
1.53 - case '\n':
1.54 - out.append("\\n\"\n + \"");
1.55 - break;
1.56 - case '\t':
1.57 - out.append("\\t");
1.58 - break;
1.59 - case '\r':
1.60 - out.append("\\r");
1.61 - break;
1.62 - default:
1.63 - out.append((char)ch);
1.64 + if (escape) {
1.65 + switch (ch) {
1.66 + case '"':
1.67 + out.append("\\\"");
1.68 + break;
1.69 + case '\\':
1.70 + out.append("\\\\");
1.71 + break;
1.72 + case '\n':
1.73 + out.append("\\n\"\n + \"");
1.74 + break;
1.75 + case '\t':
1.76 + out.append("\\t");
1.77 + break;
1.78 + case '\r':
1.79 + out.append("\\r");
1.80 + break;
1.81 + default:
1.82 + out.append((char)ch);
1.83 + }
1.84 + } else {
1.85 + out.append((char)ch);
1.86 }
1.87 }
1.88 } finally {
1.89 @@ -759,7 +769,7 @@
1.90
1.91 @Override
1.92 protected void requireResource(String resourcePath) throws IOException {
1.93 - requireResourceImpl(resourcePath);
1.94 + requireResourceImpl(true, resourcePath);
1.95 super.asBinary.remove(resourcePath);
1.96 }
1.97 }
1.98 @@ -878,7 +888,7 @@
1.99
1.100 @Override
1.101 protected void requireResource(String resourcePath) throws IOException {
1.102 - requireResourceImpl(resourcePath);
1.103 + requireResourceImpl(true, resourcePath);
1.104 super.asBinary.remove(resourcePath);
1.105 }
1.106 }