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