Fix JS Map.keys.remove return value #KT-65525
This commit is contained in:
committed by
Space Team
parent
20b9ac9d55
commit
600e306d80
@@ -20,7 +20,7 @@ internal class HashMapKeys<E> internal constructor(
|
||||
override fun clear() = backing.clear()
|
||||
override fun add(element: E): Boolean = throw UnsupportedOperationException()
|
||||
override fun addAll(elements: Collection<E>): Boolean = throw UnsupportedOperationException()
|
||||
override fun remove(element: E): Boolean = backing.remove(element) != null
|
||||
override fun remove(element: E): Boolean = backing.removeKey(element)
|
||||
override fun iterator(): MutableIterator<E> = backing.keysIterator()
|
||||
|
||||
override fun checkIsMutable() = backing.checkIsMutable()
|
||||
|
||||
@@ -348,6 +348,14 @@ internal class InternalHashMap<K, V> private constructor(
|
||||
}
|
||||
}
|
||||
|
||||
override fun removeKey(key: K): Boolean {
|
||||
checkIsMutable()
|
||||
val index = findKey(key)
|
||||
if (index < 0) return false
|
||||
removeEntryAt(index)
|
||||
return true
|
||||
}
|
||||
|
||||
private fun removeEntryAt(index: Int) {
|
||||
keysArray.resetAt(index)
|
||||
valuesArray?.resetAt(index)
|
||||
|
||||
@@ -22,6 +22,7 @@ internal interface InternalMap<K, V> {
|
||||
fun containsOtherEntry(entry: Map.Entry<*, *>): Boolean
|
||||
|
||||
fun remove(key: K): V?
|
||||
fun removeKey(key: K): Boolean
|
||||
fun removeValue(value: V): Boolean
|
||||
fun removeEntry(entry: Map.Entry<K, V>): Boolean
|
||||
|
||||
|
||||
@@ -173,6 +173,12 @@ internal open class InternalStringMap<K, V> : InternalMap<K, V> {
|
||||
return removingValue
|
||||
}
|
||||
|
||||
override fun removeKey(key: K): Boolean {
|
||||
val index = findKeyIndex(key) ?: return false
|
||||
removeKeyIndex(key, index)
|
||||
return true
|
||||
}
|
||||
|
||||
internal open fun removeKeyIndex(key: K, removingIndex: Int) {
|
||||
jsDeleteProperty(backingMap.unsafeCast<Any>(), key as Any)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user