1.1 --- a/emul/src/main/java/java/lang/AbstractStringBuilder.java Thu Oct 11 10:43:17 2012 -0700
1.2 +++ b/emul/src/main/java/java/lang/AbstractStringBuilder.java Tue Oct 16 11:55:56 2012 +0200
1.3 @@ -126,7 +126,7 @@
1.4 throw new OutOfMemoryError();
1.5 newCapacity = Integer.MAX_VALUE;
1.6 }
1.7 - value = String.copyOf(value, newCapacity);
1.8 + value = copyOf(value, newCapacity);
1.9 }
1.10
1.11 /**
1.12 @@ -138,7 +138,7 @@
1.13 */
1.14 public void trimToSize() {
1.15 if (count < value.length) {
1.16 - value = String.copyOf(value, count);
1.17 + value = copyOf(value, count);
1.18 }
1.19 }
1.20
1.21 @@ -352,7 +352,7 @@
1.22 throw new StringIndexOutOfBoundsException(srcEnd);
1.23 if (srcBegin > srcEnd)
1.24 throw new StringIndexOutOfBoundsException("srcBegin > srcEnd");
1.25 - String.arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin);
1.26 + arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin);
1.27 }
1.28
1.29 /**
1.30 @@ -502,7 +502,7 @@
1.31 public AbstractStringBuilder append(char[] str) {
1.32 int len = str.length;
1.33 ensureCapacityInternal(count + len);
1.34 - String.arraycopy(str, 0, value, count, len);
1.35 + arraycopy(str, 0, value, count, len);
1.36 count += len;
1.37 return this;
1.38 }
1.39 @@ -532,7 +532,7 @@
1.40 public AbstractStringBuilder append(char str[], int offset, int len) {
1.41 if (len > 0) // let arraycopy report AIOOBE for len < 0
1.42 ensureCapacityInternal(count + len);
1.43 - String.arraycopy(str, offset, value, count, len);
1.44 + arraycopy(str, offset, value, count, len);
1.45 count += len;
1.46 return this;
1.47 }
1.48 @@ -699,7 +699,7 @@
1.49 throw new StringIndexOutOfBoundsException();
1.50 int len = end - start;
1.51 if (len > 0) {
1.52 - String.arraycopy(value, start+len, value, start, count-end);
1.53 + arraycopy(value, start+len, value, start, count-end);
1.54 count -= len;
1.55 }
1.56 return this;
1.57 @@ -761,7 +761,7 @@
1.58 public AbstractStringBuilder deleteCharAt(int index) {
1.59 if ((index < 0) || (index >= count))
1.60 throw new StringIndexOutOfBoundsException(index);
1.61 - String.arraycopy(value, index+1, value, index, count-index-1);
1.62 + arraycopy(value, index+1, value, index, count-index-1);
1.63 count--;
1.64 return this;
1.65 }
1.66 @@ -799,7 +799,7 @@
1.67 int newCount = count + len - (end - start);
1.68 ensureCapacityInternal(newCount);
1.69
1.70 - String.arraycopy(value, end, value, start + len, count - end);
1.71 + arraycopy(value, end, value, start + len, count - end);
1.72 str.getChars(value, start);
1.73 count = newCount;
1.74 return this;
1.75 @@ -905,8 +905,8 @@
1.76 "offset " + offset + ", len " + len + ", str.length "
1.77 + str.length);
1.78 ensureCapacityInternal(count + len);
1.79 - String.arraycopy(value, index, value, index + len, count - index);
1.80 - String.arraycopy(str, offset, value, index, len);
1.81 + arraycopy(value, index, value, index + len, count - index);
1.82 + arraycopy(str, offset, value, index, len);
1.83 count += len;
1.84 return this;
1.85 }
1.86 @@ -972,7 +972,7 @@
1.87 str = "null";
1.88 int len = str.length();
1.89 ensureCapacityInternal(count + len);
1.90 - String.arraycopy(value, offset, value, offset + len, count - offset);
1.91 + arraycopy(value, offset, value, offset + len, count - offset);
1.92 str.getChars(value, offset);
1.93 count += len;
1.94 return this;
1.95 @@ -1007,8 +1007,8 @@
1.96 throw new StringIndexOutOfBoundsException(offset);
1.97 int len = str.length;
1.98 ensureCapacityInternal(count + len);
1.99 - String.arraycopy(value, offset, value, offset + len, count - offset);
1.100 - String.arraycopy(str, 0, value, offset, len);
1.101 + arraycopy(value, offset, value, offset + len, count - offset);
1.102 + arraycopy(str, 0, value, offset, len);
1.103 count += len;
1.104 return this;
1.105 }
1.106 @@ -1098,7 +1098,7 @@
1.107 + s.length());
1.108 int len = end - start;
1.109 ensureCapacityInternal(count + len);
1.110 - String.arraycopy(value, dstOffset, value, dstOffset + len,
1.111 + arraycopy(value, dstOffset, value, dstOffset + len,
1.112 count - dstOffset);
1.113 for (int i=start; i<end; i++)
1.114 value[dstOffset++] = s.charAt(i);
1.115 @@ -1150,7 +1150,7 @@
1.116 */
1.117 public AbstractStringBuilder insert(int offset, char c) {
1.118 ensureCapacityInternal(count + 1);
1.119 - String.arraycopy(value, offset, value, offset + 1, count - offset);
1.120 + arraycopy(value, offset, value, offset + 1, count - offset);
1.121 value[offset] = c;
1.122 count += 1;
1.123 return this;
1.124 @@ -1405,4 +1405,31 @@
1.125 return value;
1.126 }
1.127
1.128 + static char[] copyOfRange(char[] original, int from, int to) {
1.129 + int newLength = to - from;
1.130 + if (newLength < 0) {
1.131 + throw new IllegalArgumentException(from + " > " + to);
1.132 + }
1.133 + char[] copy = new char[newLength];
1.134 + arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength));
1.135 + return copy;
1.136 + }
1.137 +
1.138 + static void arraycopy(char[] value, int srcBegin, char[] dst, int dstBegin, int count) {
1.139 + while (count-- > 0) {
1.140 + dst[dstBegin++] = value[srcBegin++];
1.141 + }
1.142 + }
1.143 +
1.144 + // access system property
1.145 + static String getProperty(String nm) {
1.146 + return null;
1.147 + }
1.148 +
1.149 + static char[] copyOf(char[] original, int newLength) {
1.150 + char[] copy = new char[newLength];
1.151 + arraycopy(original, 0, copy, 0, Math.min(original.length, newLength));
1.152 + return copy;
1.153 + }
1.154 +
1.155 }
2.1 --- a/emul/src/main/java/java/lang/Boolean.java Thu Oct 11 10:43:17 2012 -0700
2.2 +++ b/emul/src/main/java/java/lang/Boolean.java Tue Oct 16 11:55:56 2012 +0200
2.3 @@ -235,7 +235,7 @@
2.4 public static boolean getBoolean(String name) {
2.5 boolean result = false;
2.6 try {
2.7 - result = toBoolean(String.getProperty(name));
2.8 + result = toBoolean(AbstractStringBuilder.getProperty(name));
2.9 } catch (IllegalArgumentException e) {
2.10 } catch (NullPointerException e) {
2.11 }
3.1 --- a/emul/src/main/java/java/lang/Integer.java Thu Oct 11 10:43:17 2012 -0700
3.2 +++ b/emul/src/main/java/java/lang/Integer.java Tue Oct 16 11:55:56 2012 +0200
3.3 @@ -600,7 +600,7 @@
3.4 // high value may be configured by property
3.5 int h = 127;
3.6 String integerCacheHighPropValue =
3.7 - String.getProperty("java.lang.Integer.IntegerCache.high");
3.8 + AbstractStringBuilder.getProperty("java.lang.Integer.IntegerCache.high");
3.9 if (integerCacheHighPropValue != null) {
3.10 int i = parseInt(integerCacheHighPropValue);
3.11 i = Math.max(i, 127);
3.12 @@ -882,7 +882,7 @@
3.13 public static Integer getInteger(String nm, Integer val) {
3.14 String v = null;
3.15 try {
3.16 - v = String.getProperty(nm);
3.17 + v = AbstractStringBuilder.getProperty(nm);
3.18 } catch (IllegalArgumentException e) {
3.19 } catch (NullPointerException e) {
3.20 }
4.1 --- a/emul/src/main/java/java/lang/Long.java Thu Oct 11 10:43:17 2012 -0700
4.2 +++ b/emul/src/main/java/java/lang/Long.java Tue Oct 16 11:55:56 2012 +0200
4.3 @@ -923,7 +923,7 @@
4.4 public static Long getLong(String nm, Long val) {
4.5 String v = null;
4.6 try {
4.7 - v = String.getProperty(nm);
4.8 + v = AbstractStringBuilder.getProperty(nm);
4.9 } catch (IllegalArgumentException e) {
4.10 } catch (NullPointerException e) {
4.11 }
5.1 --- a/emul/src/main/java/java/lang/Math.java Thu Oct 11 10:43:17 2012 -0700
5.2 +++ b/emul/src/main/java/java/lang/Math.java Tue Oct 16 11:55:56 2012 +0200
5.3 @@ -25,6 +25,8 @@
5.4
5.5 package java.lang;
5.6
5.7 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
5.8 +
5.9
5.10 /**
5.11 * The class {@code Math} contains methods for performing basic
5.12 @@ -813,9 +815,6 @@
5.13 return (a >= b) ? a : b;
5.14 }
5.15
5.16 - private static long negativeZeroFloatBits = Float.floatToIntBits(-0.0f);
5.17 - private static long negativeZeroDoubleBits = Double.doubleToLongBits(-0.0d);
5.18 -
5.19 /**
5.20 * Returns the greater of two {@code float} values. That is,
5.21 * the result is the argument closer to positive infinity. If the
5.22 @@ -830,13 +829,11 @@
5.23 * @param b another argument.
5.24 * @return the larger of {@code a} and {@code b}.
5.25 */
5.26 + @JavaScriptBody(args={"a", "b"},
5.27 + body="return Math.max(a,b);"
5.28 + )
5.29 public static float max(float a, float b) {
5.30 - if (a != a) return a; // a is NaN
5.31 - if ((a == 0.0f) && (b == 0.0f)
5.32 - && (Float.floatToIntBits(a) == negativeZeroFloatBits)) {
5.33 - return b;
5.34 - }
5.35 - return (a >= b) ? a : b;
5.36 + throw new UnsupportedOperationException();
5.37 }
5.38
5.39 /**
5.40 @@ -853,13 +850,11 @@
5.41 * @param b another argument.
5.42 * @return the larger of {@code a} and {@code b}.
5.43 */
5.44 + @JavaScriptBody(args={"a", "b"},
5.45 + body="return Math.max(a,b);"
5.46 + )
5.47 public static double max(double a, double b) {
5.48 - if (a != a) return a; // a is NaN
5.49 - if ((a == 0.0d) && (b == 0.0d)
5.50 - && (Double.doubleToLongBits(a) == negativeZeroDoubleBits)) {
5.51 - return b;
5.52 - }
5.53 - return (a >= b) ? a : b;
5.54 + throw new UnsupportedOperationException();
5.55 }
5.56
5.57 /**
5.58 @@ -904,13 +899,11 @@
5.59 * @param b another argument.
5.60 * @return the smaller of {@code a} and {@code b}.
5.61 */
5.62 + @JavaScriptBody(args={"a", "b"},
5.63 + body="return Math.min(a,b);"
5.64 + )
5.65 public static float min(float a, float b) {
5.66 - if (a != a) return a; // a is NaN
5.67 - if ((a == 0.0f) && (b == 0.0f)
5.68 - && (Float.floatToIntBits(b) == negativeZeroFloatBits)) {
5.69 - return b;
5.70 - }
5.71 - return (a <= b) ? a : b;
5.72 + throw new UnsupportedOperationException();
5.73 }
5.74
5.75 /**
5.76 @@ -927,13 +920,11 @@
5.77 * @param b another argument.
5.78 * @return the smaller of {@code a} and {@code b}.
5.79 */
5.80 + @JavaScriptBody(args={"a", "b"},
5.81 + body="return Math.min(a,b);"
5.82 + )
5.83 public static double min(double a, double b) {
5.84 - if (a != a) return a; // a is NaN
5.85 - if ((a == 0.0d) && (b == 0.0d)
5.86 - && (Double.doubleToLongBits(b) == negativeZeroDoubleBits)) {
5.87 - return b;
5.88 - }
5.89 - return (a <= b) ? a : b;
5.90 + throw new UnsupportedOperationException();
5.91 }
5.92
5.93 /**
6.1 --- a/emul/src/main/java/java/lang/String.java Thu Oct 11 10:43:17 2012 -0700
6.2 +++ b/emul/src/main/java/java/lang/String.java Tue Oct 16 11:55:56 2012 +0200
6.3 @@ -164,7 +164,7 @@
6.4 // String itself. Perhaps this constructor is being called
6.5 // in order to trim the baggage, so make a copy of the array.
6.6 int off = original.offset;
6.7 - v = copyOfRange(originalValue, off, off+size);
6.8 + v = AbstractStringBuilder.copyOfRange(originalValue, off, off+size);
6.9 } else {
6.10 // The array representing the String is the same
6.11 // size as the String, so no point in making a copy.
6.12 @@ -188,7 +188,7 @@
6.13 int size = value.length;
6.14 this.offset = 0;
6.15 this.count = size;
6.16 - this.value = copyOf(value, size);
6.17 + this.value = AbstractStringBuilder.copyOf(value, size);
6.18 }
6.19
6.20 /**
6.21 @@ -225,7 +225,7 @@
6.22 }
6.23 this.offset = 0;
6.24 this.count = count;
6.25 - this.value = copyOfRange(value, offset, offset+count);
6.26 + this.value = AbstractStringBuilder.copyOfRange(value, offset, offset+count);
6.27 }
6.28
6.29 /**
6.30 @@ -818,7 +818,7 @@
6.31 * This method doesn't perform any range checking.
6.32 */
6.33 void getChars(char dst[], int dstBegin) {
6.34 - arraycopy(value, offset, dst, dstBegin, count);
6.35 + AbstractStringBuilder.arraycopy(value, offset, dst, dstBegin, count);
6.36 }
6.37
6.38 /**
6.39 @@ -861,7 +861,7 @@
6.40 if (srcBegin > srcEnd) {
6.41 throw new StringIndexOutOfBoundsException(srcEnd - srcBegin);
6.42 }
6.43 - arraycopy(value, offset + srcBegin, dst, dstBegin,
6.44 + AbstractStringBuilder.arraycopy(value, offset + srcBegin, dst, dstBegin,
6.45 srcEnd - srcBegin);
6.46 }
6.47
6.48 @@ -3034,32 +3034,4 @@
6.49 * guaranteed to be from a pool of unique strings.
6.50 */
6.51 public native String intern();
6.52 -
6.53 - static char[] copyOfRange(char[] original, int from, int to) {
6.54 - int newLength = to - from;
6.55 - if (newLength < 0) {
6.56 - throw new IllegalArgumentException(from + " > " + to);
6.57 - }
6.58 - char[] copy = new char[newLength];
6.59 - arraycopy(original, from, copy, 0,
6.60 - Math.min(original.length - from, newLength));
6.61 - return copy;
6.62 - }
6.63 - static char[] copyOf(char[] original, int newLength) {
6.64 - char[] copy = new char[newLength];
6.65 - arraycopy(original, 0, copy, 0,
6.66 - Math.min(original.length, newLength));
6.67 - return copy;
6.68 - }
6.69 - static void arraycopy(
6.70 - char[] value, int srcBegin, char[] dst, int dstBegin, int count
6.71 - ) {
6.72 - while (count-- > 0) {
6.73 - dst[dstBegin++] = value[srcBegin++];
6.74 - }
6.75 - }
6.76 - // access system property
6.77 - static String getProperty(String nm) {
6.78 - return null;
6.79 - }
6.80 }
7.1 --- a/htmlpage/src/test/java/org/apidesign/bck2brwsr/htmlpage/PageController.java Thu Oct 11 10:43:17 2012 -0700
7.2 +++ b/htmlpage/src/test/java/org/apidesign/bck2brwsr/htmlpage/PageController.java Tue Oct 16 11:55:56 2012 +0200
7.3 @@ -27,6 +27,6 @@
7.4 public class PageController {
7.5 @OnClick(id="pg.button")
7.6 static void updateTitle() {
7.7 - TestPage.PG_TITLE.setText(TestPage.PG_TEXT.getValue());
7.8 + TestPage.PG_TITLE.setText("You want this window to be named " + TestPage.PG_TEXT.getValue());
7.9 }
7.10 }
8.1 --- a/htmlpage/src/test/java/org/apidesign/bck2brwsr/htmlpage/ProcessPageTest.java Thu Oct 11 10:43:17 2012 -0700
8.2 +++ b/htmlpage/src/test/java/org/apidesign/bck2brwsr/htmlpage/ProcessPageTest.java Tue Oct 16 11:55:56 2012 +0200
8.3 @@ -79,7 +79,7 @@
8.4 } catch (NoSuchMethodException ex) {
8.5 fail("Cannot find method in " + sb, ex);
8.6 }
8.7 - assertEquals(ret, "something", "We expect that the JavaCode performs all the wiring");
8.8 + assertEquals(ret, "You want this window to be named something", "We expect that the JavaCode performs all the wiring");
8.9 }
8.10
8.11 static Invocable compileClass(StringBuilder sb, String... names) throws ScriptException, IOException {
9.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Thu Oct 11 10:43:17 2012 -0700
9.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Tue Oct 16 11:55:56 2012 +0200
9.3 @@ -370,7 +370,7 @@
9.4 break;
9.5 case bc_iinc: {
9.6 final int varIndx = (byteCodes[++i] + 256) % 256;
9.7 - final int incrBy = (byteCodes[++i] + 256) % 256;
9.8 + final int incrBy = byteCodes[++i];
9.9 if (incrBy == 1) {
9.10 out.append("arg" + varIndx).append("++;");
9.11 } else {
9.12 @@ -465,6 +465,12 @@
9.13 out.append("{ var delta = stack.pop() - stack.pop(); stack.push(delta < 0 ?-1 : (delta == 0 ? 0 : 1)); }");
9.14 break;
9.15 }
9.16 + case bc_if_acmpeq:
9.17 + i = generateIf(byteCodes, i, "===");
9.18 + break;
9.19 + case bc_if_acmpne:
9.20 + i = generateIf(byteCodes, i, "!=");
9.21 + break;
9.22 case bc_if_icmpeq: {
9.23 i = generateIf(byteCodes, i, "==");
9.24 break;
9.25 @@ -676,6 +682,13 @@
9.26 i += 2;
9.27 break;
9.28 }
9.29 + case bc_athrow: {
9.30 + out.append("{ var t = stack.pop(); stack = new Array(1); stack[0] = t; throw t; }");
9.31 + break;
9.32 + }
9.33 + default: {
9.34 + out.append("throw 'unknown bytecode " + c + "';");
9.35 + }
9.36
9.37 }
9.38 out.append(" //");
10.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/GenJS.java Thu Oct 11 10:43:17 2012 -0700
10.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/GenJS.java Tue Oct 16 11:55:56 2012 +0200
10.3 @@ -58,8 +58,11 @@
10.4 if (name.startsWith("java/")
10.5 && !name.equals("java/lang/Object")
10.6 && !name.equals("java/lang/Class")
10.7 + && !name.equals("java/lang/Math")
10.8 && !name.equals("java/lang/Number")
10.9 && !name.equals("java/lang/Integer")
10.10 + && !name.equals("java/lang/Float")
10.11 + && !name.equals("java/lang/Double")
10.12 && !name.equals("java/lang/Throwable")
10.13 && !name.equals("java/lang/Exception")
10.14 && !name.equals("java/lang/RuntimeException")
10.15 @@ -116,7 +119,6 @@
10.16 }
10.17 }
10.18 }
10.19 -
10.20 }
10.21 private static void readResource(InputStream emul, Appendable out) throws IOException {
10.22 try {
11.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/Array.java Thu Oct 11 10:43:17 2012 -0700
11.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/Array.java Tue Oct 16 11:55:56 2012 +0200
11.3 @@ -80,4 +80,16 @@
11.4 }
11.5 return sum;
11.6 }
11.7 +
11.8 + static void arraycopy(char[] value, int srcBegin, char[] dst, int dstBegin, int count) {
11.9 + while (count-- > 0) {
11.10 + dst[dstBegin++] = value[srcBegin++];
11.11 + }
11.12 + }
11.13 +
11.14 + public static char copyArray() {
11.15 + char[] arr = { '0' };
11.16 + arraycopy(arr()[0].chars, 0, arr, 0, 1);
11.17 + return arr[0];
11.18 + }
11.19 }
12.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/ArrayTest.java Thu Oct 11 10:43:17 2012 -0700
12.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/ArrayTest.java Tue Oct 16 11:55:56 2012 +0200
12.3 @@ -39,6 +39,10 @@
12.4 );
12.5 }
12.6
12.7 + @Test public void doesCopyArrayWork() throws Exception {
12.8 + assertExec("Returns 'a'", "org_apidesign_vm4brwsr_Array_copyArrayC", Double.valueOf('a'));
12.9 + }
12.10 +
12.11 private static CharSequence codeSeq;
12.12 private static Invocable code;
12.13
13.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StringSample.java Thu Oct 11 10:43:17 2012 -0700
13.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StringSample.java Tue Oct 16 11:55:56 2012 +0200
13.3 @@ -24,12 +24,17 @@
13.4 }
13.5
13.6 public static String toStringTest(int howMuch) {
13.7 + counter = 0;
13.8 StringSample ss = null;
13.9 for (int i = 0; i < howMuch; i++) {
13.10 ss = new StringSample();
13.11 }
13.12 return ss.toString().toString();
13.13 }
13.14 +
13.15 + public static String concatStrings() {
13.16 + return (toStringTest(1) + "Ahoj").toString();
13.17 + }
13.18
13.19 @Override
13.20 public String toString() {
14.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StringTest.java Thu Oct 11 10:43:17 2012 -0700
14.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StringTest.java Tue Oct 16 11:55:56 2012 +0200
14.3 @@ -37,6 +37,15 @@
14.4 @Test public void toStringConcatenationJava() throws Exception {
14.5 assertEquals("Hello World!5", StringSample.toStringTest(5));
14.6 }
14.7 +
14.8 + @Test(timeOut=10000) public void stringStringConcat() throws Exception {
14.9 + assertExec(
14.10 + "Composes strings OK",
14.11 + "org_apidesign_vm4brwsr_StringSample_concatStringsLjava_lang_String",
14.12 + "Hello World!1Ahoj"
14.13 + );
14.14 + }
14.15 +
14.16 private static CharSequence codeSeq;
14.17 private static Invocable code;
14.18