[Wasm] Rename JsHandle to JsReference

Decision to do this was made at Kotlin/Wasm interop design meeting
This commit is contained in:
Svyatoslav Kuzmich
2023-04-19 15:38:47 +02:00
committed by teamcity
parent 7ba8f7cce2
commit 933f47aaf9
8 changed files with 29 additions and 29 deletions
@@ -126,8 +126,8 @@ private fun externrefEquals(lhs: ExternalInterfaceType, rhs: ExternalInterfaceTy
private external fun tryGetOrSetExternrefBox(
ref: ExternalInterfaceType,
ifNotCached: JsHandle<JsExternalBox>
): JsHandle<JsExternalBox>?
ifNotCached: JsReference<JsExternalBox>
): JsReference<JsExternalBox>?
@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())
}
+2 -2
View File
@@ -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.
@@ -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<out T : Any> : JsAny
public sealed external interface JsReference<out T : Any> : JsAny
@WasmOp(WasmOp.EXTERN_EXTERNALIZE)
public fun <T : Any> T.toJsHandle(): JsHandle<T> =
public fun <T : Any> T.toJsReference(): JsReference<T> =
implementedAsIntrinsic
/** Retrieve original Kotlin value from JsHandle */
public fun <T : Any> JsHandle<T>.get(): T {
/** Retrieve original Kotlin value from JsReference */
public fun <T : Any> JsReference<T>.get(): T {
returnArgumentIfItIsKotlinAny(this)
throw ClassCastException("JsHandle doesn't contain a Kotlin type")
throw ClassCastException("JsReference doesn't contain a Kotlin type")
}
+1 -1
View File
@@ -57,6 +57,6 @@ class AsyncTest {
@Test
fun testJsValueToThrowableOrNull2() {
val e = MyThrowable()
assertEquals((e.toJsHandle()).toThrowableOrNull(), e)
assertEquals((e.toJsReference()).toThrowableOrNull(), e)
}
}