Added copyToArray intrinsic method.
#KT-3352 fixed
This commit is contained in:
@@ -24,3 +24,5 @@ public fun byteArray(vararg content : Byte): ByteArray = js.noImpl
|
||||
|
||||
public fun booleanArray(vararg content : Boolean): BooleanArray = js.noImpl
|
||||
|
||||
library("copyToArray")
|
||||
public fun <reified T> Collection<T>.copyToArray(): Array<T> = js.noImpl
|
||||
|
||||
@@ -47,7 +47,7 @@ fun box(): Boolean {
|
||||
a.clear()
|
||||
assertThat(a.isEmpty(), true)
|
||||
|
||||
val array = list.toArray(Array<Int>(0, {it}))
|
||||
val array = list.copyToArray()
|
||||
|
||||
assertThat(array[0], 1)
|
||||
assertThat(array[1], 500)
|
||||
|
||||
@@ -12,6 +12,6 @@ fun box(): Boolean {
|
||||
// test addAt
|
||||
list.add(1, 500)
|
||||
|
||||
val array = list.toArray()
|
||||
val array = list.copyToArray()
|
||||
return array[0] == 1 && array[1] == 500 && array[2] == 2 && array[3] == 3 && JSON.stringify(list) == "[1,500,2,3]";
|
||||
}
|
||||
@@ -492,6 +492,16 @@ String.prototype.contains = function (s) {
|
||||
}
|
||||
};
|
||||
|
||||
Kotlin.copyToArray = function (collection) {
|
||||
var array = [];
|
||||
var it = collection.iterator();
|
||||
while (it.hasNext()) {
|
||||
array.push(it.next());
|
||||
}
|
||||
|
||||
return array;
|
||||
};
|
||||
|
||||
|
||||
Kotlin.StringBuilder = Kotlin.createClass(null,
|
||||
function () {
|
||||
|
||||
Reference in New Issue
Block a user