1.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethodTest.java Sun Dec 09 16:43:36 2012 +0100
1.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethodTest.java Wed Dec 12 09:09:42 2012 +0100
1.3 @@ -20,6 +20,9 @@
1.4 import java.io.File;
1.5 import java.io.FileWriter;
1.6 import java.io.IOException;
1.7 +import java.io.InputStream;
1.8 +import java.net.URL;
1.9 +import java.util.Enumeration;
1.10 import javax.script.Invocable;
1.11 import javax.script.ScriptEngine;
1.12 import javax.script.ScriptEngineManager;
1.13 @@ -269,7 +272,8 @@
1.14 ) throws Exception {
1.15 Object ret = null;
1.16 try {
1.17 - ret = toRun.invokeFunction(clazz.getName().replace('.', '_'), true);
1.18 + ret = toRun.invokeFunction("bck2brwsr");
1.19 + ret = toRun.invokeMethod(ret, "loadClass", clazz.getName());
1.20 ret = toRun.invokeMethod(ret, method, args);
1.21 } catch (ScriptException ex) {
1.22 fail("Execution failed in\n" + dumpJS(theCode), ex);
1.23 @@ -295,7 +299,7 @@
1.24 if (sb == null) {
1.25 sb = new StringBuilder();
1.26 }
1.27 - GenJS.compile(sb, names);
1.28 + Bck2Brwsr.generate(sb, new EmulationResources(), names);
1.29 ScriptEngineManager sem = new ScriptEngineManager();
1.30 ScriptEngine js = sem.getEngineByExtension("js");
1.31 if (eng != null) {
1.32 @@ -320,4 +324,21 @@
1.33 w.close();
1.34 return new StringBuilder(f.getPath());
1.35 }
1.36 + private static class EmulationResources implements Bck2Brwsr.Resources {
1.37 + @Override
1.38 + public InputStream get(String name) throws IOException {
1.39 + Enumeration<URL> en = StaticMethodTest.class.getClassLoader().getResources(name);
1.40 + URL u = null;
1.41 + while (en.hasMoreElements()) {
1.42 + u = en.nextElement();
1.43 + }
1.44 + if (u == null) {
1.45 + throw new IOException("Can't find " + name);
1.46 + }
1.47 + if (u.toExternalForm().contains("rt.jar!")) {
1.48 + throw new IOException("No emulation for " + u);
1.49 + }
1.50 + return u.openStream();
1.51 + }
1.52 + }
1.53 }