[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 unreachable = getInternalFunction("unreachable")
|
||||||
|
|
||||||
|
val jsArguments = getInternalFunction("jsArguments")
|
||||||
|
|
||||||
val returnIfSuspended = getInternalFunction("returnIfSuspended")
|
val returnIfSuspended = getInternalFunction("returnIfSuspended")
|
||||||
val getContinuation = getInternalFunction("getContinuation")
|
val getContinuation = getInternalFunction("getContinuation")
|
||||||
|
|
||||||
@@ -348,4 +350,4 @@ class JsIntrinsics(private val irBuiltIns: IrBuiltIns, val context: JsIrBackendC
|
|||||||
|
|
||||||
private fun getInternalClassWithoutPackage(fqName: String) =
|
private fun getInternalClassWithoutPackage(fqName: String) =
|
||||||
context.symbolTable.referenceClass(context.getClass(FqName(fqName)))
|
context.symbolTable.referenceClass(context.getClass(FqName(fqName)))
|
||||||
}
|
}
|
||||||
|
|||||||
+2
@@ -236,6 +236,8 @@ class JsIntrinsicTransformers(backendContext: JsIrBackendContext) {
|
|||||||
add(intrinsics.jsInvokeSuspendSuperType, suspendInvokeTransform)
|
add(intrinsics.jsInvokeSuspendSuperType, suspendInvokeTransform)
|
||||||
add(intrinsics.jsInvokeSuspendSuperTypeWithReceiver, suspendInvokeTransform)
|
add(intrinsics.jsInvokeSuspendSuperTypeWithReceiver, suspendInvokeTransform)
|
||||||
add(intrinsics.jsInvokeSuspendSuperTypeWithReceiverAndParam, suspendInvokeTransform)
|
add(intrinsics.jsInvokeSuspendSuperTypeWithReceiverAndParam, suspendInvokeTransform)
|
||||||
|
|
||||||
|
add(intrinsics.jsArguments) { _, _ -> Namer.ARGUMENTS }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ object Namer {
|
|||||||
|
|
||||||
val IMPLICIT_RECEIVER_NAME = "this"
|
val IMPLICIT_RECEIVER_NAME = "this"
|
||||||
|
|
||||||
|
val ARGUMENTS = JsNameRef("arguments")
|
||||||
|
|
||||||
val PROTOTYPE_NAME = "prototype"
|
val PROTOTYPE_NAME = "prototype"
|
||||||
val CONSTRUCTOR_NAME = "constructor"
|
val CONSTRUCTOR_NAME = "constructor"
|
||||||
|
|
||||||
@@ -42,4 +44,4 @@ object Namer {
|
|||||||
const val KCALLABLE_ARITY = "\$arity"
|
const val KCALLABLE_ARITY = "\$arity"
|
||||||
|
|
||||||
const val SHARED_BOX_V = "_v"
|
const val SHARED_BOX_V = "_v"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -195,6 +195,9 @@ internal fun <A> slice(a: A): A
|
|||||||
@JsIntrinsic
|
@JsIntrinsic
|
||||||
internal fun unreachable(): Nothing
|
internal fun unreachable(): Nothing
|
||||||
|
|
||||||
|
@JsIntrinsic
|
||||||
|
internal fun jsArguments(): Any?
|
||||||
|
|
||||||
@JsIntrinsic
|
@JsIntrinsic
|
||||||
@Suppress("REIFIED_TYPE_PARAMETER_NO_INLINE") // TODO: mark `inline` and skip in inliner
|
@Suppress("REIFIED_TYPE_PARAMETER_NO_INLINE") // TODO: mark `inline` and skip in inliner
|
||||||
internal fun <reified T : Any> jsClassIntrinsic(): JsClass<T>
|
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
|
internal fun jsInIntrinsic(lhs: Any?, rhs: Any): Boolean
|
||||||
|
|
||||||
@JsIntrinsic
|
@JsIntrinsic
|
||||||
internal fun jsDelete(e: Any?)
|
internal fun jsDelete(e: Any?)
|
||||||
|
|||||||
Reference in New Issue
Block a user