Introduce RandomAccess to JS.

Make EmptyList support RandomAccess.
#KT-10794
This commit is contained in:
Ilya Gorbunov
2016-02-10 21:23:35 +03:00
parent 6ba98f7fe6
commit ab68b49a70
4 changed files with 15 additions and 3 deletions
+4 -1
View File
@@ -31,6 +31,9 @@ public inline fun <T> Comparator(crossinline comparison: (T, T) -> Int): Compara
override fun compare(obj1: T, obj2: T): Int = comparison(obj1, obj2)
}
@library
public interface RandomAccess
@library
public abstract class AbstractCollection<E>() : MutableCollection<E> {
override fun isEmpty(): Boolean = noImpl
@@ -79,7 +82,7 @@ public abstract class AbstractList<E>() : AbstractCollection<E>(), MutableList<E
}
@library
public open class ArrayList<E>(capacity: Int = 0) : AbstractList<E>() {
public open class ArrayList<E>(capacity: Int = 0) : AbstractList<E>(), RandomAccess {
override fun get(index: Int): E = noImpl
override val size: Int get() = noImpl
}
+3 -1
View File
@@ -350,6 +350,8 @@
}
);
Kotlin.RandomAccess = Kotlin.createTraitNow(null);
Kotlin.PropertyMetadata = Kotlin.createClassNow(null,
function (name) {
this.name = name;
@@ -566,7 +568,7 @@
//TODO: should be JS Array-like (https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Predefined_Core_Objects#Working_with_Array-like_objects)
lazyInitClasses.ArrayList = Kotlin.createClass(
function () {
return [Kotlin.AbstractList];
return [Kotlin.AbstractList, Kotlin.RandomAccess];
},
function () {
this.array = [];