Fixed return value for ArrayList#remove in js library.
Removed unnecessary Kotlin.IndexOutOfBounds.
This commit is contained in:
@@ -48,6 +48,10 @@ public final class ArrayListTest extends JavaClassesTest {
|
||||
fooBoxTest();
|
||||
}
|
||||
|
||||
public void testRemoveWithIndexOutOfBounds() throws Exception {
|
||||
fooBoxTest();
|
||||
}
|
||||
|
||||
public void testToArray() throws Exception {
|
||||
fooBoxTest();
|
||||
}
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
package foo
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.ArrayList
|
||||
|
||||
fun box() : Boolean {
|
||||
var i = 0
|
||||
val arr = ArrayList<Int>();
|
||||
while (i++ < 10) {
|
||||
arr.add(i);
|
||||
val arr = ArrayList<Int>()
|
||||
for (i in 0..5) {
|
||||
arr.add(i)
|
||||
}
|
||||
arr.remove(2)
|
||||
var sum = 0
|
||||
for (a in arr) {
|
||||
sum += a;
|
||||
}
|
||||
return ((sum == 52) && (arr[1] == 2) && (arr[2] == 4) && (arr[3] == 5) && (arr[4] == 6) && (arr[8] == 10))
|
||||
|
||||
val removed = arr.remove(2)
|
||||
return arr.size() == 5 && removed == 2 && arr[0] == 0 && arr[1] == 1 && arr[2] == 3 && arr[3] == 4 && arr[4] == 5
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -75,7 +75,6 @@ var kotlin = {set:function (receiver, key, value) {
|
||||
|
||||
Kotlin.Exception = Kotlin.$createClass();
|
||||
Kotlin.RuntimeException = Kotlin.$createClass(Kotlin.Exception);
|
||||
Kotlin.IndexOutOfBounds = Kotlin.$createClass(Kotlin.Exception);
|
||||
Kotlin.NullPointerException = Kotlin.$createClass(Kotlin.Exception);
|
||||
Kotlin.NoSuchElementException = Kotlin.$createClass(Kotlin.Exception);
|
||||
Kotlin.IllegalArgumentException = Kotlin.$createClass(Kotlin.Exception);
|
||||
@@ -205,15 +204,11 @@ var kotlin = {set:function (receiver, key, value) {
|
||||
this.$size = 0;
|
||||
},
|
||||
get: function (index) {
|
||||
if (index < 0 || index >= this.$size) {
|
||||
throw Kotlin.IndexOutOfBounds;
|
||||
}
|
||||
this.checkRange(index);
|
||||
return this.array[index];
|
||||
},
|
||||
set: function (index, value) {
|
||||
if (index < 0 || index >= this.$size) {
|
||||
throw Kotlin.IndexOutOfBounds;
|
||||
}
|
||||
this.checkRange(index);
|
||||
this.array[index] = value;
|
||||
},
|
||||
toArray: function () {
|
||||
@@ -241,8 +236,9 @@ var kotlin = {set:function (receiver, key, value) {
|
||||
this.$size += collection.size();
|
||||
},
|
||||
removeAt: function (index) {
|
||||
this.array.splice(index, 1);
|
||||
this.checkRange(index);
|
||||
this.$size--;
|
||||
return this.array.splice(index, 1)[0];
|
||||
},
|
||||
clear: function () {
|
||||
this.array.length = 0;
|
||||
@@ -261,6 +257,11 @@ var kotlin = {set:function (receiver, key, value) {
|
||||
},
|
||||
toJSON: function () {
|
||||
return this.array;
|
||||
},
|
||||
checkRange: function(index) {
|
||||
if (index < 0 || index >= this.$size) {
|
||||
throw new Kotlin.IndexOutOfBoundsException();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user