Store just defined member in variable m and use it to assign access, cls and export the member
1.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Thu Sep 25 19:54:16 2014 +0200
1.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Thu Sep 25 23:48:41 2014 +0200
1.3 @@ -189,6 +189,7 @@
1.4 final String className = className(jc);
1.5 append("\n\n").append(assignClass(className));
1.6 append("function ").append(className).append("() {");
1.7 + append("\n var m;");
1.8 append("\n var CLS = ").append(className).append(';');
1.9 append("\n if (!CLS.$class) {");
1.10 if (proto == null) {
1.11 @@ -214,12 +215,12 @@
1.12 }
1.13 }
1.14 append("\n CLS.fld_").append(v.getName()).append(initField(v));
1.15 - append("\n c._").append(v.getName()).append(" = function (v) {")
1.16 + append("\n m = c._").append(v.getName()).append(" = function (v) {")
1.17 .append(" if (arguments.length == 1) CLS.fld_").append(v.getName())
1.18 .append(" = v; return CLS.fld_").
1.19 append(v.getName()).append("; };");
1.20 } else {
1.21 - append("\n c._").append(v.getName()).append(" = function (v) {")
1.22 + append("\n m = c._").append(v.getName()).append(" = function (v) {")
1.23 .append(" if (arguments.length == 1) this.fld_").
1.24 append(className).append('_').append(v.getName())
1.25 .append(" = v; return this.fld_").
1.26 @@ -250,12 +251,12 @@
1.27 declaredMethod(m, destObject, mn);
1.28 byte[] runAnno = m.findAnnotationData(false);
1.29 if (runAnno != null) {
1.30 - append("\n ").append(destObject).append(".").append(mn).append(".anno = {");
1.31 + append("\n m.anno = {");
1.32 generateAnno(jc, runAnno);
1.33 append("\n };");
1.34 }
1.35 - append("\n ").append(destObject).append(".").append(mn).append(".access = " + m.getAccess()).append(";");
1.36 - append("\n ").append(destObject).append(".").append(mn).append(".cls = CLS;");
1.37 + append("\n m.access = " + m.getAccess()).append(";");
1.38 + append("\n m.cls = CLS;");
1.39 }
1.40 append("\n c.constructor = CLS;");
1.41 append("\n function ").append(className).append("fillInstOf(x) {");
1.42 @@ -384,9 +385,9 @@
1.43
1.44 if (defineProp) {
1.45 append("Object.defineProperty(").append(destObject).
1.46 - append(", '").append(name).append("', { configurable: true, writable: true, value: function(");
1.47 + append(", '").append(name).append("', { configurable: true, writable: true, value: m = function(");
1.48 } else {
1.49 - append(destObject).append(".").append(name).append(" = function(");
1.50 + append("m = ").append(destObject).append(".").append(name).append(" = function(");
1.51 }
1.52 lmapper.outputArguments(this, m.isStatic());
1.53 append(") {").append("\n");
1.54 @@ -1837,7 +1838,7 @@
1.55 }
1.56 StringBuilder cnt = new StringBuilder();
1.57 final String mn = findMethodName(m, cnt);
1.58 - append(destObject).append(".").append(mn);
1.59 + append("m = ").append(destObject).append(".").append(mn);
1.60 append(" = function(");
1.61 String space = "";
1.62 int index = 0;
2.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java Thu Sep 25 19:54:16 2014 +0200
2.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java Thu Sep 25 23:48:41 2014 +0200
2.3 @@ -192,10 +192,8 @@
2.4 private void exportMember(String destObject, String memberName)
2.5 throws IOException {
2.6 append("\n").append(destObject).append("['")
2.7 - .append(memberName)
2.8 - .append("'] = ")
2.9 - .append(destObject).append(".").append(memberName)
2.10 - .append(";\n");
2.11 + .append(memberName)
2.12 + .append("'] = m;\n");
2.13 }
2.14
2.15 private void generateBody(StringArray names) throws IOException {
3.1 --- a/rt/vm/src/test/java/org/apidesign/vm4brwsr/SizeOfAMethodTest.java Thu Sep 25 19:54:16 2014 +0200
3.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/SizeOfAMethodTest.java Thu Sep 25 23:48:41 2014 +0200
3.3 @@ -40,7 +40,7 @@
3.4 @Test public void sumXYShouldBeSmall() {
3.5 String s = code;
3.6 int beg = s.indexOf("c.sum__III");
3.7 - int end = s.indexOf("c.sum__III.access");
3.8 + int end = s.indexOf(".access", beg);
3.9
3.10 assertTrue(beg > 0, "Found sum method in " + code);
3.11 assertTrue(beg < end, "Found end of sum method in " + code);
3.12 @@ -54,7 +54,7 @@
3.13 @Test public void betterConstructor() {
3.14 String s = code;
3.15 int beg = s.indexOf("c.initInflater__IIZ");
3.16 - int end = s.indexOf("c.initInflater__IIZ.access");
3.17 + int end = s.indexOf(".access", beg);
3.18
3.19 assertTrue(beg > 0, "Found initInflater method in " + code);
3.20 assertTrue(beg < end, "Found end of initInflater method in " + code);
3.21 @@ -67,7 +67,7 @@
3.22 @Test public void deepConstructor() {
3.23 String s = code;
3.24 int beg = s.indexOf("c.intHolder__I");
3.25 - int end = s.indexOf("c.intHolder__I.access");
3.26 + int end = s.indexOf(".access", beg);
3.27
3.28 assertTrue(beg > 0, "Found intHolder method in " + code);
3.29 assertTrue(beg < end, "Found end of intHolder method in " + code);
3.30 @@ -80,7 +80,7 @@
3.31 @Test public void emptyConstructorRequiresNoStack() {
3.32 String s = code;
3.33 int beg = s.indexOf("CLS.cons__V");
3.34 - int end = s.indexOf("CLS.cons__V.access");
3.35 + int end = s.indexOf(".access", beg);
3.36
3.37 assertTrue(beg > 0, "Found constructor in " + code);
3.38 assertTrue(beg < end, "Found end of constructor in " + code);