1.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/ClosureWrapper.java Mon May 06 11:57:29 2013 +0200
1.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/ClosureWrapper.java Wed May 08 14:54:32 2013 +0200
1.3 @@ -37,19 +37,23 @@
1.4
1.5 private final Bck2Brwsr.Resources res;
1.6 private final StringArray classes;
1.7 + private final boolean extension;
1.8
1.9 private String compiledCode;
1.10 private String externsCode;
1.11
1.12 private ClosureWrapper(Appendable out,
1.13 String compilationLevel,
1.14 - Bck2Brwsr.Resources res, StringArray classes) {
1.15 + Bck2Brwsr.Resources res,
1.16 + StringArray classes,
1.17 + boolean extension) {
1.18 super(
1.19 generateArguments(compilationLevel),
1.20 new PrintStream(new APS(out)), System.err
1.21 );
1.22 this.res = res;
1.23 this.classes = classes;
1.24 + this.extension = extension;
1.25 }
1.26
1.27 @Override
1.28 @@ -92,7 +96,7 @@
1.29 if (compiledCode == null) {
1.30 StringBuilder sb = new StringBuilder();
1.31 try {
1.32 - VM.compileStandalone(res, sb, classes);
1.33 + VM.compile(sb, res, classes, extension);
1.34 compiledCode = sb.toString();
1.35 } catch (IOException ex) {
1.36 compiledCode = ex.getMessage();
1.37 @@ -134,8 +138,17 @@
1.38 return finalArgs;
1.39 }
1.40
1.41 - static int produceTo(Appendable w, ObfuscationLevel obfuscationLevel, Bck2Brwsr.Resources resources, StringArray arr) throws IOException {
1.42 - ClosureWrapper cw = create(w, obfuscationLevel, resources, arr);
1.43 + static int produceTo(Appendable output,
1.44 + ObfuscationLevel obfuscationLevel,
1.45 + Bck2Brwsr.Resources resources,
1.46 + StringArray arr,
1.47 + boolean extension) throws IOException {
1.48 + final ClosureWrapper cw =
1.49 + new ClosureWrapper(output,
1.50 + (obfuscationLevel == ObfuscationLevel.FULL)
1.51 + ? "ADVANCED_OPTIMIZATIONS"
1.52 + : "SIMPLE_OPTIMIZATIONS",
1.53 + resources, arr, extension);
1.54 try {
1.55 return cw.doRun();
1.56 } catch (FlagUsageException ex) {
1.57 @@ -143,24 +156,6 @@
1.58 }
1.59 }
1.60
1.61 - private static ClosureWrapper create(Appendable w,
1.62 - ObfuscationLevel obfuscationLevel,
1.63 - Bck2Brwsr.Resources resources,
1.64 - StringArray arr) {
1.65 - switch (obfuscationLevel) {
1.66 - case MINIMAL:
1.67 - return new ClosureWrapper(w, "SIMPLE_OPTIMIZATIONS",
1.68 - resources, arr);
1.69 -
1.70 - case FULL:
1.71 - return new ClosureWrapper(w, "ADVANCED_OPTIMIZATIONS",
1.72 - resources, arr);
1.73 - default:
1.74 - throw new IllegalArgumentException(
1.75 - "Unsupported level: " + obfuscationLevel);
1.76 - }
1.77 - }
1.78 -
1.79 private static final String[] FIXED_EXTERNS = {
1.80 "bck2brwsr",
1.81 "$class",