1.1 --- a/rt/vm/src/test/java/org/apidesign/vm4brwsr/TestVM.java Sat Oct 05 07:23:48 2013 +0200
1.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/TestVM.java Fri Oct 11 09:58:03 2013 +0200
1.3 @@ -24,23 +24,33 @@
1.4 import java.net.URL;
1.5 import java.util.Enumeration;
1.6 import javax.script.Invocable;
1.7 +import javax.script.ScriptContext;
1.8 import javax.script.ScriptEngine;
1.9 import javax.script.ScriptEngineManager;
1.10 import javax.script.ScriptException;
1.11 import static org.testng.Assert.*;
1.12
1.13 -final class TestVM {
1.14 +public final class TestVM {
1.15 private final Invocable code;
1.16 private final CharSequence codeSeq;
1.17 private final Object bck2brwsr;
1.18 + private BytesLoader resources;
1.19
1.20
1.21 private TestVM(Invocable code, CharSequence codeSeq) throws ScriptException, NoSuchMethodException {
1.22 this.code = code;
1.23 this.codeSeq = codeSeq;
1.24 - this.bck2brwsr = code.invokeFunction("bck2brwsr");
1.25 + this.bck2brwsr = ((ScriptEngine)code).eval("bck2brwsr(function(n) { return loader.get(n); })");
1.26 + ((ScriptEngine)code).getContext().setAttribute("loader", this, ScriptContext.ENGINE_SCOPE);
1.27 }
1.28
1.29 + public void register(BytesLoader res) {
1.30 + this.resources = res;
1.31 + }
1.32 +
1.33 + public byte[] get(String res) throws IOException {
1.34 + return resources != null ? resources.get(res) : null;
1.35 + }
1.36
1.37 public Object execCode(
1.38 String msg, Class<?> clazz, String method,