[Wasm] Change externRefToAny to make it compatible with SpiderMonkey and V8

It's hard to achieve that without implementing part of `externRefToAny` using an intrinsic. It should be rewritten when all VMs and tools update to the latest spec.

Also, stop using (deprecated) instructions unsupported by SpiderMonkey.

#KT-56166 In-Progress
This commit is contained in:
Zalim Bashorov
2023-01-27 00:34:45 +01:00
parent d1855371a0
commit 885381dd63
6 changed files with 37 additions and 21 deletions
@@ -211,6 +211,7 @@ class WasmSymbols(
val nullableDoubleIeee754Equals = getInternalFunction("nullableDoubleIeee754Equals")
val unsafeGetScratchRawMemory = getInternalFunction("unsafeGetScratchRawMemory")
val returnArgumentIfItIsKotlinAny = getInternalFunction("returnArgumentIfItIsKotlinAny")
val newJsArray = getInternalFunction("newJsArray")
val jsArrayPush = getInternalFunction("jsArrayPush")
@@ -594,11 +594,23 @@ class BodyGenerator(
}
wasmSymbols.unsafeGetScratchRawMemory -> {
body.buildConstI32Symbol(context.scratchMemAddr, location)
}
wasmSymbols.returnArgumentIfItIsKotlinAny -> {
body.buildBlock("returnIfAny", WasmAnyRef) { innerLabel ->
body.buildGetLocal(functionContext.referenceLocal(0), location)
body.buildInstr(WasmOp.EXTERN_INTERNALIZE, location)
body.buildBrInstr(WasmOp.BR_ON_NON_DATA_DEPRECATED, innerLabel, location)
body.buildBrInstr(
WasmOp.BR_ON_CAST_FAIL_DEPRECATED,
innerLabel,
context.referenceGcType(backendContext.irBuiltIns.anyClass),
location
)
body.buildInstr(WasmOp.RETURN, location)
}
}
wasmSymbols.wasmArrayCopy -> {
val immediate = WasmImmediate.GcType(