[WASM] Fix invalid element visiting for external declarations
This commit is contained in:
+33
-9
@@ -64,6 +64,9 @@ class ComplexExternalDeclarationsToTopLevelFunctionsLowering(val context: WasmBa
|
|||||||
error("Unknown external element ${element::class}")
|
error("Unknown external element ${element::class}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun visitTypeParameter(declaration: IrTypeParameter) {
|
||||||
|
}
|
||||||
|
|
||||||
override fun visitValueParameter(declaration: IrValueParameter) {
|
override fun visitValueParameter(declaration: IrValueParameter) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,21 +189,22 @@ class ComplexExternalDeclarationsToTopLevelFunctionsLowering(val context: WasmBa
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun processFunctionOrConstructor(
|
private val IrFunction.isSetOperator get() =
|
||||||
|
(this is IrSimpleFunction) && isOperator && name.asString() == "set"
|
||||||
|
|
||||||
|
private val IrFunction.isGetOperator get() =
|
||||||
|
(this is IrSimpleFunction) && isOperator && name.asString() == "get"
|
||||||
|
|
||||||
|
private fun createJsCodeForFunction(
|
||||||
function: IrFunction,
|
function: IrFunction,
|
||||||
name: Name,
|
numDefaultParameters: Int,
|
||||||
returnType: IrType,
|
|
||||||
isConstructor: Boolean,
|
isConstructor: Boolean,
|
||||||
jsFunctionReference: String
|
jsFunctionReference: String
|
||||||
) {
|
): String {
|
||||||
val dispatchReceiver = function.dispatchReceiverParameter
|
val dispatchReceiver = function.dispatchReceiverParameter
|
||||||
val numValueParameters = function.valueParameters.size
|
val numValueParameters = function.valueParameters.size
|
||||||
|
|
||||||
|
return buildString {
|
||||||
val numDefaultParameters =
|
|
||||||
numDefaultParametersForExternalFunction(function)
|
|
||||||
|
|
||||||
val jsCode = buildString {
|
|
||||||
append("(")
|
append("(")
|
||||||
if (dispatchReceiver != null) {
|
if (dispatchReceiver != null) {
|
||||||
append("_this, ")
|
append("_this, ")
|
||||||
@@ -238,6 +242,26 @@ class ComplexExternalDeclarationsToTopLevelFunctionsLowering(val context: WasmBa
|
|||||||
}
|
}
|
||||||
append(")")
|
append(")")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun processFunctionOrConstructor(
|
||||||
|
function: IrFunction,
|
||||||
|
name: Name,
|
||||||
|
returnType: IrType,
|
||||||
|
isConstructor: Boolean,
|
||||||
|
jsFunctionReference: String
|
||||||
|
) {
|
||||||
|
val dispatchReceiver = function.dispatchReceiverParameter
|
||||||
|
|
||||||
|
val numDefaultParameters =
|
||||||
|
numDefaultParametersForExternalFunction(function)
|
||||||
|
|
||||||
|
val jsCode = when {
|
||||||
|
function.isSetOperator -> "(_this, i, value) => _this[i] = value"
|
||||||
|
function.isGetOperator -> "(_this, i) => _this[i]"
|
||||||
|
else -> createJsCodeForFunction(function, numDefaultParameters, isConstructor, jsFunctionReference)
|
||||||
|
}
|
||||||
|
|
||||||
val res = createExternalJsFunction(
|
val res = createExternalJsFunction(
|
||||||
name,
|
name,
|
||||||
"_\$external_fun",
|
"_\$external_fun",
|
||||||
|
|||||||
Reference in New Issue
Block a user