From 01fcc84d73ee77a722914067f2f146b07a86d887 Mon Sep 17 00:00:00 2001 From: Svyatoslav Kuzmich Date: Sat, 14 Jan 2023 20:00:08 +0100 Subject: [PATCH] [Wasm] Refactor callingWasmDirectly.kt test from @JsFun to @WasmImport --- .../boxWasmJsInterop/callingWasmDirectly.kt | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/compiler/testData/codegen/boxWasmJsInterop/callingWasmDirectly.kt b/compiler/testData/codegen/boxWasmJsInterop/callingWasmDirectly.kt index 1b2ea27dc66..d000f31dead 100644 --- a/compiler/testData/codegen/boxWasmJsInterop/callingWasmDirectly.kt +++ b/compiler/testData/codegen/boxWasmJsInterop/callingWasmDirectly.kt @@ -1,27 +1,31 @@ // TARGET_BACKEND: WASM +// FILE: wasmModule.mjs + +/* + (module + (func (export "addTwo") (param i32 i32) (result i32) + local.get 0 + local.get 1 + i32.add)) +*/ +let bytes = [0, 97, 115, 109, 1, 0, 0, 0, 1, 7, 1, 96, 2, 127, 127, 1, 127, 3, +2, 1, 0, 7, 10, 1, 6, 97, 100, 100, 84, 119, 111, 0, 0, 10, 9, 1, +7, 0, 32, 0, 32, 1, 106, 11, 0, 10, 4, 110, 97, 109, 101, 2, 3, 1, 0, 0]; +let buffer = (new Int8Array(bytes)).buffer; +let module = new WebAssembly.Module(buffer); +let instance = new WebAssembly.Instance(module); +export let addTwo = instance.exports.addTwo; + +// FILE: main.kt + +import kotlin.wasm.WasmImport /* Here we pass export of another Wasm module to our import directly without JS layer. This enables strict type check without JS conversons. For instance, recursion groups of function types must fully match. - -(module - (func (export "addTwo") (param i32 i32) (result i32) - local.get 0 - local.get 1 - i32.add)) */ -@JsFun(""" -(() => { - let bytes = [0, 97, 115, 109, 1, 0, 0, 0, 1, 7, 1, 96, 2, 127, 127, 1, 127, 3, - 2, 1, 0, 7, 10, 1, 6, 97, 100, 100, 84, 119, 111, 0, 0, 10, 9, 1, - 7, 0, 32, 0, 32, 1, 106, 11, 0, 10, 4, 110, 97, 109, 101, 2, 3, 1, 0, 0]; - let buffer = (new Int8Array(bytes)).buffer; - let module = new WebAssembly.Module(buffer); - let instance = new WebAssembly.Instance(module); - return instance.exports.addTwo; -})() -""") +@WasmImport("./wasmModule.mjs") external fun addTwo(a: Int, b: Int): Int fun box(): String {