1.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Tue Jan 15 11:53:07 2013 +0100
1.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Tue Jan 15 12:26:19 2013 +0100
1.3 @@ -19,6 +19,7 @@
1.4
1.5 import java.io.IOException;
1.6 import java.io.InputStream;
1.7 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
1.8 import org.apidesign.javap.AnnotationParser;
1.9 import org.apidesign.javap.ClassData;
1.10 import org.apidesign.javap.FieldData;
1.11 @@ -957,7 +958,8 @@
1.12 append(".length; i" + d).append("++) {");
1.13 out.append("\n var a" + d).
1.14 append (" = new Array(l" + d).append(").initWith('")
1.15 - .append(typeName).append("', null);");
1.16 + .append(typeName).append("', ")
1.17 + .append(typeName.length() == 2 ? "0" : "null").append(");");
1.18 out.append("\n a" + (d - 1)).append("[i" + d).append("] = a" + d).
1.19 append(";");
1.20 }
2.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/Array.java Tue Jan 15 11:53:07 2013 +0100
2.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/Array.java Tue Jan 15 12:26:19 2013 +0100
2.3 @@ -51,6 +51,16 @@
2.4 return doubles[4][0];
2.5 }
2.6
2.7 + static double[][] dbls = new double[1][2];
2.8 + public static double twoDoubles() {
2.9 + return dbls[0][0] + dbls[0][0];
2.10 + }
2.11 +
2.12 + static int[][] tints = new int[1][2];
2.13 + public static int twoInts() {
2.14 + return tints[0][0] + tints[0][0];
2.15 + }
2.16 +
2.17 private static final Array[] ARR = { new Array(), new Array(), new Array() };
2.18
2.19 private static Array[][] arr() {
3.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/ArrayTest.java Tue Jan 15 11:53:07 2013 +0100
3.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/ArrayTest.java Tue Jan 15 12:26:19 2013 +0100
3.3 @@ -53,6 +53,17 @@
3.4 Double.valueOf(105)
3.5 );
3.6 }
3.7 +
3.8 + @Test public void twoDoubles() throws Exception {
3.9 + assertExec("Elements are initialized", Array.class, "twoDoubles__D",
3.10 + Double.valueOf(0)
3.11 + );
3.12 + }
3.13 + @Test public void twoInts() throws Exception {
3.14 + assertExec("Elements are initialized", Array.class, "twoInts__I",
3.15 + Double.valueOf(0)
3.16 + );
3.17 + }
3.18
3.19 @Test public void doesCopyArrayWork() throws Exception {
3.20 assertExec("Returns 'a'", Array.class, "copyArray__C", Double.valueOf('a'));
4.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/IntegerArithmeticTest.java Tue Jan 15 11:53:07 2013 +0100
4.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/IntegerArithmeticTest.java Tue Jan 15 12:26:19 2013 +0100
4.3 @@ -93,21 +93,12 @@
4.4
4.5 @Compare public int sumTwoDimensions() {
4.6 int[][] matrix = createMatrix(4, 3);
4.7 - int sum = 0;
4.8 - for (int i = 0; i < matrix.length; i++) {
4.9 - for (int j = 0; j < matrix[i].length; j++) {
4.10 - sum += matrix[i][j];
4.11 - }
4.12 - }
4.13 - return sum;
4.14 + matrix[0][0] += 10;
4.15 + return matrix[0][0];
4.16 }
4.17
4.18 static int[][] createMatrix(int x, int y) {
4.19 - int[][] m = new int[x][y];
4.20 - for (int i = 0; i < Math.min(x, y); i++) {
4.21 - m[i][i] = i;
4.22 - }
4.23 - return m;
4.24 + return new int[x][y];
4.25 }
4.26
4.27 @Factory