Files
kotlin-fork/compiler/testData/codegen/boxWasmJsInterop/jsExport.kt
T
Svyatoslav Kuzmich 1e91fe155b [Wasm] Restrict types allowed in JS interop
- Prohibit Any, Array and other unsupported non-external types in JS
  interop context
- Add K1 diagnostic
- Update BE testdata

^KT-57136 Fixed
2023-03-16 09:12:07 +00:00

48 lines
849 B
Kotlin
Vendored

// TARGET_BACKEND: WASM
// MODULE: main
// FILE: externals.kt
class C(val x: Int)
@JsExport
fun makeC(x: Int): JsHandle<C> = C(x).toJsHandle()
@JsExport
fun getX(c: JsHandle<C>): Int = c.get().x
@JsExport
fun getString(s: String): String = "Test string $s";
@JsExport
fun isEven(x: Int): Boolean = x % 2 == 0
external interface EI
@JsExport
fun eiAsAny(ei: EI): JsHandle<Any> = ei.toJsHandle()
@JsExport
fun anyAsEI(any: JsHandle<Any>): EI = any.get() as EI
fun box(): String = "OK"
// FILE: entry.mjs
import main from "./index.mjs"
const c = main.makeC(300);
if (main.getX(c) !== 300) {
throw "Fail 1";
}
if (main.getString("2") !== "Test string 2") {
throw "Fail 2";
}
if (main.isEven(31) !== false || main.isEven(10) !== true) {
throw "Fail 3";
}
if (main.anyAsEI(main.eiAsAny({x:10})).x !== 10) {
throw "Fail 4";
}