[Wasm] Add uninstantiated MJS wrapper
It allows * Custom imports * Ability to skip initializer
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
// TARGET_BACKEND: WASM
|
||||
|
||||
// FILE: wasmImport.kt
|
||||
import kotlin.wasm.WasmImport
|
||||
|
||||
@WasmImport("foo")
|
||||
external fun inc(x: Int): Int
|
||||
|
||||
@JsExport
|
||||
fun myBox(): String {
|
||||
if (inc(5) != 6) return "KFail1"
|
||||
return "OK"
|
||||
}
|
||||
|
||||
var initialized: Int = 0
|
||||
|
||||
@JsExport
|
||||
fun getInitialized(): Int = initialized
|
||||
|
||||
fun main() {
|
||||
initialized = 100
|
||||
}
|
||||
|
||||
// FILE: entry.mjs
|
||||
import { instantiate } from "./index.uninstantiated.mjs";
|
||||
|
||||
let inc = x => x + 1;
|
||||
|
||||
let imports = {
|
||||
"foo": { inc },
|
||||
}
|
||||
|
||||
let { exports } = await instantiate(imports, /*runInitializer=*/false);
|
||||
if (exports.getInitialized() !== 0) {
|
||||
throw "Fail1"
|
||||
}
|
||||
exports.__init();
|
||||
if (exports.getInitialized() !== 100) {
|
||||
throw "Fail2"
|
||||
}
|
||||
|
||||
if (exports.myBox() != "OK") {
|
||||
throw "Fail3"
|
||||
}
|
||||
Reference in New Issue
Block a user