Provide extension unsafeCast for dynamic.
#KT-15310
This commit is contained in:
@@ -23,6 +23,13 @@ public inline fun Any?.asDynamic(): dynamic = this
|
|||||||
*/
|
*/
|
||||||
public inline fun <T> Any?.unsafeCast(): @kotlin.internal.NoInfer T = this.asDynamic()
|
public inline fun <T> Any?.unsafeCast(): @kotlin.internal.NoInfer T = this.asDynamic()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reinterprets this `dynamic` value as a value of the specified type [T] without any actual type checking.
|
||||||
|
*/
|
||||||
|
@kotlin.internal.DynamicExtension
|
||||||
|
@JsName("unsafeCastDynamic")
|
||||||
|
public inline fun <T> dynamic.unsafeCast(): @kotlin.internal.NoInfer T = this
|
||||||
|
|
||||||
// TODO add the support ES6 iterators
|
// TODO add the support ES6 iterators
|
||||||
@kotlin.internal.DynamicExtension
|
@kotlin.internal.DynamicExtension
|
||||||
public operator fun dynamic.iterator(): Iterator<dynamic> {
|
public operator fun dynamic.iterator(): Iterator<dynamic> {
|
||||||
|
|||||||
@@ -4732,6 +4732,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
|
|||||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/inlineStdlib/thisInExtension.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/inlineStdlib/thisInExtension.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("unsafeCast.kt")
|
||||||
|
public void testUnsafeCast() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/inlineStdlib/unsafeCast.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("js/js.translator/testData/box/java")
|
@TestMetadata("js/js.translator/testData/box/java")
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package foo
|
||||||
|
|
||||||
|
// CHECK_NOT_CALLED_IN_SCOPE: scope=box function=isType
|
||||||
|
// CHECK_NOT_CALLED_IN_SCOPE: scope=box function=throwCCE
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
// dynamic unsafeCast
|
||||||
|
val result = js("\"OK\"").unsafeCast<String>()
|
||||||
|
// Any unsafeCast
|
||||||
|
val intOk = result.unsafeCast<Int>()
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user