[JS IR] Introduce jsArguments() intrinsic function
`jsArguments()` is lowered into a reference of the `arguments` object. This is useful for extracting varargs, when calling Kotlin code from JavaScript. For a concrete example, see KT-15223.
This commit is contained in:
@@ -215,6 +215,8 @@ class JsIntrinsics(private val irBuiltIns: IrBuiltIns, val context: JsIrBackendC
|
||||
|
||||
val unreachable = getInternalFunction("unreachable")
|
||||
|
||||
val jsArguments = getInternalFunction("jsArguments")
|
||||
|
||||
val returnIfSuspended = getInternalFunction("returnIfSuspended")
|
||||
val getContinuation = getInternalFunction("getContinuation")
|
||||
|
||||
@@ -348,4 +350,4 @@ class JsIntrinsics(private val irBuiltIns: IrBuiltIns, val context: JsIrBackendC
|
||||
|
||||
private fun getInternalClassWithoutPackage(fqName: String) =
|
||||
context.symbolTable.referenceClass(context.getClass(FqName(fqName)))
|
||||
}
|
||||
}
|
||||
|
||||
+2
@@ -236,6 +236,8 @@ class JsIntrinsicTransformers(backendContext: JsIrBackendContext) {
|
||||
add(intrinsics.jsInvokeSuspendSuperType, suspendInvokeTransform)
|
||||
add(intrinsics.jsInvokeSuspendSuperTypeWithReceiver, suspendInvokeTransform)
|
||||
add(intrinsics.jsInvokeSuspendSuperTypeWithReceiverAndParam, suspendInvokeTransform)
|
||||
|
||||
add(intrinsics.jsArguments) { _, _ -> Namer.ARGUMENTS }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ object Namer {
|
||||
|
||||
val IMPLICIT_RECEIVER_NAME = "this"
|
||||
|
||||
val ARGUMENTS = JsNameRef("arguments")
|
||||
|
||||
val PROTOTYPE_NAME = "prototype"
|
||||
val CONSTRUCTOR_NAME = "constructor"
|
||||
|
||||
@@ -42,4 +44,4 @@ object Namer {
|
||||
const val KCALLABLE_ARITY = "\$arity"
|
||||
|
||||
const val SHARED_BOX_V = "_v"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,6 +195,9 @@ internal fun <A> slice(a: A): A
|
||||
@JsIntrinsic
|
||||
internal fun unreachable(): Nothing
|
||||
|
||||
@JsIntrinsic
|
||||
internal fun jsArguments(): Any?
|
||||
|
||||
@JsIntrinsic
|
||||
@Suppress("REIFIED_TYPE_PARAMETER_NO_INLINE") // TODO: mark `inline` and skip in inliner
|
||||
internal fun <reified T : Any> jsClassIntrinsic(): JsClass<T>
|
||||
@@ -204,4 +207,4 @@ internal fun <reified T : Any> jsClassIntrinsic(): JsClass<T>
|
||||
internal fun jsInIntrinsic(lhs: Any?, rhs: Any): Boolean
|
||||
|
||||
@JsIntrinsic
|
||||
internal fun jsDelete(e: Any?)
|
||||
internal fun jsDelete(e: Any?)
|
||||
|
||||
Reference in New Issue
Block a user