# HG changeset patch # User Jaroslav Tulach # Date 1355687301 -3600 # Node ID b5dd05670bef61a9a18402693b9ebdd2c980891e # Parent 4a653c70ca2051795deae039ca2645a1033043b8 Sharing the is -> byte[] loading algorithm diff -r 4a653c70ca20 -r b5dd05670bef vm/src/test/java/org/apidesign/vm4brwsr/BytesLoader.java --- a/vm/src/test/java/org/apidesign/vm4brwsr/BytesLoader.java Sun Dec 16 20:17:06 2012 +0100 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/BytesLoader.java Sun Dec 16 20:48:21 2012 +0100 @@ -33,6 +33,21 @@ if (!requested.add(name)) { throw new IllegalStateException("Requested for second time: " + name); } + byte[] arr = readClass(name); + /* + System.err.print("loader['" + name + "'] = ["); + for (int i = 0; i < arr.length; i++) { + if (i > 0) { + System.err.print(", "); + } + System.err.print(arr[i]); + } + System.err.println("]"); + */ + return arr; + } + + static byte[] readClass(String name) throws IOException { InputStream is = BytesLoader.class.getClassLoader().getResourceAsStream(name); if (is == null) { throw new IOException("Can't find " + name); @@ -46,16 +61,6 @@ } offset += len; } - /* - System.err.print("loader['" + name + "'] = ["); - for (int i = 0; i < arr.length; i++) { - if (i > 0) { - System.err.print(", "); - } - System.err.print(arr[i]); - } - System.err.println("]"); - */ return arr; } diff -r 4a653c70ca20 -r b5dd05670bef vm/src/test/java/org/apidesign/vm4brwsr/VMinVMTest.java --- a/vm/src/test/java/org/apidesign/vm4brwsr/VMinVMTest.java Sun Dec 16 20:17:06 2012 +0100 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/VMinVMTest.java Sun Dec 16 20:48:21 2012 +0100 @@ -20,7 +20,6 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; -import java.io.InputStream; import static org.testng.Assert.*; import javax.script.Invocable; import org.testng.annotations.BeforeClass; @@ -36,13 +35,13 @@ private static Invocable code; @Test public void compareGeneratedCodeForArrayClass() throws Exception { - compareCode("/org/apidesign/vm4brwsr/Array.class"); + compareCode("org/apidesign/vm4brwsr/Array.class"); } @Test public void compareGeneratedCodeForClassesClass() throws Exception { - compareCode("/org/apidesign/vm4brwsr/Classes.class"); + compareCode("org/apidesign/vm4brwsr/Classes.class"); } - + @BeforeClass public void compileTheCode() throws Exception { StringBuilder sb = new StringBuilder(); @@ -52,20 +51,8 @@ codeSeq = sb; } - private static byte[] readClass(String res) throws IOException { - InputStream is1 = VMinVMTest.class.getResourceAsStream(res); - assertNotNull(is1, "Stream found"); - byte[] arr = new byte[is1.available()]; - int len = is1.read(arr); - is1.close(); - if (len != arr.length) { - throw new IOException("Wrong len " + len + " for arr: " + arr.length); - } - return arr; - } - private void compareCode(final String nm) throws Exception, IOException { - byte[] arr = readClass(nm); + byte[] arr = BytesLoader.readClass(nm); String ret1 = VMinVM.toJavaScript(arr); Object ret;