[JS] Reduce usage of 'js' function in stdlib
Function 'kotlin.js.js' is to be redesigned in JS IR backend, partially because it is a hard feature to support. Current implementation is unstable and can cause problems around inlining and name generator. Luckily most of its use-cases can be covered by simpler features like dynamic expressions and external declarations. Thus we are reducing it's usage in stdlib to make IR backend more stable in current state. JavaScript features that can't be covered by dynamic expression are implemented in 'jsOperators.kt' file respectively for each backend: - 'internal inline' function which calls 'js' function inside for current pre-IR backend - 'internal' function with '_hack' parameters for JS IR backend which will be later intinsicified in a compiler
This commit is contained in:
@@ -68,7 +68,7 @@ internal class InternalHashCodeMap<K, V>(override val equality: EqualityComparat
|
||||
if (chainOrEntry !is Array<*>) {
|
||||
val entry: MutableEntry<K, V> = chainOrEntry
|
||||
if (equality.equals(entry.key, key)) {
|
||||
deleteProperty(backingMap, hashCode)
|
||||
jsDeleteProperty(backingMap, hashCode)
|
||||
size--
|
||||
return entry.value
|
||||
} else {
|
||||
@@ -82,7 +82,7 @@ internal class InternalHashCodeMap<K, V>(override val equality: EqualityComparat
|
||||
if (chain.size == 1) {
|
||||
chain.asDynamic().length = 0
|
||||
// remove the whole array
|
||||
deleteProperty(backingMap, hashCode)
|
||||
jsDeleteProperty(backingMap, hashCode)
|
||||
} else {
|
||||
// splice out the entry we're removing
|
||||
chain.asDynamic().splice(index, 1)
|
||||
|
||||
@@ -19,11 +19,10 @@ internal interface InternalMap<K, V> : MutableIterable<MutableMap.MutableEntry<K
|
||||
fun clear(): Unit
|
||||
|
||||
fun createJsMap(): dynamic {
|
||||
val newJsMap = js("Object.create(null)")
|
||||
val result = js("Object.create(null)")
|
||||
// force to switch object representation to dictionary mode
|
||||
// Using js-function due to JS_IR limitations
|
||||
js("newJsMap[\"foo\"] = 1")
|
||||
js("delete newJsMap[\"foo\"]")
|
||||
return newJsMap
|
||||
result["foo"] = 1
|
||||
jsDeleteProperty(result, "foo")
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ internal class InternalStringMap<K, V>(override val equality: EqualityComparator
|
||||
if (key !is String) return null
|
||||
val value = backingMap[key]
|
||||
if (value !== undefined) {
|
||||
deleteProperty(backingMap, key)
|
||||
jsDeleteProperty(backingMap, key)
|
||||
size--
|
||||
// structureChanged(host)
|
||||
return value.unsafeCast<V>()
|
||||
|
||||
@@ -15,7 +15,7 @@ internal fun <T : Any> getKClass(jClass: JsClass<T>): KClass<T> = getOrCreateKCl
|
||||
internal fun <T : Any> getKClassFromExpression(e: T): KClass<T> =
|
||||
when (jsTypeOf(e)) {
|
||||
"string" -> PrimitiveClasses.stringClass
|
||||
"number" -> if (js("e | 0") === e) PrimitiveClasses.intClass else PrimitiveClasses.doubleClass
|
||||
"number" -> if (jsBitwiseOr(e, 0).asDynamic() === e) PrimitiveClasses.intClass else PrimitiveClasses.doubleClass
|
||||
"boolean" -> PrimitiveClasses.booleanClass
|
||||
"function" -> PrimitiveClasses.functionClass(e.asDynamic().length)
|
||||
else -> {
|
||||
|
||||
Reference in New Issue
Block a user