# HG changeset patch # User Jaroslav Tulach # Date 1461815972 -7200 # Node ID ebda6f4d0336d68e7749b1a1d453f132c32ab224 # Parent 72ef454e3987112028c2935b11ca0085a64313db# Parent 40b0f05e2545518a21da594d327d2ea033f14fe6 Merging eval(@JavaScriptBody) diff -r 72ef454e3987 -r ebda6f4d0336 ko/kosample/pom.xml --- a/ko/kosample/pom.xml Wed Apr 27 07:28:33 2016 +0200 +++ b/ko/kosample/pom.xml Thu Apr 28 05:59:32 2016 +0200 @@ -20,7 +20,7 @@ ${project.version} - MINIMAL + FULL 2.13 UTF-8 diff -r 72ef454e3987 -r ebda6f4d0336 rt/emul/compacttest/src/test/resources/org/apidesign/bck2brwsr/vmtest/impl/htmlannotations.js --- a/rt/emul/compacttest/src/test/resources/org/apidesign/bck2brwsr/vmtest/impl/htmlannotations.js Wed Apr 27 07:28:33 2016 +0200 +++ b/rt/emul/compacttest/src/test/resources/org/apidesign/bck2brwsr/vmtest/impl/htmlannotations.js Thu Apr 28 05:59:32 2016 +0200 @@ -18,5 +18,3 @@ function mul(x, y) { return x * y; } function all() { return '*/*'; } -window.mul = mul; -window.all = all; diff -r 72ef454e3987 -r ebda6f4d0336 rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java Wed Apr 27 07:28:33 2016 +0200 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java Thu Apr 28 05:59:32 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,19 +266,25 @@ } } - 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"); - readResource(emul, this); + append("\n"); + if (useEval) { + append("(0 || 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 { - int state = 0; for (;;) { int ch = emul.read(); if (ch == -1) { @@ -287,7 +293,29 @@ if (ch < 0 || ch > 255) { throw new IOException("Invalid char in emulation " + ch); } - 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 { emul.close(); @@ -741,7 +769,7 @@ @Override protected void requireResource(String resourcePath) throws IOException { - requireResourceImpl(resourcePath); + requireResourceImpl(true, resourcePath); super.asBinary.remove(resourcePath); } } @@ -860,7 +888,7 @@ @Override protected void requireResource(String resourcePath) throws IOException { - requireResourceImpl(resourcePath); + requireResourceImpl(true, resourcePath); super.asBinary.remove(resourcePath); } }