[JS BE] add runtime-function and intrinsics for es6-classes
This commit is contained in:
@@ -151,6 +151,11 @@ class JsIntrinsics(private val irBuiltIns: IrBuiltIns, val context: JsIrBackendC
|
||||
val jsAnyToString = getInternalFunction("anyToString")
|
||||
val jsCompareTo = getInternalFunction("compareTo")
|
||||
val jsEquals = getInternalFunction("equals")
|
||||
val jsConstruct = getInternalFunction("construct")
|
||||
val jsNewTarget = unOp("jsNewTarget")
|
||||
val jsEmptyObject = unOp("emptyObject")
|
||||
val jsOpenInitializerBox = binOp("openInitializerBox")
|
||||
val es6DefaultType = defineEs6DefaultTypeIntrinsic().symbol
|
||||
|
||||
val jsImul = getInternalFunction("imul")
|
||||
|
||||
@@ -324,6 +329,14 @@ class JsIntrinsics(private val irBuiltIns: IrBuiltIns, val context: JsIrBackendC
|
||||
}
|
||||
}
|
||||
|
||||
private fun defineEs6DefaultTypeIntrinsic(): IrSimpleFunction {
|
||||
return externalPackageFragment.addFunction {
|
||||
name = Name.identifier("DefaultType")
|
||||
}.apply {
|
||||
returnType = addTypeParameter("T", irBuiltIns.anyType).defaultType
|
||||
}
|
||||
}
|
||||
|
||||
private fun defineJsBindIntrinsic(): IrSimpleFunction {
|
||||
return externalPackageFragment.addFunction {
|
||||
name = Name.identifier("\$jsBind\$")
|
||||
|
||||
+30
@@ -101,6 +101,36 @@ class JsIntrinsicTransformers(backendContext: JsIrBackendContext) {
|
||||
}
|
||||
}
|
||||
|
||||
add(intrinsics.jsNewTarget) { _, _ ->
|
||||
JsNameRef(JsName("target"), JsNameRef(JsName("new")))
|
||||
}
|
||||
|
||||
add(intrinsics.jsOpenInitializerBox) { call, context ->
|
||||
val arguments = translateCallArguments(call, context)
|
||||
|
||||
JsInvocation(
|
||||
JsNameRef("Object.assign"),
|
||||
arguments
|
||||
)
|
||||
}
|
||||
|
||||
add(intrinsics.jsEmptyObject) { _, _ ->
|
||||
JsObjectLiteral()
|
||||
}
|
||||
|
||||
add(intrinsics.es6DefaultType) { call, context ->
|
||||
val classifier: IrClassifierSymbol = call.getTypeArgument(0)!!.classifierOrFail
|
||||
val owner = classifier.owner
|
||||
|
||||
when {
|
||||
owner is IrClass && owner.isEffectivelyExternal() ->
|
||||
context.getRefForExternalClass(owner)
|
||||
|
||||
else ->
|
||||
context.getNameForStaticDeclaration(owner as IrDeclarationWithName).makeRef()
|
||||
}
|
||||
}
|
||||
|
||||
addIfNotNull(intrinsics.jsCode) { _, _ -> error("Should not be called") }
|
||||
|
||||
add(intrinsics.jsGetContinuation) { _, context: JsGenerationContext ->
|
||||
|
||||
Reference in New Issue
Block a user