diff --git a/compiler/testData/codegen/boxWasmJsInterop/functionTypes.kt b/compiler/testData/codegen/boxWasmJsInterop/functionTypes.kt index a8e7567dc42..d9d7b218c29 100644 --- a/compiler/testData/codegen/boxWasmJsInterop/functionTypes.kt +++ b/compiler/testData/codegen/boxWasmJsInterop/functionTypes.kt @@ -98,7 +98,7 @@ external fun is123Array(x: EI): Boolean external fun create123Array(): EI data class DC(val x: Int, val y: Int) -typealias JSDC = JsHandle +typealias JSDC = JsReference external fun extenalWithLambda( x: (Boolean, Byte, Short, Char, Int, Long, Float, Double, String, EI, JSDC) -> Unit, @@ -179,7 +179,7 @@ fun box(): String { test(string == "S") test(is123Array(ei)) test(dc.x == 100 && dc.y == 200) - }, DC(100, 200).toJsHandle()) + }, DC(100, 200).toJsReference()) if (extenalWithLambdasCount != 11) return "Fail 1" @@ -195,7 +195,7 @@ fun box(): String { double = { 600.5 }, string = { "700" }, ei = { create123Array() }, - dc = { DC(800, 800).toJsHandle() }, + dc = { DC(800, 800).toJsReference() }, dcGetY = { it.get().y } ) if (externalWithLambdas2Count != 11) return "Fail externalWithLambdas2" @@ -212,7 +212,7 @@ fun box(): String { { 600.5 }, { "700" }, { create123Array() }, - { DC(800, 800).toJsHandle() }, + { DC(800, 800).toJsReference() }, { it.get().y } ) if (externalWithLambdas2RefCount != 11) return "Fail externalWithLambdas2" @@ -230,7 +230,7 @@ fun box(): String { 600.5, "700", create123Array(), - DC(800, 800).toJsHandle(), + DC(800, 800).toJsReference(), { it.get().y } ) if (jsLambdaCount != 11) diff --git a/compiler/testData/codegen/boxWasmJsInterop/jsExport.kt b/compiler/testData/codegen/boxWasmJsInterop/jsExport.kt index f8b8b8b75ca..181660e0acc 100644 --- a/compiler/testData/codegen/boxWasmJsInterop/jsExport.kt +++ b/compiler/testData/codegen/boxWasmJsInterop/jsExport.kt @@ -5,10 +5,10 @@ class C(val x: Int) @JsExport -fun makeC(x: Int): JsHandle = C(x).toJsHandle() +fun makeC(x: Int): JsReference = C(x).toJsReference() @JsExport -fun getX(c: JsHandle): Int = c.get().x +fun getX(c: JsReference): Int = c.get().x @JsExport fun getString(s: String): String = "Test string $s"; @@ -19,10 +19,10 @@ fun isEven(x: Int): Boolean = x % 2 == 0 external interface EI @JsExport -fun eiAsAny(ei: EI): JsHandle = ei.toJsHandle() +fun eiAsAny(ei: EI): JsReference = ei.toJsReference() @JsExport -fun anyAsEI(any: JsHandle): EI = any.get() as EI +fun anyAsEI(any: JsReference): EI = any.get() as EI fun box(): String = "OK" diff --git a/compiler/testData/codegen/boxWasmJsInterop/jsToKotlinAdapters.kt b/compiler/testData/codegen/boxWasmJsInterop/jsToKotlinAdapters.kt index 0882180c66d..6339a749938 100644 --- a/compiler/testData/codegen/boxWasmJsInterop/jsToKotlinAdapters.kt +++ b/compiler/testData/codegen/boxWasmJsInterop/jsToKotlinAdapters.kt @@ -44,7 +44,7 @@ fun testExterRef() { } class DataRefImpl -typealias DataRef = JsHandle +typealias DataRef = JsReference fun notNullDataRef(x: DataRef): DataRef = js("x") @@ -55,7 +55,7 @@ fun nullDataRef(x: DataRef): DataRef? = js("x") fun null2DataRef(x: DataRef): DataRef? = js("null") fun testDataRef() { - val dataRef = DataRefImpl().toJsHandle() + val dataRef = DataRefImpl().toJsReference() check(notNullDataRef(dataRef) == dataRef) checkNPE { notNull2DataRef(dataRef) } check (nullDataRef(dataRef) == dataRef) diff --git a/compiler/testData/codegen/boxWasmJsInterop/jsTypes.kt b/compiler/testData/codegen/boxWasmJsInterop/jsTypes.kt index 6e75d30168a..dda6a07d6b6 100644 --- a/compiler/testData/codegen/boxWasmJsInterop/jsTypes.kt +++ b/compiler/testData/codegen/boxWasmJsInterop/jsTypes.kt @@ -49,13 +49,13 @@ fun box(): String { assertTrue(jsArray[1] == "element1".toJsString()) assertTrue(jsRepresentation(jsArray) == "object:element0,element1,element2") - // JsHandle - val jsHandle: JsHandle = 10.toJsHandle() - assertTrue(jsHandle.get() == 10) - assertTrue(jsHandle.toJsHandle().get() == jsHandle) + // JsReference + val jsReference: JsReference = 10.toJsReference() + assertTrue(jsReference.get() == 10) + assertTrue(jsReference.toJsReference().get() == jsReference) val c = listOf(1) - assertTrue(c.toJsHandle().get() === c.toJsHandle().get()) - assertTrue(c.toJsHandle() === c.toJsHandle()) + assertTrue(c.toJsReference().get() === c.toJsReference().get()) + assertTrue(c.toJsReference() === c.toJsReference()) return "OK" } \ No newline at end of file diff --git a/libraries/stdlib/wasm/internal/kotlin/wasm/internal/ExternalWrapper.kt b/libraries/stdlib/wasm/internal/kotlin/wasm/internal/ExternalWrapper.kt index f26cefbe3dd..b8be92c7538 100644 --- a/libraries/stdlib/wasm/internal/kotlin/wasm/internal/ExternalWrapper.kt +++ b/libraries/stdlib/wasm/internal/kotlin/wasm/internal/ExternalWrapper.kt @@ -126,8 +126,8 @@ private fun externrefEquals(lhs: ExternalInterfaceType, rhs: ExternalInterfaceTy private external fun tryGetOrSetExternrefBox( ref: ExternalInterfaceType, - ifNotCached: JsHandle -): JsHandle? + ifNotCached: JsReference +): JsReference? @WasmNoOpCast @Suppress("unused") @@ -174,7 +174,7 @@ internal fun externRefToAny(ref: ExternalInterfaceType): Any? { // If we have Null in notNullRef -- return null // If we already have a box -- return it, // otherwise -- remember new box and return it. - return tryGetOrSetExternrefBox(ref, JsExternalBox(ref).toJsHandle()) + return tryGetOrSetExternrefBox(ref, JsExternalBox(ref).toJsReference()) } diff --git a/libraries/stdlib/wasm/src/kotlin/Dynamic.kt b/libraries/stdlib/wasm/src/kotlin/Dynamic.kt index 815c7f5689c..75585778df7 100644 --- a/libraries/stdlib/wasm/src/kotlin/Dynamic.kt +++ b/libraries/stdlib/wasm/src/kotlin/Dynamic.kt @@ -16,8 +16,8 @@ public external interface Dynamic : JsAny /** * Reinterprets this value as a value of the Dynamic type. */ -@Deprecated("If value is a subtype of JsAny, use JsAny instead. Otherwise, use toJsHandle", level = DeprecationLevel.ERROR) -fun Any.asDynamic(): JsAny = this.toJsHandle() +@Deprecated("If value is a subtype of JsAny, use JsAny instead. Otherwise, use toJsReference", level = DeprecationLevel.ERROR) +fun Any.asDynamic(): JsAny = this.toJsReference() /** * Reinterprets this value as a value of the Dynamic type. diff --git a/libraries/stdlib/wasm/src/kotlin/js/JsHandle.kt b/libraries/stdlib/wasm/src/kotlin/js/JsReference.kt similarity index 66% rename from libraries/stdlib/wasm/src/kotlin/js/JsHandle.kt rename to libraries/stdlib/wasm/src/kotlin/js/JsReference.kt index 62595c919f4..a53138ba6c2 100644 --- a/libraries/stdlib/wasm/src/kotlin/js/JsHandle.kt +++ b/libraries/stdlib/wasm/src/kotlin/js/JsReference.kt @@ -10,20 +10,20 @@ import kotlin.wasm.internal.implementedAsIntrinsic import kotlin.wasm.internal.returnArgumentIfItIsKotlinAny /** - * JavaScript value that can serve as a handle for any Kotlin value. + * JavaScript value that can serve as a reference for any Kotlin value. * * In JavaScript, it behaves like an immutable empty object with a null prototype. * When passed back to Kotlin/Wasm, the original value can be retrieved using the [get] method. */ @Suppress("WRONG_JS_INTEROP_TYPE") // Exception to the rule -public sealed external interface JsHandle : JsAny +public sealed external interface JsReference : JsAny @WasmOp(WasmOp.EXTERN_EXTERNALIZE) -public fun T.toJsHandle(): JsHandle = +public fun T.toJsReference(): JsReference = implementedAsIntrinsic -/** Retrieve original Kotlin value from JsHandle */ -public fun JsHandle.get(): T { +/** Retrieve original Kotlin value from JsReference */ +public fun JsReference.get(): T { returnArgumentIfItIsKotlinAny(this) - throw ClassCastException("JsHandle doesn't contain a Kotlin type") + throw ClassCastException("JsReference doesn't contain a Kotlin type") } \ No newline at end of file diff --git a/libraries/stdlib/wasm/test/js/AsyncTest.kt b/libraries/stdlib/wasm/test/js/AsyncTest.kt index 7e00fa7733b..9d929ffc5f6 100644 --- a/libraries/stdlib/wasm/test/js/AsyncTest.kt +++ b/libraries/stdlib/wasm/test/js/AsyncTest.kt @@ -57,6 +57,6 @@ class AsyncTest { @Test fun testJsValueToThrowableOrNull2() { val e = MyThrowable() - assertEquals((e.toJsHandle()).toThrowableOrNull(), e) + assertEquals((e.toJsReference()).toThrowableOrNull(), e) } } \ No newline at end of file