Provide no-op members in JS ArrayList to work with capacity.

#KT-14637
This commit is contained in:
Ilya Gorbunov
2016-11-03 23:47:47 +03:00
parent fbcf7c146b
commit a067888fed
2 changed files with 11 additions and 0 deletions
@@ -21,6 +21,10 @@ public open class ArrayList<E> internal constructor(private var array: Array<Any
public constructor(capacity: Int = 0) : this(emptyArray()) {}
public constructor(elements: Collection<E>) : this(elements.toTypedArray<Any?>()) {}
/** Does nothing in this ArrayList implementation. */
public fun trimToSize() {}
/** Does nothing in this ArrayList implementation. */
public fun ensureCapacity(minCapacity: Int) {}
override val size: Int get() = array.size
override fun get(index: Int): E = array[rangeCheck(index)] as E
@@ -37,6 +37,13 @@ class JsCollectionsTest {
snapshotDoesNotCreateView(arrayOf<Any>("first", "last"), { arrayListOf(*it) })
}
@test fun arrayListCapacity() {
val list = ArrayList<Any>(20)
list.ensureCapacity(100)
list.trimToSize()
assertTrue(list.isEmpty())
}
@test fun listEqualsOperatesOnAny() {
assertFalse(listOf(1, 2, 3).equals(object {}))
}