In order to support fields of the same name in subclasses we are now prefixing them with name of the class that defines them. To provide convenient way to access them from generated bytecode and also directly from JavaScript, there is a getter/setter function for each field. It starts with _ followed by the field name. If called with a parameter, it sets the field, with a parameter it just returns it.
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Sat, 26 Jan 2013 08:47:05 +0100
changeset 5925e13b1ac2886
parent 591 efe024e8afd6
child 593 b42911b78a16
child 595 784aaf9ee179
In order to support fields of the same name in subclasses we are now prefixing them with name of the class that defines them. To provide convenient way to access them from generated bytecode and also directly from JavaScript, there is a getter/setter function for each field. It starts with _ followed by the field name. If called with a parameter, it sets the field, with a parameter it just returns it.
emul/mini/src/main/java/java/lang/String.java
emul/mini/src/main/java/java/lang/reflect/Method.java
javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Canvas.java
javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java
javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/GraphicsContext.java
vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java
vm/src/main/java/org/apidesign/vm4brwsr/VMLazy.java
vmtest/src/test/java/org/apidesign/bck2brwsr/tck/InheritanceA.java
vmtest/src/test/java/org/apidesign/bck2brwsr/tck/InheritanceB.java
vmtest/src/test/java/org/apidesign/bck2brwsr/tck/InheritanceTest.java
     1.1 --- a/emul/mini/src/main/java/java/lang/String.java	Fri Jan 25 16:47:04 2013 +0100
     1.2 +++ b/emul/mini/src/main/java/java/lang/String.java	Sat Jan 26 08:47:05 2013 +0100
     1.3 @@ -115,7 +115,7 @@
     1.4      /** use serialVersionUID from JDK 1.0.2 for interoperability */
     1.5      private static final long serialVersionUID = -6849794470754667710L;
     1.6      
     1.7 -    @JavaScriptOnly(name="toString", value="function() { return this.fld_r; }")
     1.8 +    @JavaScriptOnly(name="toString", value="String.prototype._r")
     1.9      private static void jsToString() {
    1.10      }
    1.11      
    1.12 @@ -174,7 +174,7 @@
    1.13          "for (var i = 0; i < charArr.length; i++) {\n"
    1.14        + "  if (typeof charArr[i] === 'number') charArr[i] = String.fromCharCode(charArr[i]);\n"
    1.15        + "}\n"
    1.16 -      + "this.fld_r = charArr.join('');\n"
    1.17 +      + "this._r(charArr.join(''));\n"
    1.18      )
    1.19      public String(char value[]) {
    1.20      }
    1.21 @@ -205,7 +205,7 @@
    1.22          "for (var i = off; i < up; i++) {\n" +
    1.23          "  if (typeof charArr[i] === 'number') charArr[i] = String.fromCharCode(charArr[i]);\n" +
    1.24          "}\n" +
    1.25 -        "this.fld_r = charArr.slice(off, up).join(\"\");\n"
    1.26 +        "this._r(charArr.slice(off, up).join(\"\"));\n"
    1.27      )
    1.28      public String(char value[], int offset, int count) {
    1.29      }
     2.1 --- a/emul/mini/src/main/java/java/lang/reflect/Method.java	Fri Jan 25 16:47:04 2013 +0100
     2.2 +++ b/emul/mini/src/main/java/java/lang/reflect/Method.java	Sat Jan 26 08:47:05 2013 +0100
     2.3 @@ -533,7 +533,7 @@
     2.4          + "} else {\n"
     2.5          + "  p = args;\n"
     2.6          + "}\n"
     2.7 -        + "return method.fld_data.apply(self, p);\n"
     2.8 +        + "return method._data().apply(self, p);\n"
     2.9      )
    2.10      private static native Object invoke0(boolean isStatic, Method m, Object self, Object[] args);
    2.11  
    2.12 @@ -648,8 +648,9 @@
    2.13  
    2.14      @JavaScriptBody(args = { "ac" }, 
    2.15          body = 
    2.16 -          "if (this.fld_data.anno) {"
    2.17 -        + "  return this.fld_data.anno['L' + ac.jvmName + ';'];"
    2.18 +          "var a = this._data().anno;"
    2.19 +        + "if (a) {"
    2.20 +        + "  return a['L' + ac.jvmName + ';'];"
    2.21          + "} else return null;"
    2.22      )
    2.23      private Object getAnnotationData(Class<?> annotationClass) {
     3.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Canvas.java	Fri Jan 25 16:47:04 2013 +0100
     3.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Canvas.java	Sat Jan 26 08:47:05 2013 +0100
     3.3 @@ -47,7 +47,7 @@
     3.4  
     3.5      @JavaScriptBody(
     3.6              args = {"el"},
     3.7 -            body = "var e = window.document.getElementById(el.fld_id);\n"
     3.8 +            body = "var e = window.document.getElementById(el._id());\n"
     3.9              + "return e.getContext('2d');\n")
    3.10      private native static Object getContextImpl(Canvas el);
    3.11  
     4.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java	Fri Jan 25 16:47:04 2013 +0100
     4.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java	Sat Jan 26 08:47:05 2013 +0100
     4.3 @@ -41,21 +41,21 @@
     4.4      
     4.5      @JavaScriptBody(
     4.6          args={"el", "property", "value"},
     4.7 -        body="var e = window.document.getElementById(el.fld_id);\n"
     4.8 +        body="var e = window.document.getElementById(el._id());\n"
     4.9             + "e[property] = value;\n"
    4.10      )
    4.11      static native void setAttribute(Element el, String property, Object value);
    4.12  
    4.13      @JavaScriptBody(
    4.14          args={"el", "property"},
    4.15 -        body="var e = window.document.getElementById(el.fld_id);\n"
    4.16 +        body="var e = window.document.getElementById(el._id());\n"
    4.17             + "return e[property];\n"
    4.18      )
    4.19      static native Object getAttribute(Element el, String property);
    4.20      
    4.21      @JavaScriptBody(
    4.22          args={"el"},
    4.23 -        body="return window.document.getElementById(el.fld_id);"
    4.24 +        body="return window.document.getElementById(el._id());"
    4.25      )
    4.26      static native Object getElementById(Element el);
    4.27      
    4.28 @@ -65,8 +65,8 @@
    4.29       */
    4.30      @JavaScriptBody(
    4.31          args={ "ev", "r" },
    4.32 -        body="var e = window.document.getElementById(this.fld_id);\n"
    4.33 -           + "e[ev.fld_id] = function() { r.run__V(); };\n"
    4.34 +        body="var e = window.document.getElementById(this._id());\n"
    4.35 +           + "e[ev._id()] = function() { r.run__V(); };\n"
    4.36      )
    4.37      final void on(OnEvent ev, Runnable r) {
    4.38      }
     5.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/GraphicsContext.java	Fri Jan 25 16:47:04 2013 +0100
     5.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/GraphicsContext.java	Sat Jan 26 08:47:05 2013 +0100
     5.3 @@ -32,7 +32,7 @@
     5.4      }
     5.5  
     5.6      @JavaScriptBody(args = {"centerx", "centery", "radius", "startangle", "endangle", "ccw"},
     5.7 -            body = "this.fld_context.arc(centerx,centery, radius, startangle, endangle,ccw);")
     5.8 +            body = "this._context().arc(centerx,centery, radius, startangle, endangle,ccw);")
     5.9      public native void arc(double centerX,
    5.10              double centerY,
    5.11              double startAngle,
    5.12 @@ -41,7 +41,7 @@
    5.13              boolean ccw);
    5.14  
    5.15      @JavaScriptBody(args = {"x1", "y1", "x2", "y2", "r"},
    5.16 -            body = "this.fld_context.arcTo(x1,y1,x2,y2,r);")
    5.17 +            body = "this._context().arcTo(x1,y1,x2,y2,r);")
    5.18      public native void arcTo(double x1,
    5.19              double y1,
    5.20              double x2,
    5.21 @@ -49,68 +49,68 @@
    5.22              double r);
    5.23  
    5.24      @JavaScriptBody(args = {"x", "y"},
    5.25 -            body = "return this.fld_context.isPointInPath(x,y);")
    5.26 +            body = "return this._context().isPointInPath(x,y);")
    5.27      public native boolean isPointInPath(double x, double y);
    5.28  
    5.29 -    @JavaScriptBody(args = {}, body = "this.fld_context.fill();")
    5.30 +    @JavaScriptBody(args = {}, body = "this._context().fill();")
    5.31      public native void fill();
    5.32  
    5.33 -    @JavaScriptBody(args = {}, body = "this.fld_context.stroke();")
    5.34 +    @JavaScriptBody(args = {}, body = "this._context().stroke();")
    5.35      public native void stroke();
    5.36  
    5.37 -    @JavaScriptBody(args = {}, body = "this.fld_context.beginPath();")
    5.38 +    @JavaScriptBody(args = {}, body = "this._context().beginPath();")
    5.39      public native void beginPath();
    5.40  
    5.41 -    @JavaScriptBody(args = {}, body = "this.fld_context.closePath();")
    5.42 +    @JavaScriptBody(args = {}, body = "this._context().closePath();")
    5.43      public native void closePath();
    5.44  
    5.45 -    @JavaScriptBody(args = {}, body = "this.fld_context.clip();")
    5.46 +    @JavaScriptBody(args = {}, body = "this._context().clip();")
    5.47      public native void clip();
    5.48  
    5.49 -    @JavaScriptBody(args = {"x", "y"}, body = "this.fld_context.moveTo(x,y);")
    5.50 +    @JavaScriptBody(args = {"x", "y"}, body = "this._context().moveTo(x,y);")
    5.51      public native void moveTo(double x, double y);
    5.52  
    5.53 -    @JavaScriptBody(args = {"x", "y"}, body = "this.fld_context.lineTo(x,y);")
    5.54 +    @JavaScriptBody(args = {"x", "y"}, body = "this._context().lineTo(x,y);")
    5.55      public native void lineTo(double x, double y);
    5.56  
    5.57 -    @JavaScriptBody(args = {"cpx", "cpy", "x", "y"}, body = "this.fld_context.quadraticCurveTo(cpx,cpy,x,y);")
    5.58 +    @JavaScriptBody(args = {"cpx", "cpy", "x", "y"}, body = "this._context().quadraticCurveTo(cpx,cpy,x,y);")
    5.59      public native void quadraticCurveTo(double cpx, double cpy, double x, double y);
    5.60  
    5.61      @JavaScriptBody(args = {"cp1x", "cp1y", "cp2x", "cp2y", "x", "y"},
    5.62 -            body = "this.fld_context.bezierCurveTo(cp1x,cp1y,cp2x,cp2y,x,y);")
    5.63 +            body = "this._context().bezierCurveTo(cp1x,cp1y,cp2x,cp2y,x,y);")
    5.64      public native void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y);
    5.65  
    5.66 -    @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this.fld_context.fillRect(x,y,width,height);")
    5.67 +    @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().fillRect(x,y,width,height);")
    5.68      public native void fillRect(double x, double y, double width, double height);
    5.69  
    5.70 -    @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this.fld_context.strokeRect(x,y,width,height);")
    5.71 +    @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().strokeRect(x,y,width,height);")
    5.72      public native void strokeRect(double x, double y, double width, double height);
    5.73  
    5.74 -    @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this.fld_context.clearRect(x,y,width,height);")
    5.75 +    @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().clearRect(x,y,width,height);")
    5.76      public native void clearRect(double x, double y, double width, double height);
    5.77  
    5.78 -    @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this.fld_context.rectect(x,y,width,height);")
    5.79 +    @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().rectect(x,y,width,height);")
    5.80      public native void rect(double x, double y, double width, double height);
    5.81  
    5.82 -    @JavaScriptBody(args = {}, body = "this.fld_context.save();")
    5.83 +    @JavaScriptBody(args = {}, body = "this._context().save();")
    5.84      public native void save();
    5.85  
    5.86 -    @JavaScriptBody(args = {}, body = "this.fld_context.restore();")
    5.87 +    @JavaScriptBody(args = {}, body = "this._context().restore();")
    5.88      public native void restore();
    5.89  
    5.90 -    @JavaScriptBody(args = {"angle"}, body = "this.fld_context.rotate(angle);")
    5.91 +    @JavaScriptBody(args = {"angle"}, body = "this._context().rotate(angle);")
    5.92      public native void rotate(double angle);
    5.93  
    5.94 -    @JavaScriptBody(args = {"a", "b", "c", "d", "e", "f"}, body = "this.fld_context.transform(a,b,c,d,e,f);")
    5.95 +    @JavaScriptBody(args = {"a", "b", "c", "d", "e", "f"}, body = "this._context().transform(a,b,c,d,e,f);")
    5.96      public native void transform(double a, double b, double c, double d, double e, double f);
    5.97  
    5.98 -    @JavaScriptBody(args = {"a", "b", "c", "d", "e", "f"}, body = "this.fld_context.setTransform(a,b,c,d,e,f);")
    5.99 +    @JavaScriptBody(args = {"a", "b", "c", "d", "e", "f"}, body = "this._context().setTransform(a,b,c,d,e,f);")
   5.100      public native void setTransform(double a, double b, double c, double d, double e, double f);
   5.101  
   5.102 -    @JavaScriptBody(args = {"x", "y"}, body = "this.fld_context.translate(x,y);")
   5.103 +    @JavaScriptBody(args = {"x", "y"}, body = "this._context().translate(x,y);")
   5.104      public native void translate(double x, double y);
   5.105  
   5.106 -    @JavaScriptBody(args = {"x", "y"}, body = "this.fld_context.scale(x,y);")
   5.107 +    @JavaScriptBody(args = {"x", "y"}, body = "this._context().scale(x,y);")
   5.108      public native void scale(double x, double y);
   5.109  
   5.110      public void drawImage(Image image, double x, double y) {
   5.111 @@ -134,10 +134,10 @@
   5.112      @JavaScriptBody(args = {"ctx", "img", "x", "y"}, body = "ctx.drawImage(img,x,y);")
   5.113      private native static void drawImageImpl(Object ctx, Object img, double x, double y);
   5.114  
   5.115 -    @JavaScriptBody(args = {"style"}, body = "this.fld_context.fillStyle=style;")
   5.116 +    @JavaScriptBody(args = {"style"}, body = "this._context().fillStyle=style;")
   5.117      public native void setFillStyle(String style);
   5.118  
   5.119 -    @JavaScriptBody(args = {}, body = "return this.fld_context.fillStyle;")
   5.120 +    @JavaScriptBody(args = {}, body = "return this._context().fillStyle;")
   5.121      public native String getFillStyle();
   5.122  
   5.123      public void setFillStyle(LinearGradient style) {
   5.124 @@ -155,7 +155,7 @@
   5.125      @JavaScriptBody(args = {"context","obj"}, body = "context.fillStyle=obj;")
   5.126      private native void setFillStyleImpl(Object context, Object obj);
   5.127  
   5.128 -    @JavaScriptBody(args = {"style"}, body = "this.fld_context.strokeStyle=style;")
   5.129 +    @JavaScriptBody(args = {"style"}, body = "this._context().strokeStyle=style;")
   5.130      public native void setStrokeStyle(String style);
   5.131  
   5.132      public void setStrokeStyle(LinearGradient style) {
   5.133 @@ -166,7 +166,7 @@
   5.134          setStrokeStyleImpl(context, style.object());
   5.135      }
   5.136  
   5.137 -    @JavaScriptBody(args = {"style"}, body = "this.fld_context.fillStyle=style;")
   5.138 +    @JavaScriptBody(args = {"style"}, body = "this._context().fillStyle=style;")
   5.139      public void setStrokeStyle(Pattern style) {
   5.140          setStrokeStyleImpl(context, style.object());
   5.141      }
   5.142 @@ -174,79 +174,79 @@
   5.143      @JavaScriptBody(args = {"context","obj"}, body = "context.strokeStyle=obj;")
   5.144      private native void setStrokeStyleImpl(Object context, Object obj);
   5.145  
   5.146 -    @JavaScriptBody(args = {"color"}, body = "this.fld_context.shadowColor=color;")
   5.147 +    @JavaScriptBody(args = {"color"}, body = "this._context().shadowColor=color;")
   5.148      public native void setShadowColor(String color);
   5.149  
   5.150 -    @JavaScriptBody(args = {"blur"}, body = "this.fld_context.shadowBlur=blur;")
   5.151 +    @JavaScriptBody(args = {"blur"}, body = "this._context().shadowBlur=blur;")
   5.152      public native void setShadowBlur(double blur);
   5.153      
   5.154 -    @JavaScriptBody(args = {"x"}, body = "this.fld_context.shadowOffsetX=x;")
   5.155 +    @JavaScriptBody(args = {"x"}, body = "this._context().shadowOffsetX=x;")
   5.156      public native void setShadowOffsetX(double x);
   5.157  
   5.158 -    @JavaScriptBody(args = {"y"}, body = "this.fld_context.shadowOffsetY=y;")
   5.159 +    @JavaScriptBody(args = {"y"}, body = "this._context().shadowOffsetY=y;")
   5.160      public native void setShadowOffsetY(double y);
   5.161  
   5.162 -    @JavaScriptBody(args = {}, body = "return this.fld_context.strokeStyle;")
   5.163 +    @JavaScriptBody(args = {}, body = "return this._context().strokeStyle;")
   5.164      public native String getStrokeStyle();
   5.165  
   5.166 -    @JavaScriptBody(args = {}, body = "return this.fld_context.shadowColor;")
   5.167 +    @JavaScriptBody(args = {}, body = "return this._context().shadowColor;")
   5.168      public native String getShadowColor();
   5.169  
   5.170 -    @JavaScriptBody(args = {}, body = "return this.fld_context.shadowBlur;")
   5.171 +    @JavaScriptBody(args = {}, body = "return this._context().shadowBlur;")
   5.172      public native double getShadowBlur();
   5.173  
   5.174 -    @JavaScriptBody(args = {}, body = "return this.fld_context.shadowOffsetX;")
   5.175 +    @JavaScriptBody(args = {}, body = "return this._context().shadowOffsetX;")
   5.176      public native double getShadowOffsetX();
   5.177  
   5.178 -    @JavaScriptBody(args = {}, body = "return this.fld_context.shadowOffsetY;")
   5.179 +    @JavaScriptBody(args = {}, body = "return this._context().shadowOffsetY;")
   5.180      public native double getShadowOffsetY();
   5.181  
   5.182 -    @JavaScriptBody(args = {}, body = "return this.fld_context.lineCap;")
   5.183 +    @JavaScriptBody(args = {}, body = "return this._context().lineCap;")
   5.184      public native String getLineCap();
   5.185  
   5.186 -    @JavaScriptBody(args = {"style"}, body = "this.fld_context.lineCap=style;")
   5.187 +    @JavaScriptBody(args = {"style"}, body = "this._context().lineCap=style;")
   5.188      public native void setLineCap(String style);
   5.189  
   5.190 -    @JavaScriptBody(args = {}, body = "return this.fld_context.lineJoin;")
   5.191 +    @JavaScriptBody(args = {}, body = "return this._context().lineJoin;")
   5.192      public native String getLineJoin();
   5.193  
   5.194 -    @JavaScriptBody(args = {"style"}, body = "this.fld_context.lineJoin=style;")
   5.195 +    @JavaScriptBody(args = {"style"}, body = "this._context().lineJoin=style;")
   5.196      public native void setLineJoin(String style) ;
   5.197  
   5.198 -    @JavaScriptBody(args = {}, body = "return this.fld_context.lineWidth;")
   5.199 +    @JavaScriptBody(args = {}, body = "return this._context().lineWidth;")
   5.200      public native double getLineWidth();
   5.201  
   5.202 -    @JavaScriptBody(args = {"width"}, body = "this.fld_context.lineJoin=width;")
   5.203 +    @JavaScriptBody(args = {"width"}, body = "this._context().lineJoin=width;")
   5.204      public native void setLineWidth(double width);
   5.205  
   5.206 -    @JavaScriptBody(args = {}, body = "return this.fld_context.miterLimit;")
   5.207 +    @JavaScriptBody(args = {}, body = "return this._context().miterLimit;")
   5.208      public native double getMiterLimit();
   5.209  
   5.210 -    @JavaScriptBody(args = {"limit"}, body = "this.fld_context.miterLimit=limit;")
   5.211 +    @JavaScriptBody(args = {"limit"}, body = "this._context().miterLimit=limit;")
   5.212      public native void setMiterLimit(double limit);
   5.213  
   5.214 -    @JavaScriptBody(args = {}, body = "return this.fld_context.font;")
   5.215 +    @JavaScriptBody(args = {}, body = "return this._context().font;")
   5.216      public native String getFont();
   5.217  
   5.218 -    @JavaScriptBody(args = {"font"}, body = "this.fld_context.font=font;")
   5.219 +    @JavaScriptBody(args = {"font"}, body = "this._context().font=font;")
   5.220      public native void setFont(String font);
   5.221  
   5.222 -    @JavaScriptBody(args = {}, body = "return this.fld_context.textAlign;")
   5.223 +    @JavaScriptBody(args = {}, body = "return this._context().textAlign;")
   5.224      public native String getTextAlign();
   5.225  
   5.226 -    @JavaScriptBody(args = {"textalign"}, body = "this.fld_context.textAlign=textalign;")
   5.227 +    @JavaScriptBody(args = {"textalign"}, body = "this._context().textAlign=textalign;")
   5.228      public native void setTextAlign(String textAlign);
   5.229  
   5.230 -    @JavaScriptBody(args = {}, body = "return this.fld_context.textBaseline;")
   5.231 +    @JavaScriptBody(args = {}, body = "return this._context().textBaseline;")
   5.232      public native String getTextBaseline();
   5.233  
   5.234 -    @JavaScriptBody(args = {"textbaseline"}, body = "this.fld_context.textBaseline=textbaseline;")
   5.235 +    @JavaScriptBody(args = {"textbaseline"}, body = "this._context().textBaseline=textbaseline;")
   5.236      public native void setTextBaseline(String textbaseline);
   5.237  
   5.238 -    @JavaScriptBody(args = {"text", "x", "y"}, body = "this.fld_context.fillText(text,x,y);")
   5.239 +    @JavaScriptBody(args = {"text", "x", "y"}, body = "this._context().fillText(text,x,y);")
   5.240      public native void fillText(String text, double x, double y);
   5.241  
   5.242 -    @JavaScriptBody(args = {"text", "x", "y", "maxwidth"}, body = "this.fld_context.fillText(text,x,y,maxwidth);")
   5.243 +    @JavaScriptBody(args = {"text", "x", "y", "maxwidth"}, body = "this._context().fillText(text,x,y,maxwidth);")
   5.244      public void fillText(String text, double x, double y, double maxWidth) {
   5.245      }
   5.246  
   5.247 @@ -255,13 +255,13 @@
   5.248      }
   5.249  
   5.250      @JavaScriptBody(args = {"text"},
   5.251 -            body = "return this.fld_context.measureText(text);")
   5.252 +            body = "return this._context().measureText(text);")
   5.253      private native Object measureTextImpl(String text);
   5.254  
   5.255 -    @JavaScriptBody(args = {"text", "x", "y"}, body = "this.fld_context.strokeText(text,x,y);")
   5.256 +    @JavaScriptBody(args = {"text", "x", "y"}, body = "this._context().strokeText(text,x,y);")
   5.257      public native void strokeText(String text, double x, double y);
   5.258  
   5.259 -    @JavaScriptBody(args = {"text", "x", "y", "maxWidth"}, body = "this.fld_context.strokeText(text,x,y,maxWidth);")
   5.260 +    @JavaScriptBody(args = {"text", "x", "y", "maxWidth"}, body = "this._context().strokeText(text,x,y,maxWidth);")
   5.261      public native void strokeText(String text, double x, double y, double maxWidth) ;
   5.262  
   5.263      public ImageData createImageData(double x, double y) {
   5.264 @@ -269,7 +269,7 @@
   5.265      }
   5.266  
   5.267      @JavaScriptBody(args = {"x", "y"},
   5.268 -            body = "return this.fld_context.createImageData(x,y);")
   5.269 +            body = "return this._context().createImageData(x,y);")
   5.270      private native Object createImageDataImpl(double x, double y);
   5.271  
   5.272      public ImageData createImageData(ImageData imageData) {
   5.273 @@ -281,7 +281,7 @@
   5.274      }
   5.275  
   5.276      @JavaScriptBody(args = {"x", "y", "width", "height"},
   5.277 -            body = "return this.fld_context.getImageData(x,y,width,height);")
   5.278 +            body = "return this._context().getImageData(x,y,width,height);")
   5.279      private native Object getImageDataImpl(double x, double y, double width, double height);
   5.280  
   5.281      public void putImageData(ImageData imageData, double x, double y) {
   5.282 @@ -289,7 +289,7 @@
   5.283      }
   5.284  
   5.285      @JavaScriptBody(args = {"imageData", "x", "y"},
   5.286 -            body = "this.fld_context.putImageData(imageData,x,y);")
   5.287 +            body = "this._context().putImageData(imageData,x,y);")
   5.288      private native void putImageDataImpl(Object imageData, double x, double y);
   5.289  
   5.290      public void putImageData(ImageData imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight) {
   5.291 @@ -297,19 +297,19 @@
   5.292      }
   5.293  
   5.294      @JavaScriptBody(args = {"imageData", "x", "y", "dirtyx", "dirtyy", "dirtywidth", "dirtyheight"},
   5.295 -            body = "this.fld_context.putImageData(imageData,x,y, dirtyx, dirtyy, dirtywidth,dirtyheight);")
   5.296 +            body = "this._context().putImageData(imageData,x,y, dirtyx, dirtyy, dirtywidth,dirtyheight);")
   5.297      private native void putImageDataImpl(Object imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight);
   5.298  
   5.299 -    @JavaScriptBody(args = {"alpha"}, body = "this.fld_context.globalAlpha=alpha;")
   5.300 +    @JavaScriptBody(args = {"alpha"}, body = "this._context().globalAlpha=alpha;")
   5.301      public native void setGlobalAlpha(double alpha) ;
   5.302  
   5.303 -    @JavaScriptBody(args = {}, body = "return this.fld_context.globalAlpha;")
   5.304 +    @JavaScriptBody(args = {}, body = "return this._context().globalAlpha;")
   5.305      public native double getGlobalAlpha();
   5.306  
   5.307 -    @JavaScriptBody(args = {"operation"}, body = "this.fld_context.globalCompositeOperation=operation;")
   5.308 +    @JavaScriptBody(args = {"operation"}, body = "this._context().globalCompositeOperation=operation;")
   5.309      public native void setGlobalCompositeOperation(double alpha);
   5.310  
   5.311 -    @JavaScriptBody(args = {}, body = "return this.fld_context.globalCompositeOperation;")
   5.312 +    @JavaScriptBody(args = {}, body = "return this._context().globalCompositeOperation;")
   5.313      public native double getGlobalCompositeOperation();
   5.314  
   5.315      public LinearGradient createLinearGradient(double x0, double y0, double x1, double y1) {
     6.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Fri Jan 25 16:47:04 2013 +0100
     6.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Sat Jan 26 08:47:05 2013 +0100
     6.3 @@ -114,11 +114,6 @@
     6.4          out.append("\n\n").append(assignClass(className));
     6.5          out.append("function CLS() {");
     6.6          out.append("\n  if (!CLS.prototype.$instOf_").append(className).append(") {");
     6.7 -        for (FieldData v : jc.getFields()) {
     6.8 -            if (v.isStatic()) {
     6.9 -                out.append("\n  CLS.").append(v.getName()).append(initField(v));
    6.10 -            }
    6.11 -        }
    6.12          if (proto == null) {
    6.13              String sc = jc.getSuperClassName(); // with _
    6.14              out.append("\n    var pp = ").
    6.15 @@ -134,6 +129,18 @@
    6.16              out.append("\n    var c = ").append(proto[0]).append(";");
    6.17              out.append("\n    var sprcls = null;");
    6.18          }
    6.19 +        for (FieldData v : jc.getFields()) {
    6.20 +            if (v.isStatic()) {
    6.21 +                out.append("\n  CLS.").append(v.getName()).append(initField(v));
    6.22 +            } else {
    6.23 +                out.append("\n  c._").append(v.getName()).append(" = function (v) {")
    6.24 +                   .append("  if (arguments.length == 1) this.fld_").
    6.25 +                    append(className).append('_').append(v.getName())
    6.26 +                   .append(" = v; return this.fld_").
    6.27 +                    append(className).append('_').append(v.getName())
    6.28 +                   .append("; };");
    6.29 +            }
    6.30 +        }
    6.31          for (MethodData m : jc.getMethods()) {
    6.32              byte[] onlyArr = m.findAnnotationData(true);
    6.33              String[] only = findAnnotation(onlyArr, jc, 
    6.34 @@ -206,6 +213,7 @@
    6.35              }
    6.36              if (!v.isStatic()) {
    6.37                  out.append("\n    this.fld_").
    6.38 +                    append(className).append('_').
    6.39                      append(v.getName()).append(initField(v));
    6.40              }
    6.41          }
    6.42 @@ -1197,8 +1205,26 @@
    6.43                      int indx = readIntArg(byteCodes, i);
    6.44                      String[] fi = jc.getFieldInfoName(indx);
    6.45                      final int type = VarType.fromFieldType(fi[2].charAt(0));
    6.46 -                    emit(out, "var @2 = @1.fld_@3;",
    6.47 -                         smapper.popA(), smapper.pushT(type), fi[1]);
    6.48 +                    final String mangleClass = mangleSig(fi[0]);
    6.49 +                    final String mangleClassAccess = accessClass(mangleClass);
    6.50 +                    emit(out, "var @2 = @4(false)._@3.call(@1);",
    6.51 +                         smapper.popA(),
    6.52 +                         smapper.pushT(type), fi[1], mangleClassAccess
    6.53 +                    );
    6.54 +                    i += 2;
    6.55 +                    break;
    6.56 +                }
    6.57 +                case opc_putfield: {
    6.58 +                    int indx = readIntArg(byteCodes, i);
    6.59 +                    String[] fi = jc.getFieldInfoName(indx);
    6.60 +                    final int type = VarType.fromFieldType(fi[2].charAt(0));
    6.61 +                    final String mangleClass = mangleSig(fi[0]);
    6.62 +                    final String mangleClassAccess = accessClass(mangleClass);
    6.63 +                    emit(out, "@4(false)._@3.call(@2, @1);",
    6.64 +                         smapper.popT(type),
    6.65 +                         smapper.popA(), fi[1], 
    6.66 +                         mangleClassAccess
    6.67 +                    );
    6.68                      i += 2;
    6.69                      break;
    6.70                  }
    6.71 @@ -1213,15 +1239,6 @@
    6.72                      addReference(fi[0]);
    6.73                      break;
    6.74                  }
    6.75 -                case opc_putfield: {
    6.76 -                    int indx = readIntArg(byteCodes, i);
    6.77 -                    String[] fi = jc.getFieldInfoName(indx);
    6.78 -                    final int type = VarType.fromFieldType(fi[2].charAt(0));
    6.79 -                    emit(out, "@2.fld_@3 = @1;",
    6.80 -                         smapper.popT(type), smapper.popA(), fi[1]);
    6.81 -                    i += 2;
    6.82 -                    break;
    6.83 -                }
    6.84                  case opc_putstatic: {
    6.85                      int indx = readIntArg(byteCodes, i);
    6.86                      String[] fi = jc.getFieldInfoName(indx);
    6.87 @@ -1420,6 +1437,10 @@
    6.88          }
    6.89      }
    6.90      
    6.91 +    static String mangleSig(String sig) {
    6.92 +        return mangleSig(sig, 0, sig.length());
    6.93 +    }
    6.94 +    
    6.95      private static String mangleSig(String txt, int first, int last) {
    6.96          StringBuilder sb = new StringBuilder();
    6.97          for (int i = first; i < last; i++) {
     7.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/VMLazy.java	Fri Jan 25 16:47:04 2013 +0100
     7.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/VMLazy.java	Sat Jan 26 08:47:05 2013 +0100
     7.3 @@ -117,8 +117,8 @@
     7.4          body =
     7.5          "var cls = n.replace__Ljava_lang_String_2CC('/','_').toString();"
     7.6          + "\nvar dot = n.replace__Ljava_lang_String_2CC('/','.').toString();"
     7.7 -        + "\nvar lazy = this.fld_lazy;"
     7.8 -        + "\nvar loader = lazy.fld_loader;"
     7.9 +        + "\nvar lazy = this._lazy();"
    7.10 +        + "\nvar loader = lazy._loader();"
    7.11          + "\nvar vm = loader.vm;"
    7.12          + "\nif (vm[cls]) return false;"
    7.13          + "\nvm[cls] = function() {"
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/InheritanceA.java	Sat Jan 26 08:47:05 2013 +0100
     8.3 @@ -0,0 +1,34 @@
     8.4 +/**
     8.5 + * Back 2 Browser Bytecode Translator
     8.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     8.7 + *
     8.8 + * This program is free software: you can redistribute it and/or modify
     8.9 + * it under the terms of the GNU General Public License as published by
    8.10 + * the Free Software Foundation, version 2 of the License.
    8.11 + *
    8.12 + * This program is distributed in the hope that it will be useful,
    8.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    8.15 + * GNU General Public License for more details.
    8.16 + *
    8.17 + * You should have received a copy of the GNU General Public License
    8.18 + * along with this program. Look for COPYING file in the top folder.
    8.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
    8.20 + */
    8.21 +package org.apidesign.bck2brwsr.tck;
    8.22 +
    8.23 +/**
    8.24 + *
    8.25 + * @author Jaroslav Tulach <jtulach@netbeans.org>
    8.26 + */
    8.27 +public class InheritanceA {
    8.28 +    private String name;
    8.29 +    
    8.30 +    public void setA(String n) {
    8.31 +        this.name = n;
    8.32 +    }
    8.33 +    
    8.34 +    public String getA() {
    8.35 +        return name;
    8.36 +    }
    8.37 +}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/InheritanceB.java	Sat Jan 26 08:47:05 2013 +0100
     9.3 @@ -0,0 +1,34 @@
     9.4 +/**
     9.5 + * Back 2 Browser Bytecode Translator
     9.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     9.7 + *
     9.8 + * This program is free software: you can redistribute it and/or modify
     9.9 + * it under the terms of the GNU General Public License as published by
    9.10 + * the Free Software Foundation, version 2 of the License.
    9.11 + *
    9.12 + * This program is distributed in the hope that it will be useful,
    9.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    9.15 + * GNU General Public License for more details.
    9.16 + *
    9.17 + * You should have received a copy of the GNU General Public License
    9.18 + * along with this program. Look for COPYING file in the top folder.
    9.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
    9.20 + */
    9.21 +package org.apidesign.bck2brwsr.tck;
    9.22 +
    9.23 +/**
    9.24 + *
    9.25 + * @author Jaroslav Tulach <jtulach@netbeans.org>
    9.26 + */
    9.27 +public class InheritanceB extends InheritanceA {
    9.28 +    private String name;
    9.29 +    
    9.30 +    public void setB(String n) {
    9.31 +        this.name = n;
    9.32 +    }
    9.33 +    
    9.34 +    public String getB() {
    9.35 +        return name;
    9.36 +    }
    9.37 +}
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/InheritanceTest.java	Sat Jan 26 08:47:05 2013 +0100
    10.3 @@ -0,0 +1,41 @@
    10.4 +/**
    10.5 + * Back 2 Browser Bytecode Translator
    10.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    10.7 + *
    10.8 + * This program is free software: you can redistribute it and/or modify
    10.9 + * it under the terms of the GNU General Public License as published by
   10.10 + * the Free Software Foundation, version 2 of the License.
   10.11 + *
   10.12 + * This program is distributed in the hope that it will be useful,
   10.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   10.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   10.15 + * GNU General Public License for more details.
   10.16 + *
   10.17 + * You should have received a copy of the GNU General Public License
   10.18 + * along with this program. Look for COPYING file in the top folder.
   10.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   10.20 + */
   10.21 +package org.apidesign.bck2brwsr.tck;
   10.22 +
   10.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
   10.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
   10.25 +import org.testng.annotations.Factory;
   10.26 +
   10.27 +/**
   10.28 + *
   10.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   10.30 + */
   10.31 +public class InheritanceTest {
   10.32 +
   10.33 +    @Compare public String checkFieldsIndependent() throws ClassNotFoundException {
   10.34 +        InheritanceB ib = new InheritanceB();
   10.35 +        ib.setA("A");
   10.36 +        ib.setB("B");
   10.37 +        return "A: " + ib.getA() + " B: " + ib.getB();
   10.38 +    }
   10.39 +    
   10.40 +    @Factory
   10.41 +    public static Object[] create() {
   10.42 +        return VMTest.create(InheritanceTest.class);
   10.43 +    }
   10.44 +}