rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java
changeset 1509 16f50abb439b
parent 1409 3d1612be40bc
child 1513 ba912ef24b27
     1.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java	Thu Nov 07 09:41:45 2013 +0100
     1.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java	Tue Apr 29 16:22:23 2014 +0200
     1.3 @@ -58,7 +58,7 @@
     1.4      }
     1.5  
     1.6      protected void doCompile(Bck2Brwsr.Resources l, StringArray names) throws IOException {
     1.7 -        out.append("(function VM(global) {var fillInVMSkeleton = function(vm) {");
     1.8 +        append("(function VM(global) {var fillInVMSkeleton = function(vm) {");
     1.9          StringArray processed = new StringArray();
    1.10          StringArray initCode = new StringArray();
    1.11          StringArray skipClass = new StringArray();
    1.12 @@ -80,7 +80,7 @@
    1.13                  }
    1.14                  InputStream is = loadClass(l, name);
    1.15                  if (is == null) {
    1.16 -                    lazyReference(out, name);
    1.17 +                    lazyReference(this, name);
    1.18                      skipClass.add(name);
    1.19                      continue;
    1.20                  }
    1.21 @@ -89,22 +89,7 @@
    1.22                      processed.add(name);
    1.23                      initCode.add(ic == null ? "" : ic);
    1.24                  } catch (RuntimeException ex) {
    1.25 -                    if (out instanceof CharSequence) {
    1.26 -                        CharSequence seq = (CharSequence)out;
    1.27 -                        int lastBlock = seq.length();
    1.28 -                        while (lastBlock-- > 0) {
    1.29 -                            if (seq.charAt(lastBlock) == '{') {
    1.30 -                                break;
    1.31 -                            }
    1.32 -                        }
    1.33 -                        throw new IOException("Error while compiling " + name + "\n" 
    1.34 -                            + seq.subSequence(lastBlock + 1, seq.length()), ex
    1.35 -                        );
    1.36 -                    } else {
    1.37 -                        throw new IOException("Error while compiling " + name + "\n" 
    1.38 -                            + out, ex
    1.39 -                        );
    1.40 -                    }
    1.41 +                    throw new IOException("Error while compiling " + name + "\n", ex);
    1.42                  }
    1.43              }
    1.44  
    1.45 @@ -116,7 +101,7 @@
    1.46                  if (emul == null) {
    1.47                      throw new IOException("Can't find " + resource);
    1.48                  }
    1.49 -                readResource(emul, out);
    1.50 +                readResource(emul, this);
    1.51              }
    1.52              scripts = new StringArray();
    1.53              
    1.54 @@ -128,13 +113,13 @@
    1.55                  if (indx >= 0) {
    1.56                      final String theCode = initCode.toArray()[indx];
    1.57                      if (!theCode.isEmpty()) {
    1.58 -                        out.append(theCode).append("\n");
    1.59 +                        append(theCode).append("\n");
    1.60                      }
    1.61                      initCode.toArray()[indx] = "";
    1.62                  }
    1.63              }
    1.64          }
    1.65 -        out.append(
    1.66 +        append(
    1.67                "  return vm;\n"
    1.68              + "  };\n"
    1.69              + "  function mangleClass(name) {\n"
    1.70 @@ -172,7 +157,7 @@
    1.71              + "      loadBytes___3BLjava_lang_Object_2Ljava_lang_String_2_3Ljava_lang_Object_2I(loader, null, args, 0);\n"
    1.72              + "    return loader;\n"
    1.73              + "  };\n");
    1.74 -        out.append("}(this));");
    1.75 +        append("}(this));");
    1.76      }
    1.77      private static void readResource(InputStream emul, Appendable out) throws IOException {
    1.78          try {