# HG changeset patch # User Jaroslav Tulach # Date 1356036873 -3600 # Node ID 86f3ea771e248a5213d88a4e1b8b7cbae93197a4 # Parent 67fef1fda66751de8d69eb8e6ce556c7d804d935 Moving the read method closer to the definition of the script diff -r 67fef1fda667 -r 86f3ea771e24 launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java Thu Dec 20 21:53:58 2012 +0100 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java Thu Dec 20 21:54:33 2012 +0100 @@ -130,7 +130,7 @@ ScriptEngine mach = sem.getEngineByExtension(sen); sb.append( - "\nvar vm = bck2brwsr(org.apidesign.bck2brwsr.vmtest.VMTest.read);" + "\nvar vm = new bck2brwsr(org.apidesign.bck2brwsr.launcher.Console.read);" + "\nfunction initVM() { return vm; };" + "\n"); diff -r 67fef1fda667 -r 86f3ea771e24 launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Console.java --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Console.java Thu Dec 20 21:53:58 2012 +0100 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Console.java Thu Dec 20 21:54:33 2012 +0100 @@ -17,9 +17,12 @@ */ package org.apidesign.bck2brwsr.launcher; +import java.io.IOException; +import java.io.InputStream; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URL; +import java.util.Enumeration; import org.apidesign.bck2brwsr.core.JavaScriptBody; /** @@ -89,6 +92,37 @@ return r == null ? "null" : r.toString().toString(); } + /** Helper method that inspects the classpath and loads given resource + * (usually a class file). Used while running tests in Rhino. + * + * @param name resource name to find + * @return the array of bytes in the given resource + * @throws IOException I/O in case something goes wrong + */ + public static byte[] read(String name) throws IOException { + URL u = null; + Enumeration en = Console.class.getClassLoader().getResources(name); + while (en.hasMoreElements()) { + u = en.nextElement(); + } + if (u == null) { + throw new IOException("Can't find " + name); + } + try (InputStream is = u.openStream()) { + byte[] arr; + arr = new byte[is.available()]; + int offset = 0; + while (offset < arr.length) { + int len = is.read(arr, offset, arr.length - offset); + if (len == -1) { + throw new IOException("Can't read " + name); + } + offset += len; + } + return arr; + } + } + private static Object invokeMethod(String clazz, String method) throws ClassNotFoundException, InvocationTargetException, SecurityException, IllegalAccessException, IllegalArgumentException { diff -r 67fef1fda667 -r 86f3ea771e24 vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/VMTest.java --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/VMTest.java Thu Dec 20 21:53:58 2012 +0100 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/VMTest.java Thu Dec 20 21:54:33 2012 +0100 @@ -20,10 +20,7 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; -import java.io.InputStream; import java.lang.reflect.Method; -import java.net.URL; -import java.util.Enumeration; import java.util.Map; import java.util.WeakHashMap; import java.util.logging.Level; @@ -111,37 +108,6 @@ return m.getName() + "[Compare " + second.typeName() + "]"; } - /** Helper method that inspects the classpath and loads given resource - * (usually a class file). Used while running tests in Rhino. - * - * @param name resource name to find - * @return the array of bytes in the given resource - * @throws IOException I/O in case something goes wrong - */ - public static byte[] read(String name) throws IOException { - URL u = null; - Enumeration en = VMTest.class.getClassLoader().getResources(name); - while (en.hasMoreElements()) { - u = en.nextElement(); - } - if (u == null) { - throw new IOException("Can't find " + name); - } - try (InputStream is = u.openStream()) { - byte[] arr; - arr = new byte[is.available()]; - int offset = 0; - while (offset < arr.length) { - int len = is.read(arr, offset, arr.length - offset); - if (len == -1) { - throw new IOException("Can't read " + name); - } - offset += len; - } - return arr; - } - } - public static final class Run implements ITest { private final Method m; private final int type;