[Wasm] Add JS interop tests

This commit is contained in:
Svyatoslav Kuzmich
2021-09-13 10:57:41 +03:00
parent a32b86d016
commit 0abc798da9
9 changed files with 200 additions and 18 deletions
+25
View File
@@ -0,0 +1,25 @@
// FILE: externals.js
function createObject() {
return {};
}
function setX(obj, x) {
obj.x = x;
}
function getX(obj) {
return obj.x;
}
// FILE: externals.kt
external interface Obj
external fun createObject(): Obj
external fun setX(obj: Obj, x: Int)
external fun getX(obj: Obj): Int
fun box(): String {
val obj = createObject()
setX(obj, 100)
if (getX(obj) != 100) return "Fail 2"
return "OK"
}
+19
View File
@@ -0,0 +1,19 @@
// MODULE: main
// FILE: externals.kt
class C(val x: Int)
@JsExport
fun makeC(x: Int): C = C(x)
@JsExport
fun getX(c: C): Int = c.x
fun box(): String = "OK"
// FILE: jsExport__after.js
const c = main.makeC(300);
if (main.getX(c) !== 300) {
throw "Fail 1";
}