Fixed return value for ArrayList#remove in js library.

Removed unnecessary Kotlin.IndexOutOfBounds.
This commit is contained in:
Zalim Bashorov
2013-03-26 20:31:29 +04:00
parent 7350e14e18
commit 282c69eb6b
4 changed files with 50 additions and 19 deletions
@@ -48,6 +48,10 @@ public final class ArrayListTest extends JavaClassesTest {
fooBoxTest(); fooBoxTest();
} }
public void testRemoveWithIndexOutOfBounds() throws Exception {
fooBoxTest();
}
public void testToArray() throws Exception { public void testToArray() throws Exception {
fooBoxTest(); fooBoxTest();
} }
@@ -1,17 +1,13 @@
package foo package foo
import java.util.ArrayList; import java.util.ArrayList
fun box() : Boolean { fun box() : Boolean {
var i = 0 val arr = ArrayList<Int>()
val arr = ArrayList<Int>(); for (i in 0..5) {
while (i++ < 10) { arr.add(i)
arr.add(i);
} }
arr.remove(2)
var sum = 0 val removed = arr.remove(2)
for (a in arr) { return arr.size() == 5 && removed == 2 && arr[0] == 0 && arr[1] == 1 && arr[2] == 3 && arr[3] == 4 && arr[4] == 5
sum += a;
}
return ((sum == 52) && (arr[1] == 2) && (arr[2] == 4) && (arr[3] == 5) && (arr[4] == 6) && (arr[8] == 10))
} }
@@ -0,0 +1,30 @@
package foo
import java.util.ArrayList
fun box() : Boolean {
var threwForEmptyList = false
val arr = ArrayList<Int>()
try {
arr.remove(2)
}
catch(e: IndexOutOfBoundsException) {
threwForEmptyList = true
}
for (i in 0..10) {
arr.add(i)
}
var threwForFilled = false
try {
arr.remove(20)
}
catch(e: IndexOutOfBoundsException) {
threwForFilled = true
}
return threwForEmptyList && threwForFilled
}
+9 -8
View File
@@ -75,7 +75,6 @@ var kotlin = {set:function (receiver, key, value) {
Kotlin.Exception = Kotlin.$createClass(); Kotlin.Exception = Kotlin.$createClass();
Kotlin.RuntimeException = Kotlin.$createClass(Kotlin.Exception); Kotlin.RuntimeException = Kotlin.$createClass(Kotlin.Exception);
Kotlin.IndexOutOfBounds = Kotlin.$createClass(Kotlin.Exception);
Kotlin.NullPointerException = Kotlin.$createClass(Kotlin.Exception); Kotlin.NullPointerException = Kotlin.$createClass(Kotlin.Exception);
Kotlin.NoSuchElementException = Kotlin.$createClass(Kotlin.Exception); Kotlin.NoSuchElementException = Kotlin.$createClass(Kotlin.Exception);
Kotlin.IllegalArgumentException = Kotlin.$createClass(Kotlin.Exception); Kotlin.IllegalArgumentException = Kotlin.$createClass(Kotlin.Exception);
@@ -205,15 +204,11 @@ var kotlin = {set:function (receiver, key, value) {
this.$size = 0; this.$size = 0;
}, },
get: function (index) { get: function (index) {
if (index < 0 || index >= this.$size) { this.checkRange(index);
throw Kotlin.IndexOutOfBounds;
}
return this.array[index]; return this.array[index];
}, },
set: function (index, value) { set: function (index, value) {
if (index < 0 || index >= this.$size) { this.checkRange(index);
throw Kotlin.IndexOutOfBounds;
}
this.array[index] = value; this.array[index] = value;
}, },
toArray: function () { toArray: function () {
@@ -241,8 +236,9 @@ var kotlin = {set:function (receiver, key, value) {
this.$size += collection.size(); this.$size += collection.size();
}, },
removeAt: function (index) { removeAt: function (index) {
this.array.splice(index, 1); this.checkRange(index);
this.$size--; this.$size--;
return this.array.splice(index, 1)[0];
}, },
clear: function () { clear: function () {
this.array.length = 0; this.array.length = 0;
@@ -261,6 +257,11 @@ var kotlin = {set:function (receiver, key, value) {
}, },
toJSON: function () { toJSON: function () {
return this.array; return this.array;
},
checkRange: function(index) {
if (index < 0 || index >= this.$size) {
throw new Kotlin.IndexOutOfBoundsException();
}
} }
}); });