# HG changeset patch # User Jaroslav Tulach # Date 1357200897 -3600 # Node ID 1fb46c65f030593e2011cd93e71726c613ebb059 # Parent a9be982d9b9c8ef1d8df46fa49d04450a6442db6 clone works on arrays diff -r a9be982d9b9c -r 1fb46c65f030 emul/src/main/resources/org/apidesign/vm4brwsr/emul/java_lang_String.js --- a/emul/src/main/resources/org/apidesign/vm4brwsr/emul/java_lang_String.js Mon Dec 31 17:50:27 2012 +0100 +++ b/emul/src/main/resources/org/apidesign/vm4brwsr/emul/java_lang_String.js Thu Jan 03 09:14:57 2013 +0100 @@ -6,4 +6,11 @@ for(var i = 0; i < this.length; i++) this[i] = null; return this; }; - +Array.prototype.clone__Ljava_lang_Object_2 = function() { + var s = this.length; + var ret = new Array(s); + for (var i = 0; i < s; i++) { + ret[i] = this[i]; + } + return ret; +}; diff -r a9be982d9b9c -r 1fb46c65f030 vm/src/test/java/org/apidesign/vm4brwsr/Array.java --- a/vm/src/test/java/org/apidesign/vm4brwsr/Array.java Mon Dec 31 17:50:27 2012 +0100 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/Array.java Thu Jan 03 09:14:57 2013 +0100 @@ -82,11 +82,17 @@ } return sum; } - public static int simple() { - int[] arr = { 0, 1, 2, 3, 4, 5 }; + private static final int[] arr = { 0, 1, 2, 3, 4, 5 }; + public static int simple(boolean clone) { + int[] ar; + if (clone) { + ar = arr.clone(); + } else { + ar = arr; + } int sum = 0; - for (int a : arr) { + for (int a : ar) { sum += a; } return sum; diff -r a9be982d9b9c -r 1fb46c65f030 vm/src/test/java/org/apidesign/vm4brwsr/ArrayTest.java --- a/vm/src/test/java/org/apidesign/vm4brwsr/ArrayTest.java Mon Dec 31 17:50:27 2012 +0100 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/ArrayTest.java Thu Jan 03 09:14:57 2013 +0100 @@ -18,7 +18,6 @@ package org.apidesign.vm4brwsr; import javax.script.Invocable; -import javax.script.ScriptException; import static org.testng.Assert.*; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -29,8 +28,14 @@ */ public class ArrayTest { @Test public void verifySimpleIntOperation() throws Exception { - assertExec("CheckTheSum", Array.class, "simple__I", - Double.valueOf(15) + assertExec("CheckTheSum", Array.class, "simple__IZ", + Double.valueOf(15), false + ); + } + + @Test public void cloneOnArray() throws Exception { + assertExec("CheckTheSum on clone", Array.class, "simple__IZ", + Double.valueOf(15), true ); }