diff -r daa5f903b529 -r ba912ef24b27 rt/vm/src/test/java/org/apidesign/vm4brwsr/TestVM.java --- a/rt/vm/src/test/java/org/apidesign/vm4brwsr/TestVM.java Mon Apr 28 20:23:44 2014 +0200 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/TestVM.java Wed Apr 30 15:04:10 2014 +0200 @@ -25,23 +25,33 @@ import java.net.URL; import java.util.Enumeration; import javax.script.Invocable; +import javax.script.ScriptContext; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; import static org.testng.Assert.*; -final class TestVM { +public final class TestVM { private final Invocable code; private final CharSequence codeSeq; private final Object bck2brwsr; + private BytesLoader resources; private TestVM(Invocable code, CharSequence codeSeq) throws ScriptException, NoSuchMethodException { this.code = code; this.codeSeq = codeSeq; - this.bck2brwsr = code.invokeFunction("bck2brwsr"); + this.bck2brwsr = ((ScriptEngine)code).eval("bck2brwsr(function(n) { return loader.get(n); })"); + ((ScriptEngine)code).getContext().setAttribute("loader", this, ScriptContext.ENGINE_SCOPE); } + public void register(BytesLoader res) { + this.resources = res; + } + + public byte[] get(String res) throws IOException { + return resources != null ? resources.get(res) : null; + } public Object execCode( String msg, Class clazz, String method, @@ -234,11 +244,26 @@ return ex.toString(); } } - + + final CharSequence codeSeq() { + return codeSeq; + } private static class EmulationResources implements Bck2Brwsr.Resources { @Override public InputStream get(String name) throws IOException { + if ("java/net/URI.class".equals(name)) { + // skip + return null; + } + if ("java/net/URLConnection.class".equals(name)) { + // skip + return null; + } + if ("java/lang/System.class".equals(name)) { + // skip + return null; + } Enumeration en = StaticMethodTest.class.getClassLoader().getResources(name); URL u = null; while (en.hasMoreElements()) {