[Wasm] Disable interop adapters for WasmImport

Merge-request: KT-MR-8152
This commit is contained in:
Svyatoslav Kuzmich
2022-12-28 17:33:51 +00:00
committed by Space Team
parent 34a49b3f56
commit 9d099348ba
2 changed files with 18 additions and 1 deletions
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.backend.wasm.WasmBackendContext
import org.jetbrains.kotlin.backend.wasm.ir2wasm.isBuiltInWasmRefType
import org.jetbrains.kotlin.backend.wasm.ir2wasm.isExported
import org.jetbrains.kotlin.backend.wasm.ir2wasm.isExternalType
import org.jetbrains.kotlin.backend.wasm.utils.getWasmImportDescriptor
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
import org.jetbrains.kotlin.ir.backend.js.utils.getJsNameOrKotlinName
import org.jetbrains.kotlin.ir.builders.*
@@ -49,6 +50,7 @@ class JsInteropFunctionsLowering(val context: WasmBackendContext) : DeclarationT
if (declaration.isPropertyAccessor) return null
if (declaration.parent !is IrPackageFragment) return null
if (!isExported && !isExternal) return null
if (declaration.getWasmImportDescriptor() != null) return null
check(!(isExported && isExternal)) { "Exported external declarations are not supported: ${declaration.fqNameWhenAvailable}" }
check(declaration.parent !is IrClass) { "Interop members are not supported: ${declaration.fqNameWhenAvailable}" }
@@ -12,11 +12,19 @@ external fun inc2(x: Int): Int
@WasmImport("./bar.mjs", "inc3")
external fun inc3(x: Int): Int
@WasmImport("./bar.mjs", "giveMeNumber")
external fun giveMeNumber(x: Boolean)
@JsExport
fun myBox(): String {
if (inc1(5) != 6) return "KFail1"
if (inc2(5) != 6) return "KFail2"
if (inc3(5) != 6) return "KFail3"
// Test that booleans are translated as i32
giveMeNumber(true)
giveMeNumber(false)
return "OK"
}
@@ -37,7 +45,14 @@ let inc = x => x + 1;
let imports = {
"foo": { inc1 : inc },
"~!@#\$%^&*()_+\`-={}|[]\\\\:\\\";'<>?,./" : { inc2 : inc },
"./bar.mjs" : { inc3 : inc },
"./bar.mjs" : {
inc3 : inc,
giveMeNumber(x) {
if (typeof x !== 'number') {
throw "Not a number!";
}
},
},
}
let { exports } = await instantiate(imports);