1.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Sat Dec 01 08:52:30 2012 +0100
1.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Sat Dec 01 12:14:37 2012 +0100
1.3 @@ -107,17 +107,18 @@
1.4 generateInstanceMethod("\n p.", m);
1.5 }
1.6 }
1.7 + out.append("\n p.constructor = CLS;");
1.8 out.append("\n p.$instOf_").append(className).append(" = true;");
1.9 for (String superInterface : jc.getSuperInterfaces()) {
1.10 out.append("\n p.$instOf_").append(superInterface.replace('/', '_')).append(" = true;");
1.11 }
1.12 out.append("\n CLS.$class = java_lang_Class(true);");
1.13 out.append("\n CLS.$class.jvmName = '").append(jc.getClassName()).append("';");
1.14 - out.append("\n if (arguments.length === 0) {");
1.15 - out.append("\n return new CLS();");
1.16 - out.append("\n }");
1.17 out.append("\n }");
1.18 out.append("\n if (arguments.length === 0) {");
1.19 + out.append("\n if (!(this instanceof CLS)) {");
1.20 + out.append("\n return new CLS();");
1.21 + out.append("\n }");
1.22 for (FieldData v : jc.getFields()) {
1.23 if (!v.isStatic()) {
1.24 out.append("\n this.fld_").
1.25 @@ -126,7 +127,7 @@
1.26 }
1.27 out.append("\n return this;");
1.28 out.append("\n }");
1.29 - out.append("\n return new CLS;");
1.30 + out.append("\n return arguments[0] ? new CLS() : CLS.prototype;");
1.31 out.append("\n}");
1.32 StringBuilder sb = new StringBuilder();
1.33 for (String init : toInitilize.toArray()) {
1.34 @@ -142,7 +143,7 @@
1.35 final String mn = findMethodName(m, argsCnt);
1.36 out.append(prefix).append(mn).append(" = function");
1.37 if (mn.equals("classV")) {
1.38 - toInitilize.add(className(jc) + "(true)." + mn);
1.39 + toInitilize.add(className(jc) + "(false)." + mn);
1.40 }
1.41 out.append('(');
1.42 String space = "";
1.43 @@ -585,9 +586,9 @@
1.44 case opc_new: {
1.45 int indx = readIntArg(byteCodes, i);
1.46 String ci = jc.getClassName(indx);
1.47 - out.append("s.push(");
1.48 - out.append("new ").append(ci.replace('/','_'));
1.49 - out.append(");");
1.50 + out.append("s.push(new ");
1.51 + out.append(ci.replace('/','_'));
1.52 + out.append("());");
1.53 addReference(ci);
1.54 i += 2;
1.55 break;
1.56 @@ -888,7 +889,7 @@
1.57 }
1.58 final String in = mi[0];
1.59 out.append(in.replace('/', '_'));
1.60 - out.append("(true).");
1.61 + out.append("(false).");
1.62 out.append(mn);
1.63 out.append('(');
1.64 String sep = "";