1.1 --- a/benchmarks/matrix-multiplication/src/main/java/org/apidesign/benchmark/matrixmul/Matrix.java Tue Jan 22 09:19:47 2013 +0100
1.2 +++ b/benchmarks/matrix-multiplication/src/main/java/org/apidesign/benchmark/matrixmul/Matrix.java Tue Jan 22 19:27:00 2013 +0100
1.3 @@ -45,7 +45,7 @@
1.4 //final int x = 10;
1.5 for (int i = 0; i < rank; i++) {
1.6 for (int j = 0; j < rank; j++) {
1.7 - data[i][j] = i + j;
1.8 + data[i][j] = 1 / (1 + i + j);
1.9 }
1.10 }
1.11 }
2.1 --- a/benchmarks/matrix-multiplication/src/test/java/org/apidesign/benchmark/matrixmul/MatrixTest.java Tue Jan 22 09:19:47 2013 +0100
2.2 +++ b/benchmarks/matrix-multiplication/src/test/java/org/apidesign/benchmark/matrixmul/MatrixTest.java Tue Jan 22 19:27:00 2013 +0100
2.3 @@ -27,8 +27,6 @@
2.4 * @author Jaroslav Tulach <jtulach@netbeans.org>
2.5 */
2.6 public class MatrixTest {
2.7 - public static final int ITERATION_COUNT = 10;
2.8 -
2.9 public MatrixTest() {
2.10 }
2.11
2.12 @@ -41,12 +39,9 @@
2.13 m2.generateData();
2.14
2.15 Matrix res = null;
2.16 - for (int i = 0; i < ITERATION_COUNT; i++) {
2.17 - Matrix m = m1.multiply(m2);
2.18 - if (res != null && !res.equals(m)) {
2.19 - return "different";
2.20 - }
2.21 - res = m;
2.22 + for (int i = 0; i < 10000; i++) {
2.23 + res = m1.multiply(m2);
2.24 + m1 = res;
2.25 }
2.26
2.27 StringBuilder sb = new StringBuilder();
3.1 --- a/emul/src/main/java/java/lang/Class.java Tue Jan 22 09:19:47 2013 +0100
3.2 +++ b/emul/src/main/java/java/lang/Class.java Tue Jan 22 19:27:00 2013 +0100
3.3 @@ -1198,7 +1198,8 @@
3.4 )
3.5 native static Class getPrimitiveClass(String type);
3.6
3.7 - public boolean desiredAssertionStatus() {
3.8 - return false;
3.9 - }
3.10 + @JavaScriptBody(args = {}, body =
3.11 + "return vm.desiredAssertionStatus ? vm.desiredAssertionStatus : false;"
3.12 + )
3.13 + public native boolean desiredAssertionStatus();
3.14 }
4.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/PageProcessor.java Tue Jan 22 09:19:47 2013 +0100
4.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/PageProcessor.java Tue Jan 22 19:27:00 2013 +0100
4.3 @@ -160,11 +160,17 @@
4.4 if (tag.equals("input")) {
4.5 return "Input";
4.6 }
4.7 + if (tag.equals("canvas")) {
4.8 + return "Canvas";
4.9 + }
4.10 + if (tag.equals("img")) {
4.11 + return "Image";
4.12 + }
4.13 return "Element";
4.14 }
4.15
4.16 private static String cnstnt(String id) {
4.17 - return id.toUpperCase(Locale.ENGLISH).replace('.', '_');
4.18 + return id.toUpperCase(Locale.ENGLISH).replace('.', '_').replace('-', '_');
4.19 }
4.20
4.21 private boolean initializeOnClick(
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Canvas.java Tue Jan 22 19:27:00 2013 +0100
5.3 @@ -0,0 +1,61 @@
5.4 +/**
5.5 + * Back 2 Browser Bytecode Translator
5.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5.7 + *
5.8 + * This program is free software: you can redistribute it and/or modify
5.9 + * it under the terms of the GNU General Public License as published by
5.10 + * the Free Software Foundation, version 2 of the License.
5.11 + *
5.12 + * This program is distributed in the hope that it will be useful,
5.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5.15 + * GNU General Public License for more details.
5.16 + *
5.17 + * You should have received a copy of the GNU General Public License
5.18 + * along with this program. Look for COPYING file in the top folder.
5.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
5.20 + */
5.21 +package org.apidesign.bck2brwsr.htmlpage.api;
5.22 +
5.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
5.24 +
5.25 +/**
5.26 + *
5.27 + * @author Anton Epple <toni.epple@eppleton.de>
5.28 + */
5.29 +public class Canvas extends Element {
5.30 +
5.31 + public Canvas(String id) {
5.32 + super(id);
5.33 + }
5.34 +
5.35 + public void setHeight(int height) {
5.36 + setAttribute(this, "height", height);
5.37 + }
5.38 +
5.39 + public int getHeight() {
5.40 + return (Integer) getAttribute(this, "height");
5.41 + }
5.42 +
5.43 + public void setWidth(int width) {
5.44 + setAttribute(this, "width", width);
5.45 + }
5.46 +
5.47 + public int getWidth() {
5.48 + return (Integer) getAttribute(this, "width");
5.49 + }
5.50 +
5.51 + @JavaScriptBody(
5.52 + args = {"el"},
5.53 + body = "var e = window.document.getElementById(el.fld_id);\n"
5.54 + + "return e.getContext('2d');\n")
5.55 + private native static Object getContextImpl(Canvas el);
5.56 +
5.57 + public GraphicsContext getContext() {
5.58 + return new GraphicsContext(getContextImpl(this));
5.59 + }
5.60 +
5.61 + @Override
5.62 + void dontSubclass() {
5.63 + }
5.64 +}
6.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java Tue Jan 22 09:19:47 2013 +0100
6.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java Tue Jan 22 19:27:00 2013 +0100
6.3 @@ -46,6 +46,12 @@
6.4 )
6.5 static native Object getAttribute(Element el, String property);
6.6
6.7 + @JavaScriptBody(
6.8 + args={"el"},
6.9 + body="return window.document.getElementById(el.fld_id);"
6.10 + )
6.11 + static native Object getElementById(Element el);
6.12 +
6.13 /** Executes given runnable when user performs a "click" on the given
6.14 * element.
6.15 * @param r the runnable to execute, never null
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/GraphicsContext.java Tue Jan 22 19:27:00 2013 +0100
7.3 @@ -0,0 +1,335 @@
7.4 +/**
7.5 + * Back 2 Browser Bytecode Translator
7.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
7.7 + *
7.8 + * This program is free software: you can redistribute it and/or modify
7.9 + * it under the terms of the GNU General Public License as published by
7.10 + * the Free Software Foundation, version 2 of the License.
7.11 + *
7.12 + * This program is distributed in the hope that it will be useful,
7.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7.15 + * GNU General Public License for more details.
7.16 + *
7.17 + * You should have received a copy of the GNU General Public License
7.18 + * along with this program. Look for COPYING file in the top folder.
7.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
7.20 + */
7.21 +package org.apidesign.bck2brwsr.htmlpage.api;
7.22 +
7.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
7.24 +
7.25 +/**
7.26 + *
7.27 + * @author Anton Epple <toni.epple@eppleton.de>
7.28 + */
7.29 +public class GraphicsContext {
7.30 +
7.31 + Object context;
7.32 +
7.33 + GraphicsContext(Object contextImpl) {
7.34 + this.context = contextImpl;
7.35 + }
7.36 +
7.37 + @JavaScriptBody(args = {"centerx", "centery", "radius", "startangle", "endangle", "ccw"},
7.38 + body = "this.fld_context.arc(centerx,centery, radius, startangle, endangle,ccw);")
7.39 + public native void arc(double centerX,
7.40 + double centerY,
7.41 + double startAngle,
7.42 + double radius,
7.43 + double endAngle,
7.44 + boolean ccw);
7.45 +
7.46 + @JavaScriptBody(args = {"x1", "y1", "x2", "y2", "r"},
7.47 + body = "this.fld_context.arcTo(x1,y1,x2,y2,r);")
7.48 + public native void arcTo(double x1,
7.49 + double y1,
7.50 + double x2,
7.51 + double y2,
7.52 + double r);
7.53 +
7.54 + @JavaScriptBody(args = {"x", "y"},
7.55 + body = "return this.fld_context.isPointInPath(x,y);")
7.56 + public native boolean isPointInPath(double x, double y);
7.57 +
7.58 + @JavaScriptBody(args = {}, body = "this.fld_context.fill();")
7.59 + public native void fill();
7.60 +
7.61 + @JavaScriptBody(args = {}, body = "this.fld_context.stroke();")
7.62 + public native void stroke();
7.63 +
7.64 + @JavaScriptBody(args = {}, body = "this.fld_context.beginPath();")
7.65 + public native void beginPath();
7.66 +
7.67 + @JavaScriptBody(args = {}, body = "this.fld_context.closePath();")
7.68 + public native void closePath();
7.69 +
7.70 + @JavaScriptBody(args = {}, body = "this.fld_context.clip();")
7.71 + public native void clip();
7.72 +
7.73 + @JavaScriptBody(args = {"x", "y"}, body = "this.fld_context.moveTo(x,y);")
7.74 + public native void moveTo(double x, double y);
7.75 +
7.76 + @JavaScriptBody(args = {"x", "y"}, body = "this.fld_context.lineTo(x,y);")
7.77 + public native void lineTo(double x, double y);
7.78 +
7.79 + @JavaScriptBody(args = {"cpx", "cpy", "x", "y"}, body = "this.fld_context.quadraticCurveTo(cpx,cpy,x,y);")
7.80 + public native void quadraticCurveTo(double cpx, double cpy, double x, double y);
7.81 +
7.82 + @JavaScriptBody(args = {"cp1x", "cp1y", "cp2x", "cp2y", "x", "y"},
7.83 + body = "this.fld_context.bezierCurveTo(cp1x,cp1y,cp2x,cp2y,x,y);")
7.84 + public native void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y);
7.85 +
7.86 + @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this.fld_context.fillRect(x,y,width,height);")
7.87 + public native void fillRect(double x, double y, double width, double height);
7.88 +
7.89 + @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this.fld_context.strokeRect(x,y,width,height);")
7.90 + public native void strokeRect(double x, double y, double width, double height);
7.91 +
7.92 + @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this.fld_context.clearRect(x,y,width,height);")
7.93 + public native void clearRect(double x, double y, double width, double height);
7.94 +
7.95 + @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this.fld_context.rectect(x,y,width,height);")
7.96 + public native void rect(double x, double y, double width, double height);
7.97 +
7.98 + @JavaScriptBody(args = {}, body = "this.fld_context.save();")
7.99 + public native void save();
7.100 +
7.101 + @JavaScriptBody(args = {}, body = "this.fld_context.restore();")
7.102 + public native void restore();
7.103 +
7.104 + @JavaScriptBody(args = {"angle"}, body = "this.fld_context.rotate(angle);")
7.105 + public native void rotate(double angle);
7.106 +
7.107 + @JavaScriptBody(args = {"a", "b", "c", "d", "e", "f"}, body = "this.fld_context.transform(a,b,c,d,e,f);")
7.108 + public native void transform(double a, double b, double c, double d, double e, double f);
7.109 +
7.110 + @JavaScriptBody(args = {"a", "b", "c", "d", "e", "f"}, body = "this.fld_context.setTransform(a,b,c,d,e,f);")
7.111 + public native void setTransform(double a, double b, double c, double d, double e, double f);
7.112 +
7.113 + @JavaScriptBody(args = {"x", "y"}, body = "this.fld_context.translate(x,y);")
7.114 + public native void translate(double x, double y);
7.115 +
7.116 + @JavaScriptBody(args = {"x", "y"}, body = "this.fld_context.scale(x,y);")
7.117 + public native void scale(double x, double y);
7.118 +
7.119 + public void drawImage(Image image, double x, double y) {
7.120 + drawImageImpl(context, Element.getElementById(image), x, y);
7.121 + }
7.122 +
7.123 + public void drawImage(Image image, double x, double y, double width, double height) {
7.124 + drawImageImpl(context, Element.getElementById(image), x, y, width, height);
7.125 + }
7.126 +
7.127 + public void drawImage(Image image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height) {
7.128 + drawImageImpl(context, Element.getElementById(image), sx, sy, sWidth, sHeight, x, y, width, height);
7.129 + }
7.130 +
7.131 + @JavaScriptBody(args = {"ctx", "img", "x", "y", "width", "height"}, body = "ctx.drawImage(img,x,y,width,height);")
7.132 + private native static void drawImageImpl(Object ctx, Object img, double x, double y, double width, double height);
7.133 +
7.134 + @JavaScriptBody(args = {"ctx", "img", "sx", "sy", "swidth", "sheight", "x", "y", "width", "height"}, body = "ctx.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);")
7.135 + private native static void drawImageImpl(Object ctx, Object img, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height);
7.136 +
7.137 + @JavaScriptBody(args = {"ctx", "img", "x", "y"}, body = "ctx.drawImage(img,x,y);")
7.138 + private native static void drawImageImpl(Object ctx, Object img, double x, double y);
7.139 +
7.140 + @JavaScriptBody(args = {"style"}, body = "this.fld_context.fillStyle=style;")
7.141 + public native void setFillStyle(String style);
7.142 +
7.143 + @JavaScriptBody(args = {}, body = "return this.fld_context.fillStyle;")
7.144 + public native String getFillStyle();
7.145 +
7.146 + public void setFillStyle(LinearGradient style) {
7.147 + setFillStyleImpl(context, style.object());
7.148 + }
7.149 +
7.150 + public void setFillStyle(RadialGradient style) {
7.151 + setFillStyleImpl(context, style.object());
7.152 + }
7.153 +
7.154 + public void setFillStyle(Pattern style) {
7.155 + setFillStyleImpl(context, style.object());
7.156 + }
7.157 +
7.158 + @JavaScriptBody(args = {"context","obj"}, body = "context.fillStyle=obj;")
7.159 + private native void setFillStyleImpl(Object context, Object obj);
7.160 +
7.161 + @JavaScriptBody(args = {"style"}, body = "this.fld_context.strokeStyle=style;")
7.162 + public native void setStrokeStyle(String style);
7.163 +
7.164 + public void setStrokeStyle(LinearGradient style) {
7.165 + setStrokeStyleImpl(context, style.object());
7.166 + }
7.167 +
7.168 + public void setStrokeStyle(RadialGradient style) {
7.169 + setStrokeStyleImpl(context, style.object());
7.170 + }
7.171 +
7.172 + @JavaScriptBody(args = {"style"}, body = "this.fld_context.fillStyle=style;")
7.173 + public void setStrokeStyle(Pattern style) {
7.174 + setStrokeStyleImpl(context, style.object());
7.175 + }
7.176 +
7.177 + @JavaScriptBody(args = {"context","obj"}, body = "context.strokeStyle=obj;")
7.178 + private native void setStrokeStyleImpl(Object context, Object obj);
7.179 +
7.180 + @JavaScriptBody(args = {"color"}, body = "this.fld_context.shadowColor=color;")
7.181 + public native void setShadowColor(String color);
7.182 +
7.183 + @JavaScriptBody(args = {"blur"}, body = "this.fld_context.shadowBlur=blur;")
7.184 + public native void setShadowBlur(double blur);
7.185 +
7.186 + @JavaScriptBody(args = {"x"}, body = "this.fld_context.shadowOffsetX=x;")
7.187 + public native void setShadowOffsetX(double x);
7.188 +
7.189 + @JavaScriptBody(args = {"y"}, body = "this.fld_context.shadowOffsetY=y;")
7.190 + public native void setShadowOffsetY(double y);
7.191 +
7.192 + @JavaScriptBody(args = {}, body = "return this.fld_context.strokeStyle;")
7.193 + public native String getStrokeStyle();
7.194 +
7.195 + @JavaScriptBody(args = {}, body = "return this.fld_context.shadowColor;")
7.196 + public native String getShadowColor();
7.197 +
7.198 + @JavaScriptBody(args = {}, body = "return this.fld_context.shadowBlur;")
7.199 + public native double getShadowBlur();
7.200 +
7.201 + @JavaScriptBody(args = {}, body = "return this.fld_context.shadowOffsetX;")
7.202 + public native double getShadowOffsetX();
7.203 +
7.204 + @JavaScriptBody(args = {}, body = "return this.fld_context.shadowOffsetY;")
7.205 + public native double getShadowOffsetY();
7.206 +
7.207 + @JavaScriptBody(args = {}, body = "return this.fld_context.lineCap;")
7.208 + public native String getLineCap();
7.209 +
7.210 + @JavaScriptBody(args = {"style"}, body = "this.fld_context.lineCap=style;")
7.211 + public native void setLineCap(String style);
7.212 +
7.213 + @JavaScriptBody(args = {}, body = "return this.fld_context.lineJoin;")
7.214 + public native String getLineJoin();
7.215 +
7.216 + @JavaScriptBody(args = {"style"}, body = "this.fld_context.lineJoin=style;")
7.217 + public native void setLineJoin(String style) ;
7.218 +
7.219 + @JavaScriptBody(args = {}, body = "return this.fld_context.lineWidth;")
7.220 + public native double getLineWidth();
7.221 +
7.222 + @JavaScriptBody(args = {"width"}, body = "this.fld_context.lineJoin=width;")
7.223 + public native void setLineWidth(double width);
7.224 +
7.225 + @JavaScriptBody(args = {}, body = "return this.fld_context.miterLimit;")
7.226 + public native double getMiterLimit();
7.227 +
7.228 + @JavaScriptBody(args = {"limit"}, body = "this.fld_context.miterLimit=limit;")
7.229 + public native void setMiterLimit(double limit);
7.230 +
7.231 + @JavaScriptBody(args = {}, body = "return this.fld_context.font;")
7.232 + public native String getFont();
7.233 +
7.234 + @JavaScriptBody(args = {"font"}, body = "this.fld_context.font=font;")
7.235 + public native void setFont(String font);
7.236 +
7.237 + @JavaScriptBody(args = {}, body = "return this.fld_context.textAlign;")
7.238 + public native String getTextAlign();
7.239 +
7.240 + @JavaScriptBody(args = {"textalign"}, body = "this.fld_context.textAlign=textalign;")
7.241 + public native void setTextAlign(String textAlign);
7.242 +
7.243 + @JavaScriptBody(args = {}, body = "return this.fld_context.textBaseline;")
7.244 + public native String getTextBaseline();
7.245 +
7.246 + @JavaScriptBody(args = {"textbaseline"}, body = "this.fld_context.textBaseline=textbaseline;")
7.247 + public native void setTextBaseline(String textbaseline);
7.248 +
7.249 + @JavaScriptBody(args = {"text", "x", "y"}, body = "this.fld_context.fillText(text,x,y);")
7.250 + public native void fillText(String text, double x, double y);
7.251 +
7.252 + @JavaScriptBody(args = {"text", "x", "y", "maxwidth"}, body = "this.fld_context.fillText(text,x,y,maxwidth);")
7.253 + public void fillText(String text, double x, double y, double maxWidth) {
7.254 + }
7.255 +
7.256 + public TextMetrics measureText(String text) {
7.257 + return new TextMetrics(measureTextImpl(text));
7.258 + }
7.259 +
7.260 + @JavaScriptBody(args = {"text"},
7.261 + body = "return this.fld_context.measureText(text);")
7.262 + private native Object measureTextImpl(String text);
7.263 +
7.264 + @JavaScriptBody(args = {"text", "x", "y"}, body = "this.fld_context.strokeText(text,x,y);")
7.265 + public native void strokeText(String text, double x, double y);
7.266 +
7.267 + @JavaScriptBody(args = {"text", "x", "y", "maxWidth"}, body = "this.fld_context.strokeText(text,x,y,maxWidth);")
7.268 + public native void strokeText(String text, double x, double y, double maxWidth) ;
7.269 +
7.270 + public ImageData createImageData(double x, double y) {
7.271 + return new ImageData(createImageDataImpl(x, y));
7.272 + }
7.273 +
7.274 + @JavaScriptBody(args = {"x", "y"},
7.275 + body = "return this.fld_context.createImageData(x,y);")
7.276 + private native Object createImageDataImpl(double x, double y);
7.277 +
7.278 + public ImageData createImageData(ImageData imageData) {
7.279 + return new ImageData(createImageDataImpl(imageData.getWidth(), imageData.getHeight()));
7.280 + }
7.281 +
7.282 + public ImageData getImageData(double x, double y, double width, double height) {
7.283 + return new ImageData(getImageDataImpl(x, y, width, height));
7.284 + }
7.285 +
7.286 + @JavaScriptBody(args = {"x", "y", "width", "height"},
7.287 + body = "return this.fld_context.getImageData(x,y,width,height);")
7.288 + private native Object getImageDataImpl(double x, double y, double width, double height);
7.289 +
7.290 + public void putImageData(ImageData imageData, double x, double y) {
7.291 + putImageDataImpl(imageData.object(), x, y);
7.292 + }
7.293 +
7.294 + @JavaScriptBody(args = {"imageData", "x", "y"},
7.295 + body = "this.fld_context.putImageData(imageData,x,y);")
7.296 + private native void putImageDataImpl(Object imageData, double x, double y);
7.297 +
7.298 + public void putImageData(ImageData imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight) {
7.299 + putImageDataImpl(imageData.object(), x, y, dirtyx, dirtyy, dirtywidth, dirtyheight);
7.300 + }
7.301 +
7.302 + @JavaScriptBody(args = {"imageData", "x", "y", "dirtyx", "dirtyy", "dirtywidth", "dirtyheight"},
7.303 + body = "this.fld_context.putImageData(imageData,x,y, dirtyx, dirtyy, dirtywidth,dirtyheight);")
7.304 + private native void putImageDataImpl(Object imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight);
7.305 +
7.306 + @JavaScriptBody(args = {"alpha"}, body = "this.fld_context.globalAlpha=alpha;")
7.307 + public native void setGlobalAlpha(double alpha) ;
7.308 +
7.309 + @JavaScriptBody(args = {}, body = "return this.fld_context.globalAlpha;")
7.310 + public native double getGlobalAlpha();
7.311 +
7.312 + @JavaScriptBody(args = {"operation"}, body = "this.fld_context.globalCompositeOperation=operation;")
7.313 + public native void setGlobalCompositeOperation(double alpha);
7.314 +
7.315 + @JavaScriptBody(args = {}, body = "return this.fld_context.globalCompositeOperation;")
7.316 + public native double getGlobalCompositeOperation();
7.317 +
7.318 + public LinearGradient createLinearGradient(double x0, double y0, double x1, double y1) {
7.319 + return new LinearGradient(createLinearGradientImpl(context, x0, y0, x1, y1));
7.320 + }
7.321 +
7.322 + @JavaScriptBody(args = {"context", "x0", "y0", "x1", "y1"}, body = "return context.createLinearGradient(x0,y0,x1,y1);")
7.323 + private native Object createLinearGradientImpl(Object context, double x0, double y0, double x1, double y1);
7.324 +
7.325 + public Pattern createPattern(Image image, String repeat) {
7.326 + return new Pattern(createPatternImpl(context, image, repeat));
7.327 + }
7.328 +
7.329 + @JavaScriptBody(args = {"context", "image", "repeat"}, body = "return context.createPattern(image, repeat);")
7.330 + private static native Object createPatternImpl(Object context, Image image, String repeat);
7.331 +
7.332 + public RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) {
7.333 + return new RadialGradient(createRadialGradientImpl(context, x0, y0, r0, x1, y1, r1));
7.334 + }
7.335 +
7.336 + @JavaScriptBody(args = {"context", "x0", "y0", "r0", "x1", "y1", "r1"}, body = "return context.createRadialGradient(x0,y0,r0,x1,y1,r1);")
7.337 + private static native Object createRadialGradientImpl(Object context, double x0, double y0, double r0, double x1, double y1, double r1);
7.338 +}
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Image.java Tue Jan 22 19:27:00 2013 +0100
8.3 @@ -0,0 +1,36 @@
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.htmlpage.api;
8.22 +
8.23 +/**
8.24 + *
8.25 + * @author Anton Epple <toni.epple@eppleton.de>
8.26 + */
8.27 +public class Image extends Element{
8.28 +
8.29 + public Image(String id) {
8.30 + super(id);
8.31 + }
8.32 +
8.33 +
8.34 +
8.35 + @Override
8.36 + void dontSubclass() {
8.37 + }
8.38 +
8.39 +}
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
9.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/ImageData.java Tue Jan 22 19:27:00 2013 +0100
9.3 @@ -0,0 +1,89 @@
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 +/*
9.22 + * To change this template, choose Tools | Templates
9.23 + * and open the template in the editor.
9.24 + */
9.25 +package org.apidesign.bck2brwsr.htmlpage.api;
9.26 +
9.27 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
9.28 +
9.29 +/**
9.30 + *
9.31 + * @author Anton Epple <toni.epple@eppleton.de>
9.32 + */
9.33 +public class ImageData {
9.34 +
9.35 + private Object imageData;
9.36 + private Data data;
9.37 +
9.38 + public ImageData(Object imageData) {
9.39 + this.imageData = imageData;
9.40 + }
9.41 +
9.42 + public Data getData(){
9.43 + if (data == null){
9.44 + data = new Data(getDataImpl(imageData));
9.45 + }
9.46 + return data;
9.47 + }
9.48 +
9.49 + @JavaScriptBody(args = {"imageData"}, body = "return imageData.data")
9.50 + public native Object getDataImpl(Object imageData);
9.51 +
9.52 + public double getWidth() {
9.53 + return getWidthImpl(imageData);
9.54 + }
9.55 +
9.56 + @JavaScriptBody(args = {"imageData"}, body = "return imagedata.width;")
9.57 + private static native double getWidthImpl(Object imageData);
9.58 +
9.59 + public double getHeight() {
9.60 + return getHeightImpl(imageData);
9.61 + }
9.62 +
9.63 + @JavaScriptBody(args = {"imageData"}, body = "return imagedata.height;")
9.64 + private static native double getHeightImpl(Object imageData);
9.65 +
9.66 + Object object() {
9.67 + return imageData;
9.68 + }
9.69 +
9.70 + public static class Data {
9.71 +
9.72 + Object data;
9.73 +
9.74 + public Data(Object data) {
9.75 + this.data = data;
9.76 + }
9.77 +
9.78 + public int get(int index) {
9.79 + return getImpl(data, index);
9.80 + }
9.81 +
9.82 + public void set(int index, int value) {
9.83 + setImpl(data, index, value);
9.84 + }
9.85 +
9.86 + @JavaScriptBody(args = {"data", "index", "value"}, body = "data[index]=value;")
9.87 + private static native void setImpl(Object data, int index, int value);
9.88 +
9.89 + @JavaScriptBody(args = {"imagedata", "index"}, body = "return data[index];")
9.90 + private static native int getImpl(Object data, int index);
9.91 + }
9.92 +}
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/LinearGradient.java Tue Jan 22 19:27:00 2013 +0100
10.3 @@ -0,0 +1,45 @@
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.htmlpage.api;
10.22 +
10.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
10.24 +
10.25 +/**
10.26 + *
10.27 + * @author Anton Epple <toni.epple@eppleton.de>
10.28 + */
10.29 +public class LinearGradient {
10.30 +
10.31 + private final Object gradient;
10.32 +
10.33 + LinearGradient(Object linearGradient) {
10.34 + this.gradient = linearGradient;
10.35 + }
10.36 +
10.37 + Object object() {
10.38 + return gradient;
10.39 + }
10.40 +
10.41 + public void addColorStop(double position, String color) {
10.42 + addColorStopImpl(gradient, position, color);
10.43 + }
10.44 +
10.45 + @JavaScriptBody(args = {"gradient", "position", "color"}, body =
10.46 + "gradient.addColorStop(position,color)")
10.47 + private static native void addColorStopImpl(Object gradient, double position, String color);
10.48 +}
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Paint.java Tue Jan 22 19:27:00 2013 +0100
11.3 @@ -0,0 +1,30 @@
11.4 +/**
11.5 + * Back 2 Browser Bytecode Translator
11.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
11.7 + *
11.8 + * This program is free software: you can redistribute it and/or modify
11.9 + * it under the terms of the GNU General Public License as published by
11.10 + * the Free Software Foundation, version 2 of the License.
11.11 + *
11.12 + * This program is distributed in the hope that it will be useful,
11.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11.15 + * GNU General Public License for more details.
11.16 + *
11.17 + * You should have received a copy of the GNU General Public License
11.18 + * along with this program. Look for COPYING file in the top folder.
11.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
11.20 + */
11.21 +package org.apidesign.bck2brwsr.htmlpage.api;
11.22 +
11.23 +/**
11.24 + *
11.25 + * @author Anton Epple <toni.epple@eppleton.de>
11.26 + */
11.27 +public class Paint {
11.28 +
11.29 +
11.30 + String asString(){
11.31 + return "";
11.32 + }
11.33 +}
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
12.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Pattern.java Tue Jan 22 19:27:00 2013 +0100
12.3 @@ -0,0 +1,35 @@
12.4 +/**
12.5 + * Back 2 Browser Bytecode Translator
12.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
12.7 + *
12.8 + * This program is free software: you can redistribute it and/or modify
12.9 + * it under the terms of the GNU General Public License as published by
12.10 + * the Free Software Foundation, version 2 of the License.
12.11 + *
12.12 + * This program is distributed in the hope that it will be useful,
12.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12.15 + * GNU General Public License for more details.
12.16 + *
12.17 + * You should have received a copy of the GNU General Public License
12.18 + * along with this program. Look for COPYING file in the top folder.
12.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
12.20 + */
12.21 +package org.apidesign.bck2brwsr.htmlpage.api;
12.22 +
12.23 +/**
12.24 + *
12.25 + * @author Anton Epple <toni.epple@eppleton.de>
12.26 + */
12.27 +public class Pattern {
12.28 +
12.29 + private Object pattern;
12.30 +
12.31 + public Pattern(Object pattern) {
12.32 + this.pattern = pattern;
12.33 + }
12.34 +
12.35 + Object object() {
12.36 + return pattern;
12.37 + }
12.38 +}
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
13.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/RadialGradient.java Tue Jan 22 19:27:00 2013 +0100
13.3 @@ -0,0 +1,45 @@
13.4 +/**
13.5 + * Back 2 Browser Bytecode Translator
13.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
13.7 + *
13.8 + * This program is free software: you can redistribute it and/or modify
13.9 + * it under the terms of the GNU General Public License as published by
13.10 + * the Free Software Foundation, version 2 of the License.
13.11 + *
13.12 + * This program is distributed in the hope that it will be useful,
13.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13.15 + * GNU General Public License for more details.
13.16 + *
13.17 + * You should have received a copy of the GNU General Public License
13.18 + * along with this program. Look for COPYING file in the top folder.
13.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
13.20 + */
13.21 +package org.apidesign.bck2brwsr.htmlpage.api;
13.22 +
13.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
13.24 +
13.25 +/**
13.26 + *
13.27 + * @author Anton Epple <toni.epple@eppleton.de>
13.28 + */
13.29 +public class RadialGradient {
13.30 +
13.31 + private Object gradient;
13.32 +
13.33 + public RadialGradient(Object radialGradient) {
13.34 + this.gradient = radialGradient;
13.35 + }
13.36 +
13.37 + public void addColorStop(double position, String color) {
13.38 + addColorStopImpl(gradient, position, color);
13.39 + }
13.40 +
13.41 + @JavaScriptBody(args = {"gradient", "position", "color"}, body =
13.42 + "gradient.addColorStop(position,color)")
13.43 + private static native void addColorStopImpl(Object gradient, double position, String color);
13.44 +
13.45 + Object object() {
13.46 + return gradient;
13.47 + }
13.48 +}
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
14.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/TextMetrics.java Tue Jan 22 19:27:00 2013 +0100
14.3 @@ -0,0 +1,48 @@
14.4 +/**
14.5 + * Back 2 Browser Bytecode Translator
14.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
14.7 + *
14.8 + * This program is free software: you can redistribute it and/or modify
14.9 + * it under the terms of the GNU General Public License as published by
14.10 + * the Free Software Foundation, version 2 of the License.
14.11 + *
14.12 + * This program is distributed in the hope that it will be useful,
14.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14.15 + * GNU General Public License for more details.
14.16 + *
14.17 + * You should have received a copy of the GNU General Public License
14.18 + * along with this program. Look for COPYING file in the top folder.
14.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
14.20 + */
14.21 +package org.apidesign.bck2brwsr.htmlpage.api;
14.22 +
14.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
14.24 +
14.25 +/**
14.26 + *
14.27 + * @author Anton Epple <toni.epple@eppleton.de>
14.28 + */
14.29 +public class TextMetrics {
14.30 +
14.31 + private Object textMetrics;
14.32 +
14.33 + TextMetrics(Object measureTextImpl) {
14.34 + this.textMetrics = measureTextImpl;
14.35 + }
14.36 +
14.37 + @JavaScriptBody(args = {"textMetrics"}, body = "return textMetrics.width;")
14.38 + private native double getWidth(Object textMetrics);
14.39 +
14.40 + @JavaScriptBody(args = {"textMetrics"}, body = "return textMetrics.height;")
14.41 + private native double getHeight(Object textMetrics);
14.42 +
14.43 + public double getWidth() {
14.44 + return getWidth(textMetrics);
14.45 + }
14.46 +
14.47 + public double getHeight() {
14.48 + return getHeight(textMetrics);
14.49 +
14.50 + }
14.51 +}
15.1 --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java Tue Jan 22 09:19:47 2013 +0100
15.2 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java Tue Jan 22 19:27:00 2013 +0100
15.3 @@ -55,7 +55,7 @@
15.4 */
15.5 final class Bck2BrwsrLauncher extends Launcher implements Closeable {
15.6 private static final Logger LOG = Logger.getLogger(Bck2BrwsrLauncher.class.getName());
15.7 - private static final MethodInvocation END = new MethodInvocation(null, null);
15.8 + private static final MethodInvocation END = new MethodInvocation(null, null, null);
15.9 private Set<ClassLoader> loaders = new LinkedHashSet<>();
15.10 private BlockingQueue<MethodInvocation> methods = new LinkedBlockingQueue<>();
15.11 private long timeOut;
15.12 @@ -70,9 +70,9 @@
15.13 }
15.14
15.15 @Override
15.16 - public MethodInvocation addMethod(Class<?> clazz, String method) throws IOException {
15.17 + MethodInvocation addMethod(Class<?> clazz, String method, String html) throws IOException {
15.18 loaders.add(clazz.getClassLoader());
15.19 - MethodInvocation c = new MethodInvocation(clazz.getName(), method);
15.20 + MethodInvocation c = new MethodInvocation(clazz.getName(), method, html);
15.21 methods.add(c);
15.22 try {
15.23 c.await(timeOut);
15.24 @@ -174,7 +174,13 @@
15.25 + "className: '" + cn + "', "
15.26 + "methodName: '" + mn + "', "
15.27 + "request: " + cnt
15.28 - + "}");
15.29 + );
15.30 + if (mi.html != null) {
15.31 + response.getWriter().write(", html: '");
15.32 + response.getWriter().write(encodeJSON(mi.html));
15.33 + response.getWriter().write("'");
15.34 + }
15.35 + response.getWriter().write("}");
15.36 cnt++;
15.37 }
15.38 }, "/data");
15.39 @@ -182,6 +188,22 @@
15.40 this.brwsr = launchServerAndBrwsr(server, "/execute");
15.41 }
15.42
15.43 + private static String encodeJSON(String in) {
15.44 + StringBuilder sb = new StringBuilder();
15.45 + for (int i = 0; i < in.length(); i++) {
15.46 + char ch = in.charAt(i);
15.47 + if (ch < 32 || ch == '\'' || ch == '"') {
15.48 + sb.append("\\u");
15.49 + String hs = "0000" + Integer.toHexString(ch);
15.50 + hs = hs.substring(hs.length() - 4);
15.51 + sb.append(hs);
15.52 + } else {
15.53 + sb.append(ch);
15.54 + }
15.55 + }
15.56 + return sb.toString();
15.57 + }
15.58 +
15.59 @Override
15.60 public void shutdown() throws IOException {
15.61 methods.offer(END);
15.62 @@ -216,12 +238,12 @@
15.63 if (ch == -1) {
15.64 break;
15.65 }
15.66 - if (ch == '$') {
15.67 + if (ch == '$' && params.length > 0) {
15.68 int cnt = is.read() - '0';
15.69 if (cnt == 'U' - '0') {
15.70 os.write(baseURL.getBytes());
15.71 }
15.72 - if (cnt < params.length) {
15.73 + if (cnt >= 0 && cnt < params.length) {
15.74 os.write(params[cnt].getBytes());
15.75 }
15.76 } else {
15.77 @@ -243,7 +265,8 @@
15.78 LOG.log(Level.INFO, "Desktop.browse successfully finished");
15.79 return null;
15.80 } catch (UnsupportedOperationException ex) {
15.81 - LOG.log(Level.INFO, "Desktop.browse not supported", ex);
15.82 + LOG.log(Level.INFO, "Desktop.browse not supported: {0}", ex.getMessage());
15.83 + LOG.log(Level.FINE, null, ex);
15.84 }
15.85 }
15.86 {
15.87 @@ -347,7 +370,7 @@
15.88 public Page(Res res, String resource, String... args) {
15.89 this.res = res;
15.90 this.resource = resource;
15.91 - this.args = args;
15.92 + this.args = args.length == 0 ? new String[] { "$0" } : args;
15.93 }
15.94
15.95 @Override
15.96 @@ -359,17 +382,20 @@
15.97 r = r.substring(1);
15.98 }
15.99 }
15.100 + String[] replace = {};
15.101 if (r.endsWith(".html")) {
15.102 response.setContentType("text/html");
15.103 LOG.info("Content type text/html");
15.104 + replace = args;
15.105 }
15.106 if (r.endsWith(".xhtml")) {
15.107 response.setContentType("application/xhtml+xml");
15.108 LOG.info("Content type application/xhtml+xml");
15.109 + replace = args;
15.110 }
15.111 OutputStream os = response.getOutputStream();
15.112 try (InputStream is = res.get(r)) {
15.113 - copyStream(is, os, request.getRequestURL().toString(), args);
15.114 + copyStream(is, os, request.getRequestURL().toString(), replace);
15.115 } catch (IOException ex) {
15.116 response.setDetailMessage(ex.getLocalizedMessage());
15.117 response.setError();
16.1 --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Console.java Tue Jan 22 09:19:47 2013 +0100
16.2 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Console.java Tue Jan 22 19:27:00 2013 +0100
16.3 @@ -31,11 +31,8 @@
16.4 * @author Jaroslav Tulach <jtulach@netbeans.org>
16.5 */
16.6 public class Console {
16.7 - public static String welcome() {
16.8 - return "HellofromBck2Brwsr";
16.9 - }
16.10 - public static String multiply() {
16.11 - return String.valueOf(Integer.MAX_VALUE / 2 + Integer.MAX_VALUE);
16.12 + static {
16.13 + turnAssetionStatusOn();
16.14 }
16.15
16.16 @JavaScriptBody(args = {"id", "attr"}, body =
16.17 @@ -50,7 +47,7 @@
16.18 private static native void closeWindow();
16.19
16.20 private static void log(String newText) {
16.21 - String id = "result";
16.22 + String id = "bck2brwsr.result";
16.23 String attr = "value";
16.24 setAttr(id, attr, getAttr(id, attr) + "\n" + newText);
16.25 setAttr(id, "scrollTop", getAttr(id, "scrollHeight"));
16.26 @@ -60,38 +57,74 @@
16.27 String clazz = (String) getAttr("clazz", "value");
16.28 String method = (String) getAttr("method", "value");
16.29 Object res = invokeMethod(clazz, method);
16.30 - setAttr("result", "value", res);
16.31 + setAttr("bck2brwsr.result", "value", res);
16.32 + }
16.33 +
16.34 + @JavaScriptBody(args = { "url", "callback", "arr" }, body = ""
16.35 + + "var request = new XMLHttpRequest();\n"
16.36 + + "request.open('GET', url, true);\n"
16.37 + + "request.onreadystatechange = function() {\n"
16.38 + + " if (this.readyState!==4) return;\n"
16.39 + + " arr[0] = this.responseText;\n"
16.40 + + " callback.run__V();\n"
16.41 + + "};"
16.42 + + "request.send();"
16.43 + )
16.44 + private static native void loadText(String url, Runnable callback, String[] arr) throws IOException;
16.45 +
16.46 + public static void harness(String url) throws IOException {
16.47 + log("Connecting to " + url);
16.48 + Request r = new Request(url);
16.49 }
16.50
16.51 - public static void harness(String url) {
16.52 - log("Connecting to " + url);
16.53 - try {
16.54 - URL u = new URL(url);
16.55 - for (;;) {
16.56 - String data = (String) u.getContent(new Class[] { String.class });
16.57 + private static class Request implements Runnable {
16.58 + private final String[] arr = { null };
16.59 + private final String url;
16.60 +
16.61 + private Request(String url) throws IOException {
16.62 + this.url = url;
16.63 + loadText(url, this, arr);
16.64 + }
16.65 +
16.66 + @Override
16.67 + public void run() {
16.68 + try {
16.69 + String data = arr[0];
16.70 log("\nGot \"" + data + "\"");
16.71 +
16.72 + if (data == null) {
16.73 + log("Some error exiting");
16.74 + closeWindow();
16.75 + return;
16.76 + }
16.77 +
16.78 if (data.isEmpty()) {
16.79 log("No data, exiting");
16.80 closeWindow();
16.81 - break;
16.82 + return;
16.83 }
16.84
16.85 Case c = Case.parseData(data);
16.86 + if (c.getHtmlFragment() != null) {
16.87 + setAttr("bck2brwsr.fragment", "innerHTML", c.getHtmlFragment());
16.88 + }
16.89 log("Invoking " + c.getClassName() + '.' + c.getMethodName() + " as request: " + c.getRequestId());
16.90
16.91 Object result = invokeMethod(c.getClassName(), c.getMethodName());
16.92
16.93 + setAttr("bck2brwsr.fragment", "innerHTML", "");
16.94 log("Result: " + result);
16.95
16.96 result = encodeURL("" + result);
16.97
16.98 log("Sending back: " + url + "?request=" + c.getRequestId() + "&result=" + result);
16.99 - u = new URL(url + "?request=" + c.getRequestId() + "&result=" + result);
16.100 + String u = url + "?request=" + c.getRequestId() + "&result=" + result;
16.101 +
16.102 + loadText(u, this, arr);
16.103 +
16.104 + } catch (Exception ex) {
16.105 + log(ex.getMessage());
16.106 }
16.107 -
16.108 -
16.109 - } catch (Exception ex) {
16.110 - log(ex.getMessage());
16.111 }
16.112 }
16.113
16.114 @@ -167,7 +200,7 @@
16.115 } else {
16.116 res = found.invoke(c.newInstance());
16.117 }
16.118 - } catch (Exception ex) {
16.119 + } catch (Exception | Error ex) {
16.120 res = ex.getClass().getName() + ":" + ex.getMessage();
16.121 }
16.122 } else {
16.123 @@ -175,6 +208,10 @@
16.124 }
16.125 return res;
16.126 }
16.127 +
16.128 + @JavaScriptBody(args = {}, body = "vm.desiredAssertionStatus = true;")
16.129 + private static void turnAssetionStatusOn() {
16.130 + }
16.131
16.132 private static final class Case {
16.133 private final Object data;
16.134 @@ -198,11 +235,19 @@
16.135 public String getRequestId() {
16.136 return value("request", data);
16.137 }
16.138 +
16.139 + public String getHtmlFragment() {
16.140 + return value("html", data);
16.141 + }
16.142
16.143 @JavaScriptBody(args = "s", body = "return eval('(' + s + ')');")
16.144 private static native Object toJSON(String s);
16.145
16.146 - @JavaScriptBody(args = {"p", "d"}, body = "return d[p].toString();")
16.147 + @JavaScriptBody(args = {"p", "d"}, body =
16.148 + "var v = d[p];\n"
16.149 + + "if (typeof v === 'undefined') return null;\n"
16.150 + + "return v.toString();"
16.151 + )
16.152 private static native String value(String p, Object d);
16.153 }
16.154 }
17.1 --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/JSLauncher.java Tue Jan 22 09:19:47 2013 +0100
17.2 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/JSLauncher.java Tue Jan 22 19:27:00 2013 +0100
17.3 @@ -42,10 +42,9 @@
17.4 private Object console;
17.5
17.6
17.7 - @Override
17.8 - public MethodInvocation addMethod(Class<?> clazz, String method) {
17.9 + @Override MethodInvocation addMethod(Class<?> clazz, String method, String html) {
17.10 loaders.add(clazz.getClassLoader());
17.11 - MethodInvocation mi = new MethodInvocation(clazz.getName(), method);
17.12 + MethodInvocation mi = new MethodInvocation(clazz.getName(), method, html);
17.13 try {
17.14 mi.result(code.invokeMethod(
17.15 console,
18.1 --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Launcher.java Tue Jan 22 09:19:47 2013 +0100
18.2 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Launcher.java Tue Jan 22 19:27:00 2013 +0100
18.3 @@ -32,12 +32,12 @@
18.4 Launcher() {
18.5 }
18.6
18.7 - abstract MethodInvocation addMethod(Class<?> clazz, String method) throws IOException;
18.8 + abstract MethodInvocation addMethod(Class<?> clazz, String method, String html) throws IOException;
18.9
18.10 public abstract void initialize() throws IOException;
18.11 public abstract void shutdown() throws IOException;
18.12 - public MethodInvocation invokeMethod(Class<?> clazz, String method) throws IOException {
18.13 - return addMethod(clazz, method);
18.14 + public MethodInvocation invokeMethod(Class<?> clazz, String method, String html) throws IOException {
18.15 + return addMethod(clazz, method, html);
18.16 }
18.17
18.18
19.1 --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/MethodInvocation.java Tue Jan 22 09:19:47 2013 +0100
19.2 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/MethodInvocation.java Tue Jan 22 19:27:00 2013 +0100
19.3 @@ -28,12 +28,14 @@
19.4 final CountDownLatch wait = new CountDownLatch(1);
19.5 final String className;
19.6 final String methodName;
19.7 + final String html;
19.8 private String result;
19.9 private Throwable exception;
19.10
19.11 - MethodInvocation(String className, String methodName) {
19.12 + MethodInvocation(String className, String methodName, String html) {
19.13 this.className = className;
19.14 this.methodName = methodName;
19.15 + this.html = html;
19.16 }
19.17
19.18 void await(long timeOut) throws InterruptedException {
20.1 --- a/launcher/src/main/resources/org/apidesign/bck2brwsr/launcher/console.xhtml Tue Jan 22 09:19:47 2013 +0100
20.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
20.3 @@ -1,52 +0,0 @@
20.4 -<?xml version="1.0" encoding="UTF-8"?>
20.5 -<!--
20.6 -
20.7 - Back 2 Browser Bytecode Translator
20.8 - Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
20.9 -
20.10 - This program is free software: you can redistribute it and/or modify
20.11 - it under the terms of the GNU General Public License as published by
20.12 - the Free Software Foundation, version 2 of the License.
20.13 -
20.14 - This program is distributed in the hope that it will be useful,
20.15 - but WITHOUT ANY WARRANTY; without even the implied warranty of
20.16 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20.17 - GNU General Public License for more details.
20.18 -
20.19 - You should have received a copy of the GNU General Public License
20.20 - along with this program. Look for COPYING file in the top folder.
20.21 - If not, see http://opensource.org/licenses/GPL-2.0.
20.22 -
20.23 --->
20.24 -<!DOCTYPE html>
20.25 -<html xmlns="http://www.w3.org/1999/xhtml">
20.26 - <head>
20.27 - <title>Bck2Brwsr Launcher</title>
20.28 - </head>
20.29 - <body>
20.30 - <script src="/bck2brwsr.js"></script>
20.31 - <script src="/vm.js"></script>
20.32 -
20.33 - <h1>Bck2Browser Console Launcher</h1>
20.34 -
20.35 - Class Name:
20.36 - <input id="clazz" value="$0"/>
20.37 - <br/>
20.38 - Method Name:
20.39 -
20.40 - <input id="method" value="$1"/>
20.41 - <br/>
20.42 -
20.43 - <button onclick="vm.loadClass('org.apidesign.bck2brwsr.launcher.Console').execute__V();">Execute!</button>
20.44 -
20.45 - <hr/>
20.46 - <textarea id="result" rows="10" cols="80" disabled="">
20.47 - </textarea>
20.48 -
20.49 - <script type="text/javascript">
20.50 - if ($2) {
20.51 - vm.loadClass('org.apidesign.bck2brwsr.launcher.Console').execute__V();
20.52 - }
20.53 - </script>
20.54 - </body>
20.55 -</html>
21.1 --- a/launcher/src/main/resources/org/apidesign/bck2brwsr/launcher/harness.xhtml Tue Jan 22 09:19:47 2013 +0100
21.2 +++ b/launcher/src/main/resources/org/apidesign/bck2brwsr/launcher/harness.xhtml Tue Jan 22 19:27:00 2013 +0100
21.3 @@ -27,10 +27,12 @@
21.4 <script src="/bck2brwsr.js"></script>
21.5 <script src="/vm.js"></script>
21.6
21.7 - <h1>Bck2Browser Execution Harness</h1>
21.8 + <h1>Bck2Brwsr Execution Harness</h1>
21.9
21.10 - <textarea id="result" rows="25" style="width: 100%;" disabled="">
21.11 + <textarea id="bck2brwsr.result" rows="25" style="width: 100%;" disabled="">
21.12 </textarea>
21.13 +
21.14 + <div id="bck2brwsr.fragment"/>
21.15
21.16 <script type="text/javascript">
21.17 vm.loadClass('org.apidesign.bck2brwsr.launcher.Console').harness__VLjava_lang_String_2('$U/../data');
22.1 --- a/vmtest/pom.xml Tue Jan 22 09:19:47 2013 +0100
22.2 +++ b/vmtest/pom.xml Tue Jan 22 19:27:00 2013 +0100
22.3 @@ -44,13 +44,14 @@
22.4 <dependency>
22.5 <groupId>${project.groupId}</groupId>
22.6 <artifactId>vm4brwsr</artifactId>
22.7 - <version>0.3-SNAPSHOT</version>
22.8 + <version>${project.version}</version>
22.9 <type>jar</type>
22.10 </dependency>
22.11 <dependency>
22.12 <groupId>${project.groupId}</groupId>
22.13 <artifactId>emul</artifactId>
22.14 - <version>0.3-SNAPSHOT</version>
22.15 + <version>${project.version}</version>
22.16 + <scope>test</scope>
22.17 </dependency>
22.18 <dependency>
22.19 <groupId>${project.groupId}</groupId>
23.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
23.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/BrwsrTest.java Tue Jan 22 19:27:00 2013 +0100
23.3 @@ -0,0 +1,38 @@
23.4 +/**
23.5 + * Back 2 Browser Bytecode Translator
23.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
23.7 + *
23.8 + * This program is free software: you can redistribute it and/or modify
23.9 + * it under the terms of the GNU General Public License as published by
23.10 + * the Free Software Foundation, version 2 of the License.
23.11 + *
23.12 + * This program is distributed in the hope that it will be useful,
23.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23.15 + * GNU General Public License for more details.
23.16 + *
23.17 + * You should have received a copy of the GNU General Public License
23.18 + * along with this program. Look for COPYING file in the top folder.
23.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
23.20 + */
23.21 +package org.apidesign.bck2brwsr.vmtest;
23.22 +
23.23 +import java.lang.annotation.ElementType;
23.24 +import java.lang.annotation.Retention;
23.25 +import java.lang.annotation.RetentionPolicy;
23.26 +import java.lang.annotation.Target;
23.27 +
23.28 +/** Annotation to indicate that given method should be executed
23.29 + * in a browser environment. Has to be used in conjunction with {@link VMTest#create(java.lang.Class)}
23.30 + * factory method.
23.31 + * <p>
23.32 + * The browser to is by default executed via {@link java.awt.Desktop#browse(java.net.URI)},
23.33 + * but one can change that by specifying <code>-Dvmtest.brwsrs=firefox,google-chrome</code>
23.34 + * property.
23.35 + *
23.36 + * @author Jaroslav Tulach <jtulach@netbeans.org>
23.37 + */
23.38 +@Retention(RetentionPolicy.RUNTIME)
23.39 +@Target(ElementType.METHOD)
23.40 +public @interface BrwsrTest {
23.41 +}
24.1 --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/Compare.java Tue Jan 22 09:19:47 2013 +0100
24.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/Compare.java Tue Jan 22 19:27:00 2013 +0100
24.3 @@ -32,5 +32,4 @@
24.4 @Retention(RetentionPolicy.RUNTIME)
24.5 @Target(ElementType.METHOD)
24.6 public @interface Compare {
24.7 -
24.8 }
25.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
25.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/HtmlFragment.java Tue Jan 22 19:27:00 2013 +0100
25.3 @@ -0,0 +1,38 @@
25.4 +/**
25.5 + * Back 2 Browser Bytecode Translator
25.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
25.7 + *
25.8 + * This program is free software: you can redistribute it and/or modify
25.9 + * it under the terms of the GNU General Public License as published by
25.10 + * the Free Software Foundation, version 2 of the License.
25.11 + *
25.12 + * This program is distributed in the hope that it will be useful,
25.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25.15 + * GNU General Public License for more details.
25.16 + *
25.17 + * You should have received a copy of the GNU General Public License
25.18 + * along with this program. Look for COPYING file in the top folder.
25.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
25.20 + */
25.21 +package org.apidesign.bck2brwsr.vmtest;
25.22 +
25.23 +import java.lang.annotation.ElementType;
25.24 +import java.lang.annotation.Retention;
25.25 +import java.lang.annotation.RetentionPolicy;
25.26 +import java.lang.annotation.Target;
25.27 +
25.28 +/** Allows to specify an HTML fragment for a given {@link BrwsrTest}.
25.29 + * Apply either to the method or to enclosing class. The fragment will be
25.30 + * made available in the page that executes given test. Its elements shall
25.31 + * be regularly accessible from the test.
25.32 + *
25.33 + * @author Jaroslav Tulach <jtulach@netbeans.org>
25.34 + */
25.35 +@Retention(RetentionPolicy.RUNTIME)
25.36 +@Target({ ElementType.METHOD, ElementType.TYPE})
25.37 +public @interface HtmlFragment {
25.38 + /** HTML code fragment to be exposed on the testing page.
25.39 + */
25.40 + String value();
25.41 +}
26.1 --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/Bck2BrwsrCase.java Tue Jan 22 09:19:47 2013 +0100
26.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/Bck2BrwsrCase.java Tue Jan 22 19:27:00 2013 +0100
26.3 @@ -20,6 +20,7 @@
26.4 import java.io.File;
26.5 import java.io.FileWriter;
26.6 import java.io.IOException;
26.7 +import java.lang.reflect.Constructor;
26.8 import java.lang.reflect.InvocationTargetException;
26.9 import java.lang.reflect.Method;
26.10 import java.util.Map;
26.11 @@ -37,21 +38,56 @@
26.12 private final Method m;
26.13 private final Launcher l;
26.14 private final String type;
26.15 + private final boolean fail;
26.16 Object value;
26.17 - private static final Map<Class, Object[]> compiled = new WeakHashMap<>();
26.18 - private Object inst;
26.19 + private final String html;
26.20
26.21 - Bck2BrwsrCase(Method m, String type, Launcher l) {
26.22 + Bck2BrwsrCase(Method m, String type, Launcher l, boolean fail, String html) {
26.23 this.l = l;
26.24 this.m = m;
26.25 this.type = type;
26.26 + this.fail = fail;
26.27 + this.html = html;
26.28 }
26.29
26.30 @Test(groups = "run")
26.31 public void executeCode() throws Throwable {
26.32 if (l != null) {
26.33 - MethodInvocation c = l.invokeMethod(m.getDeclaringClass(), m.getName());
26.34 - value = c.toString();
26.35 + MethodInvocation c = l.invokeMethod(m.getDeclaringClass(), m.getName(), html);
26.36 + String res = c.toString();
26.37 + value = res;
26.38 + if (fail) {
26.39 + int idx = res.indexOf(':');
26.40 + if (idx >= 0) {
26.41 + Class<? extends Throwable> thrwbl = null;
26.42 + try {
26.43 + Class<?> exCls = Class.forName(res.substring(0, idx));
26.44 + if (Throwable.class.isAssignableFrom(exCls)) {
26.45 + thrwbl = exCls.asSubclass(Throwable.class);
26.46 + }
26.47 + } catch (Exception ex) {
26.48 + // ignore
26.49 + }
26.50 + if (thrwbl != null) {
26.51 + Throwable t = null;
26.52 + try {
26.53 + for (Constructor<?> cnstr : thrwbl.getConstructors()) {
26.54 + if (cnstr.getParameterTypes().length == 1 && cnstr.getParameterTypes()[0].isAssignableFrom(String.class)) {
26.55 + t = (Throwable) cnstr.newInstance(res.substring(idx + 1));
26.56 + break;
26.57 + }
26.58 + }
26.59 + } catch (Throwable ex) {
26.60 + t = thrwbl.newInstance().initCause(ex);
26.61 + }
26.62 + if (t == null) {
26.63 + t = thrwbl.newInstance().initCause(new Exception(res.substring(idx)));
26.64 + }
26.65 + throw t;
26.66 + }
26.67 + throw new AssertionError(res);
26.68 + }
26.69 + }
26.70 } else {
26.71 try {
26.72 value = m.invoke(m.getDeclaringClass().newInstance());
27.1 --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/CompareCase.java Tue Jan 22 09:19:47 2013 +0100
27.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/CompareCase.java Tue Jan 22 19:27:00 2013 +0100
27.3 @@ -18,9 +18,6 @@
27.4 package org.apidesign.bck2brwsr.vmtest.impl;
27.5
27.6 import org.apidesign.bck2brwsr.vmtest.*;
27.7 -import java.io.File;
27.8 -import java.io.FileWriter;
27.9 -import java.io.IOException;
27.10 import java.lang.reflect.Method;
27.11 import java.util.ArrayList;
27.12 import java.util.List;
27.13 @@ -74,23 +71,8 @@
27.14 }
27.15
27.16 for (Method m : arr) {
27.17 - Compare c = m.getAnnotation(Compare.class);
27.18 - if (c == null) {
27.19 - continue;
27.20 - }
27.21 - final Bck2BrwsrCase real = new Bck2BrwsrCase(m, "Java", null);
27.22 - final Bck2BrwsrCase js = new Bck2BrwsrCase(m, "JavaScript", l.javaScript());
27.23 - ret.add(real);
27.24 - ret.add(js);
27.25 - ret.add(new CompareCase(m, real, js));
27.26 -
27.27 - for (String b : brwsr) {
27.28 - final Launcher s = l.brwsr(b);
27.29 - ret.add(s);
27.30 - final Bck2BrwsrCase cse = new Bck2BrwsrCase(m, b, s);
27.31 - ret.add(cse);
27.32 - ret.add(new CompareCase(m, real, cse));
27.33 - }
27.34 + registerCompareCases(m, l, ret, brwsr);
27.35 + registerBrwsrCases(m, l, ret, brwsr);
27.36 }
27.37 return ret.toArray();
27.38 }
27.39 @@ -123,4 +105,45 @@
27.40 public String getTestName() {
27.41 return m.getName() + "[Compare " + second.typeName() + "]";
27.42 }
27.43 +
27.44 + private static void registerCompareCases(Method m, final LaunchSetup l, List<Object> ret, String[] brwsr) {
27.45 + Compare c = m.getAnnotation(Compare.class);
27.46 + if (c == null) {
27.47 + return;
27.48 + }
27.49 + final Bck2BrwsrCase real = new Bck2BrwsrCase(m, "Java", null, false, null);
27.50 + final Bck2BrwsrCase js = new Bck2BrwsrCase(m, "JavaScript", l.javaScript(), false, null);
27.51 + ret.add(real);
27.52 + ret.add(js);
27.53 + ret.add(new CompareCase(m, real, js));
27.54 + for (String b : brwsr) {
27.55 + final Launcher s = l.brwsr(b);
27.56 + ret.add(s);
27.57 + final Bck2BrwsrCase cse = new Bck2BrwsrCase(m, b, s, false, null);
27.58 + ret.add(cse);
27.59 + ret.add(new CompareCase(m, real, cse));
27.60 + }
27.61 + }
27.62 + private static void registerBrwsrCases(Method m, final LaunchSetup l, List<Object> ret, String[] brwsr) {
27.63 + BrwsrTest c = m.getAnnotation(BrwsrTest.class);
27.64 + if (c == null) {
27.65 + return;
27.66 + }
27.67 + HtmlFragment f = m.getAnnotation(HtmlFragment.class);
27.68 + if (f == null) {
27.69 + f = m.getDeclaringClass().getAnnotation(HtmlFragment.class);
27.70 + }
27.71 + String html = f == null ? null : f.value();
27.72 + if (brwsr.length == 0) {
27.73 + final Launcher s = l.brwsr(null);
27.74 + ret.add(s);
27.75 + ret.add(new Bck2BrwsrCase(m, "Brwsr", s, true, html));
27.76 + } else {
27.77 + for (String b : brwsr) {
27.78 + final Launcher s = l.brwsr(b);
27.79 + ret.add(s);
27.80 + ret.add(new Bck2BrwsrCase(m, b, s, true, html));
27.81 + }
27.82 + }
27.83 + }
27.84 }
28.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
28.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/AssertionTest.java Tue Jan 22 19:27:00 2013 +0100
28.3 @@ -0,0 +1,39 @@
28.4 +/**
28.5 + * Back 2 Browser Bytecode Translator
28.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
28.7 + *
28.8 + * This program is free software: you can redistribute it and/or modify
28.9 + * it under the terms of the GNU General Public License as published by
28.10 + * the Free Software Foundation, version 2 of the License.
28.11 + *
28.12 + * This program is distributed in the hope that it will be useful,
28.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28.15 + * GNU General Public License for more details.
28.16 + *
28.17 + * You should have received a copy of the GNU General Public License
28.18 + * along with this program. Look for COPYING file in the top folder.
28.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
28.20 + */
28.21 +package org.apidesign.bck2brwsr.tck;
28.22 +
28.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
28.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
28.25 +import org.testng.annotations.Factory;
28.26 +
28.27 +/**
28.28 + *
28.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
28.30 + */
28.31 +public class AssertionTest {
28.32 +
28.33 + @Compare public Object checkAssert() throws ClassNotFoundException {
28.34 + assert false : "Is assertion status on?";
28.35 + return null;
28.36 + }
28.37 +
28.38 + @Factory
28.39 + public static Object[] create() {
28.40 + return VMTest.create(AssertionTest.class);
28.41 + }
28.42 +}
29.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
29.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/BrwsrCheckTest.java Tue Jan 22 19:27:00 2013 +0100
29.3 @@ -0,0 +1,57 @@
29.4 +/**
29.5 + * Back 2 Browser Bytecode Translator
29.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
29.7 + *
29.8 + * This program is free software: you can redistribute it and/or modify
29.9 + * it under the terms of the GNU General Public License as published by
29.10 + * the Free Software Foundation, version 2 of the License.
29.11 + *
29.12 + * This program is distributed in the hope that it will be useful,
29.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29.15 + * GNU General Public License for more details.
29.16 + *
29.17 + * You should have received a copy of the GNU General Public License
29.18 + * along with this program. Look for COPYING file in the top folder.
29.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
29.20 + */
29.21 +package org.apidesign.bck2brwsr.tck;
29.22 +
29.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
29.24 +import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
29.25 +import org.apidesign.bck2brwsr.vmtest.HtmlFragment;
29.26 +import org.apidesign.bck2brwsr.vmtest.VMTest;
29.27 +import org.testng.annotations.Factory;
29.28 +
29.29 +/**
29.30 + *
29.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
29.32 + */
29.33 +public class BrwsrCheckTest {
29.34 +
29.35 + @BrwsrTest public void assertWindowObjectIsDefined() {
29.36 + assert window() != null : "No window object found!";
29.37 + }
29.38 +
29.39 +
29.40 +
29.41 +
29.42 + @HtmlFragment("<h1 id='hello'>\n"
29.43 + + "Hello!\n"
29.44 + + "</h1>\n")
29.45 + @BrwsrTest public void accessProvidedFragment() {
29.46 + assert getElementById("hello") != null : "Element with 'hello' ID found";
29.47 + }
29.48 +
29.49 + @Factory
29.50 + public static Object[] create() {
29.51 + return VMTest.create(BrwsrCheckTest.class);
29.52 + }
29.53 +
29.54 +
29.55 + @JavaScriptBody(args = {}, body = "return window;")
29.56 + private static native Object window();
29.57 +
29.58 + @JavaScriptBody(args = { "id" }, body = "return window.document.getElementById(id);")
29.59 + private static native Object getElementById(String id);
29.60 +}