1.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/GenJS.java Tue Dec 04 12:06:27 2012 +0100
1.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/GenJS.java Thu Dec 06 16:11:48 2012 +0100
1.3 @@ -26,7 +26,7 @@
1.4 *
1.5 * @author Jaroslav Tulach <jtulach@netbeans.org>
1.6 */
1.7 -final class GenJS extends ByteCodeToJavaScript {
1.8 +class GenJS extends ByteCodeToJavaScript {
1.9 public GenJS(Appendable out) {
1.10 super(out);
1.11 }
1.12 @@ -41,22 +41,16 @@
1.13 compile(GenJS.class.getClassLoader(), out, names);
1.14 }
1.15 static void compile(ClassLoader l, Appendable out, StringArray names) throws IOException {
1.16 - out.append("Array.prototype.fillNulls = function() {\n" +
1.17 - " for(var i = 0; i < this.length; i++) {\n" +
1.18 - " this[i] = null;\n" +
1.19 - " }\n" +
1.20 - " return this;\n" +
1.21 - "};");
1.22 -
1.23 -
1.24 + new GenJS(out).doCompile(l, names);
1.25 + }
1.26 + protected void doCompile(ClassLoader l, StringArray names) throws IOException {
1.27 StringArray processed = new StringArray();
1.28 StringArray initCode = new StringArray();
1.29 for (String baseClass : names.toArray()) {
1.30 - GenJS js = new GenJS(out);
1.31 - js.references.add(baseClass);
1.32 + references.add(baseClass);
1.33 for (;;) {
1.34 String name = null;
1.35 - for (String n : js.references.toArray()) {
1.36 + for (String n : references.toArray()) {
1.37 if (processed.contains(n)) {
1.38 continue;
1.39 }
1.40 @@ -70,7 +64,7 @@
1.41 throw new IOException("Can't find class " + name);
1.42 }
1.43 try {
1.44 - String ic = js.compile(is);
1.45 + String ic = compile(is);
1.46 processed.add(name);
1.47 initCode.add(ic == null ? "" : ic);
1.48 } catch (RuntimeException ex) {
1.49 @@ -93,7 +87,7 @@
1.50 }
1.51 }
1.52
1.53 - for (String resource : js.scripts.toArray()) {
1.54 + for (String resource : scripts.toArray()) {
1.55 while (resource.startsWith("/")) {
1.56 resource = resource.substring(1);
1.57 }
1.58 @@ -103,9 +97,9 @@
1.59 }
1.60 readResource(emul, out);
1.61 }
1.62 - js.scripts = new StringArray();
1.63 + scripts = new StringArray();
1.64
1.65 - StringArray toInit = StringArray.asList(js.references.toArray());
1.66 + StringArray toInit = StringArray.asList(references.toArray());
1.67 toInit.reverse();
1.68
1.69 for (String ic : toInit.toArray()) {