KJS: type -> kind
This commit is contained in:
@@ -118,11 +118,13 @@ class CoroutineFunctionTransformer(private val program: JsProgram, private val f
|
|||||||
private fun generateCoroutineMetadata(constructorName: JsName): JsStatement {
|
private fun generateCoroutineMetadata(constructorName: JsName): JsStatement {
|
||||||
val baseClassRefRef = function.coroutineMetadata!!.baseClassRef.deepCopy()
|
val baseClassRefRef = function.coroutineMetadata!!.baseClassRef.deepCopy()
|
||||||
|
|
||||||
val metadataObject = JsObjectLiteral(true)
|
val metadataObject = JsObjectLiteral(true).apply {
|
||||||
metadataObject.propertyInitializers += JsPropertyInitializer(
|
propertyInitializers +=
|
||||||
JsNameRef("type"), JsNameRef("CLASS", JsNameRef("TYPE", Namer.KOTLIN_NAME)))
|
JsPropertyInitializer(JsNameRef(Namer.METADATA_CLASS_KIND),
|
||||||
metadataObject.propertyInitializers += JsPropertyInitializer(JsNameRef("simpleName"), JsLiteral.NULL)
|
JsNameRef(Namer.CLASS_KIND_CLASS, JsNameRef(Namer.CLASS_KIND_ENUM, Namer.KOTLIN_NAME)))
|
||||||
metadataObject.propertyInitializers += JsPropertyInitializer(JsNameRef("baseClasses"), JsArrayLiteral(listOf(baseClassRefRef)))
|
propertyInitializers += JsPropertyInitializer(JsNameRef(Namer.METADATA_SIMPLE_NAME), JsLiteral.NULL)
|
||||||
|
propertyInitializers += JsPropertyInitializer(JsNameRef(Namer.METADATA_SUPERTYPES), JsArrayLiteral(listOf(baseClassRefRef)))
|
||||||
|
}
|
||||||
|
|
||||||
return JsAstUtils.assignment(JsNameRef(Namer.METADATA, constructorName.makeRef()), metadataObject).makeStmt()
|
return JsAstUtils.assignment(JsNameRef(Namer.METADATA, constructorName.makeRef()), metadataObject).makeStmt()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Kotlin.TYPE = {
|
Kotlin.Kind = {
|
||||||
CLASS: "class",
|
CLASS: "class",
|
||||||
INTERFACE: "interface",
|
INTERFACE: "interface",
|
||||||
OBJECT: "object"
|
OBJECT: "object"
|
||||||
@@ -99,7 +99,7 @@ Kotlin.isType = function (object, klass) {
|
|||||||
var constructor = proto != null ? proto.constructor : null;
|
var constructor = proto != null ? proto.constructor : null;
|
||||||
if (constructor != null && "$metadata$" in constructor) {
|
if (constructor != null && "$metadata$" in constructor) {
|
||||||
var metadata = constructor.$metadata$;
|
var metadata = constructor.$metadata$;
|
||||||
if (metadata.type === Kotlin.TYPE.OBJECT) {
|
if (metadata.kind === Kotlin.Kind.OBJECT) {
|
||||||
return object === klass;
|
return object === klass;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,7 +111,7 @@ Kotlin.isType = function (object, klass) {
|
|||||||
return object instanceof klass;
|
return object instanceof klass;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (klassMetadata.type === Kotlin.TYPE.INTERFACE && object.constructor != null) {
|
if (klassMetadata.kind === Kotlin.Kind.INTERFACE && object.constructor != null) {
|
||||||
metadata = object.constructor.$metadata$;
|
metadata = object.constructor.$metadata$;
|
||||||
if (metadata != null) {
|
if (metadata != null) {
|
||||||
return isInheritanceFromInterface(metadata, klass);
|
return isInheritanceFromInterface(metadata, klass);
|
||||||
|
|||||||
@@ -111,6 +111,12 @@ public final class Namer {
|
|||||||
public static final String LOCAL_MODULE_PREFIX = "$module$";
|
public static final String LOCAL_MODULE_PREFIX = "$module$";
|
||||||
public static final String METADATA = "$metadata$";
|
public static final String METADATA = "$metadata$";
|
||||||
public static final String METADATA_SUPERTYPES = "baseClasses";
|
public static final String METADATA_SUPERTYPES = "baseClasses";
|
||||||
|
public static final String METADATA_SIMPLE_NAME = "simpleName";
|
||||||
|
public static final String METADATA_CLASS_KIND = "kind";
|
||||||
|
public static final String CLASS_KIND_ENUM = "Kind";
|
||||||
|
public static final String CLASS_KIND_CLASS = "CLASS";
|
||||||
|
public static final String CLASS_KIND_INTERFACE = "INTERFACE";
|
||||||
|
public static final String CLASS_KIND_OBJECT = "OBJECT";
|
||||||
|
|
||||||
public static final String OBJECT_INSTANCE_VAR_SUFFIX = "_instance";
|
public static final String OBJECT_INSTANCE_VAR_SUFFIX = "_instance";
|
||||||
public static final String OBJECT_INSTANCE_FUNCTION_SUFFIX = "_getInstance";
|
public static final String OBJECT_INSTANCE_FUNCTION_SUFFIX = "_getInstance";
|
||||||
|
|||||||
+6
-6
@@ -171,18 +171,18 @@ class ClassTranslator private constructor(
|
|||||||
private fun createMetadataRef() = JsNameRef(Namer.METADATA, context().getInnerReference(descriptor))
|
private fun createMetadataRef() = JsNameRef(Namer.METADATA, context().getInnerReference(descriptor))
|
||||||
|
|
||||||
private fun addMetadataType() {
|
private fun addMetadataType() {
|
||||||
val kotlinType = JsNameRef("TYPE", Namer.KOTLIN_NAME)
|
val kotlinType = JsNameRef(Namer.CLASS_KIND_ENUM, Namer.KOTLIN_NAME)
|
||||||
val typeRef = when {
|
val typeRef = when {
|
||||||
DescriptorUtils.isInterface(descriptor) -> JsNameRef("INTERFACE", kotlinType)
|
DescriptorUtils.isInterface(descriptor) -> JsNameRef(Namer.CLASS_KIND_INTERFACE, kotlinType)
|
||||||
DescriptorUtils.isObject(descriptor) -> JsNameRef("OBJECT", kotlinType)
|
DescriptorUtils.isObject(descriptor) -> JsNameRef(Namer.CLASS_KIND_OBJECT, kotlinType)
|
||||||
else -> JsNameRef("CLASS", kotlinType)
|
else -> JsNameRef(Namer.CLASS_KIND_CLASS, kotlinType)
|
||||||
}
|
}
|
||||||
|
|
||||||
metadataLiteral.propertyInitializers += JsPropertyInitializer(JsNameRef("type"), typeRef)
|
metadataLiteral.propertyInitializers += JsPropertyInitializer(JsNameRef(Namer.METADATA_CLASS_KIND), typeRef)
|
||||||
|
|
||||||
val simpleName = descriptor.name
|
val simpleName = descriptor.name
|
||||||
if (!simpleName.isSpecial) {
|
if (!simpleName.isSpecial) {
|
||||||
val simpleNameProp = JsPropertyInitializer(JsNameRef("simpleName"), program().getStringLiteral(simpleName.identifier))
|
val simpleNameProp = JsPropertyInitializer(JsNameRef(Namer.METADATA_SIMPLE_NAME), program().getStringLiteral(simpleName.identifier))
|
||||||
metadataLiteral.propertyInitializers += simpleNameProp
|
metadataLiteral.propertyInitializers += simpleNameProp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user