Drop deprecated jsClass top level and extension functions

Introduce internal toplevel jsClass in js-ir source set instead.
It is needed for JS-IR backend.
This commit is contained in:
Ilya Gorbunov
2020-06-19 06:23:47 +03:00
parent 696701d377
commit 6c8ff25e5d
8 changed files with 9 additions and 180 deletions

View File

@@ -6884,31 +6884,6 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
runTest("js/js.translator/testData/box/reflection/findAssociatedObject_oldBE.kt");
}
@TestMetadata("jsClass.kt")
public void testJsClass() throws Exception {
runTest("js/js.translator/testData/box/reflection/jsClass.kt");
}
@TestMetadata("jsClassName.kt")
public void testJsClassName() throws Exception {
runTest("js/js.translator/testData/box/reflection/jsClassName.kt");
}
@TestMetadata("jsClassOnReifiedType.kt")
public void testJsClassOnReifiedType() throws Exception {
runTest("js/js.translator/testData/box/reflection/jsClassOnReifiedType.kt");
}
@TestMetadata("jsClassOnReifiedTypeInLambda.kt")
public void testJsClassOnReifiedTypeInLambda() throws Exception {
runTest("js/js.translator/testData/box/reflection/jsClassOnReifiedTypeInLambda.kt");
}
@TestMetadata("jsClassSimpleName.kt")
public void testJsClassSimpleName() throws Exception {
runTest("js/js.translator/testData/box/reflection/jsClassSimpleName.kt");
}
@TestMetadata("kClass.kt")
public void testKClass() throws Exception {
runTest("js/js.translator/testData/box/reflection/kClass.kt");

View File

@@ -1,18 +0,0 @@
// DONT_TARGET_EXACT_BACKEND: JS_IR
// DONT_TARGET_EXACT_BACKEND: JS_IR_ES6
// EXPECTED_REACHABLE_NODES: 1322
package foo
@Suppress("DEPRECATION_ERROR")
fun box(): String {
check(jsClass<A>(), A().jsClass)
check(jsClass<B>(), B().jsClass)
check(jsClass<O>(), O.jsClass)
assertNotEquals(null, jsClass<I>())
check(jsClass<E>(), E.X.jsClass)
check(jsClass<E>(), E.Y.jsClass, shouldBeEqual = false)
// TODO uncomment after KT-13338 is fixed
// check(jsClass<E>(), E.Z.jsClass)
return "OK"
}

View File

@@ -1,33 +0,0 @@
// DONT_TARGET_EXACT_BACKEND: JS_IR
// DONT_TARGET_EXACT_BACKEND: JS_IR_ES6
// EXPECTED_REACHABLE_NODES: 1328
package foo
@Suppress("DEPRECATION_ERROR")
fun testWithInstance() {
assertEquals("A", A().jsClass.name)
assertEquals("B", B().jsClass.name)
assertEquals("O", O.jsClass.name)
assertEquals("E", E.X.jsClass.name)
assertEquals("E\$Y", E.Y.jsClass.name)
// TODO uncomment after KT-13338 is fixed
// assertEquals("E", E.Z.jsClass.name)
assertEquals("R", R().jsClass.name)
}
@Suppress("DEPRECATION_ERROR")
fun testWithClassReference() {
assertEquals("A", jsClass<A>().name)
assertEquals("B", jsClass<B>().name)
assertEquals("O", jsClass<O>().name)
assertEquals("I", jsClass<I>().name)
assertEquals("E", jsClass<E>().name)
assertEquals("R", jsClass<R>().name)
}
fun box(): String {
testWithInstance()
testWithClassReference()
return "OK"
}

View File

@@ -1,20 +0,0 @@
// DONT_TARGET_EXACT_BACKEND: JS_IR
// DONT_TARGET_EXACT_BACKEND: JS_IR_ES6
// EXPECTED_REACHABLE_NODES: 1318
package foo
@Suppress("DEPRECATION_ERROR")
inline fun <reified T : Any> foo(): JsClass<T> {
val T = 1
return jsClass<T>()
}
@Suppress("DEPRECATION_ERROR")
fun box(): String {
check(jsClass<A>(), foo<A>())
check(jsClass<B>(), foo<B>())
check(jsClass<O>(), foo<O>())
check(jsClass<E>(), foo<E>())
return "OK"
}

View File

@@ -1,20 +0,0 @@
// DONT_TARGET_EXACT_BACKEND: JS_IR
// DONT_TARGET_EXACT_BACKEND: JS_IR_ES6
// EXPECTED_REACHABLE_NODES: 1320
package foo
@Suppress("DEPRECATION_ERROR")
inline fun <reified T : Any> foo(): () -> JsClass<T> {
val T = 1
return { jsClass<T>() }
}
@Suppress("DEPRECATION_ERROR")
fun box(): String {
check(jsClass<A>(), foo<A>()())
check(jsClass<B>(), foo<B>()())
check(jsClass<O>(), foo<O>()())
check(jsClass<E>(), foo<E>()())
return "OK"
}

View File

@@ -1,51 +0,0 @@
// DONT_TARGET_EXACT_BACKEND: JS_IR
// DONT_TARGET_EXACT_BACKEND: JS_IR_ES6
// EXPECTED_REACHABLE_NODES: 1331
package foo
class undefined
class Outer {
class Nested
inner class Inner
}
@Suppress("DEPRECATION_ERROR")
fun testWithInstance() {
assertEquals("A", A().jsClass.simpleName)
assertEquals("B", B().jsClass.simpleName)
assertEquals("O", O.jsClass.simpleName)
assertEquals("E", E.X.jsClass.simpleName)
assertEquals("Y", E.Y.jsClass.simpleName)
// TODO uncomment after KT-13338 is fixed
// assertEquals("E", E.Z.jsClass.simpleName)
assertEquals("undefined", undefined().jsClass.simpleName)
assertEquals("Nested", Outer.Nested().jsClass.simpleName)
assertEquals("Inner", Outer().Inner().jsClass.simpleName)
}
@Suppress("DEPRECATION_ERROR")
fun testWithClassReference() {
assertEquals("A", jsClass<A>().simpleName)
assertEquals("B", jsClass<B>().simpleName)
assertEquals("O", jsClass<O>().simpleName)
assertEquals("I", jsClass<I>().simpleName)
assertEquals("E", jsClass<E>().simpleName)
assertEquals("undefined", jsClass<undefined>().simpleName)
assertEquals("Nested", jsClass<Outer.Nested>().simpleName)
assertEquals("Inner", jsClass<Outer.Inner>().simpleName)
}
val JsClass<*>.simpleName: String
get() {
val dynClass: dynamic = this
return dynClass.`$metadata$`.simpleName as? String ?: ""
}
fun box(): String {
testWithInstance()
testWithClassReference()
return "OK"
}

View File

@@ -0,0 +1,8 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package kotlin.js
internal external fun <T : Any> jsClass(): JsClass<T>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -19,18 +19,6 @@ external interface JsClass<T : Any> {
val name: String
}
@Deprecated("Use class literal and extension property `js` instead.", replaceWith = ReplaceWith("T::class.js"), level = DeprecationLevel.ERROR)
external fun <T : Any> jsClass(): JsClass<T>
@Deprecated("Use class literal and extension property `js` instead.", replaceWith = ReplaceWith("this::class.js"), level = DeprecationLevel.ERROR)
val <T : Any> T.jsClass: JsClass<T>
get() = when (jsTypeOf(this)) {
"string" -> js("String")
"number" -> js("Number")
"boolean" -> js("Boolean")
else -> js("Object").getPrototypeOf(this).constructor
}
/**
* Obtains a constructor reference for the given `KClass`.
*/