# HG changeset patch # User Jaroslav Tulach # Date 1461815692 -7200 # Node ID 5e8d764813f326361c4901eae4d588db5eec08f9 # Parent 693d35afc8c8754e1914bcf7f4d500b8d29f0020 Only eval @JavaScriptBody resources, no other ones as those usually refer to internals of the VM diff -r 693d35afc8c8 -r 5e8d764813f3 rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java Wed Apr 27 18:14:25 2016 +0200 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java Thu Apr 28 05:54:52 2016 +0200 @@ -245,7 +245,7 @@ while (resource.startsWith("/")) { resource = resource.substring(1); } - requireResourceImpl(resource); + requireResourceImpl(false, resource); asBinary.remove(resource); } scripts = new StringArray(); @@ -266,18 +266,24 @@ } } - final void requireResourceImpl(String resource) throws IOException { + final void requireResourceImpl(boolean useEval, String resource) throws IOException { InputStream emul = resources.get(resource); if (emul == null) { throw new IOException("Can't find " + resource); } append("\n// resource from ").append(resource).append("\n"); - append("\neval(\""); - readResource(emul, this); - append("\");\n"); + append("\n"); + if (useEval) { + append("eval(\""); + } + readResource(useEval, emul, this); + if (useEval) { + append("\");"); + } + append("\n"); } - private static void readResource(InputStream emul, Appendable out) throws IOException { + private static void readResource(boolean escape, InputStream emul, Appendable out) throws IOException { try { for (;;) { int ch = emul.read(); @@ -287,24 +293,28 @@ if (ch < 0 || ch > 255) { throw new IOException("Invalid char in emulation " + ch); } - switch (ch) { - case '"': - out.append("\\\""); - break; - case '\\': - out.append("\\\\"); - break; - case '\n': - out.append("\\n\"\n + \""); - break; - case '\t': - out.append("\\t"); - break; - case '\r': - out.append("\\r"); - break; - default: - out.append((char)ch); + if (escape) { + switch (ch) { + case '"': + out.append("\\\""); + break; + case '\\': + out.append("\\\\"); + break; + case '\n': + out.append("\\n\"\n + \""); + break; + case '\t': + out.append("\\t"); + break; + case '\r': + out.append("\\r"); + break; + default: + out.append((char)ch); + } + } else { + out.append((char)ch); } } } finally { @@ -759,7 +769,7 @@ @Override protected void requireResource(String resourcePath) throws IOException { - requireResourceImpl(resourcePath); + requireResourceImpl(true, resourcePath); super.asBinary.remove(resourcePath); } } @@ -878,7 +888,7 @@ @Override protected void requireResource(String resourcePath) throws IOException { - requireResourceImpl(resourcePath); + requireResourceImpl(true, resourcePath); super.asBinary.remove(resourcePath); } }