Ensure vararg copy behavior for specific case of arrayListOf in JS.

This commit is contained in:
Ilya Gorbunov
2015-10-16 05:12:43 +03:00
parent 446cdc087d
commit 59f88cfb52
4 changed files with 39 additions and 9 deletions
+10 -5
View File
@@ -16,13 +16,18 @@
package java.util
public fun HashSet<E>(c: Collection<E>): HashSet<E> = HashSet<E>(c.size()).apply { addAll(c) }
public fun HashSet<E>(c: Collection<E>): HashSet<E>
= HashSet<E>(c.size()).apply { addAll(c) }
public fun LinkedHashSet<E>(c: Collection<E>): HashSet<E> = LinkedHashSet<E>(c.size()).apply { addAll(c) }
public fun LinkedHashSet<E>(c: Collection<E>): HashSet<E>
= LinkedHashSet<E>(c.size()).apply { addAll(c) }
public fun HashMap<K, V>(m: Map<K, V>): HashMap<K, V> = HashMap<K, V>(m.size()).apply { putAll(m) }
public fun HashMap<K, V>(m: Map<K, V>): HashMap<K, V>
= HashMap<K, V>(m.size()).apply { putAll(m) }
public fun LinkedHashMap<K, V>(m: Map<K, V>): LinkedHashMap<K, V> = LinkedHashMap<K, V>(m.size()).apply { putAll(m) }
public fun LinkedHashMap<K, V>(m: Map<K, V>): LinkedHashMap<K, V>
= LinkedHashMap<K, V>(m.size()).apply { putAll(m) }
public fun ArrayList<E>(c: Collection<E>): ArrayList<E> = ArrayList<E>().apply { asDynamic().array = c.toTypedArray<Any?>() } // black dynamic magic
public fun ArrayList<E>(c: Collection<E>): ArrayList<E>
= ArrayList<E>().apply { asDynamic().array = c.toTypedArray<Any?>() } // black dynamic magic
+4
View File
@@ -91,3 +91,7 @@ internal fun <T> arrayPlusCollection(array: dynamic, collection: Collection<T>):
for (element in collection) result[index++] = element
return result
}
// copies vararg array due to different spread vararg behavior in JS.
// After fixing #KT-6491 may return `this`
internal inline fun <T> Array<out T>.varargToArrayOfAny(): Array<out Any?> = this.copyOf()