From 42e8017cc7feea55c5bfa6de94cac79956af003a Mon Sep 17 00:00:00 2001 From: Ilya Goncharov Date: Thu, 23 Sep 2021 22:15:26 +0300 Subject: [PATCH] [JS IR] Revert removing of safeProperty(Get|Set) --- libraries/stdlib/js-ir/runtime/kotlinJsHacks.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libraries/stdlib/js-ir/runtime/kotlinJsHacks.kt b/libraries/stdlib/js-ir/runtime/kotlinJsHacks.kt index 4f2f6c169ca..c4d6699ffb6 100644 --- a/libraries/stdlib/js-ir/runtime/kotlinJsHacks.kt +++ b/libraries/stdlib/js-ir/runtime/kotlinJsHacks.kt @@ -13,6 +13,18 @@ internal fun > enumValuesIntrinsic(): Array = internal fun > enumValueOfIntrinsic(@Suppress("UNUSED_PARAMETER") name: String): T = throw IllegalStateException("Should be replaced by compiler") +@PublishedApi +internal fun safePropertyGet(self: dynamic, getterName: String, propName: String): dynamic { + val getter = self[getterName] + return if (getter != null) getter.call(self) else self[propName] +} + +@PublishedApi +internal fun safePropertySet(self: dynamic, setterName: String, propName: String, value: dynamic) { + val setter = self[setterName] + if (setter != null) setter.call(self, value) else self[propName] = value +} + /** * Implements annotated function in JavaScript. * [code] string must contain JS expression that evaluates to JS function with signature that matches annotated kotlin function