[Wasm] Wasi stdlib implementation

KT-56608
This commit is contained in:
Igor Yakovlev
2023-07-31 14:27:09 +02:00
committed by Zalim Bashorov
parent 090f393f97
commit 8cc0660693
61 changed files with 817 additions and 103 deletions
@@ -1,62 +0,0 @@
package test.js
import kotlin.js.*
import kotlin.test.*
internal fun jsAsyncFoo(): Promise<JsAny?> =
js("(async () => 'foo')()")
internal fun jsFoo(): JsAny =
js("'foo'")
var state: JsAny? = null
class MyThrowable : Throwable()
class AsyncTest {
@Test
fun test1(): Promise<JsAny?> {
var thenExecuted = false
val p = jsAsyncFoo().then { value ->
state = value
thenExecuted = true
null
}
assertFalse(thenExecuted)
return p
}
@Test
fun test2(): Promise<JsAny?> {
assertEquals(state, jsFoo())
var thenExecuted = false
val p = jsAsyncFoo().then {
assertEquals(state, jsFoo())
thenExecuted = true
null
}.then {
assertEquals(state, jsFoo())
thenExecuted = true
null
}
assertFalse(thenExecuted)
return p
}
@Test
fun testJsValueToThrowableOrNull1(): Promise<JsAny?> {
val p = jsAsyncFoo().then {
throw MyThrowable()
}.catch { e ->
assert(e.toThrowableOrNull() is MyThrowable)
null
}
return p
}
@Test
fun testJsValueToThrowableOrNull2() {
val e = MyThrowable()
assertEquals((e.toJsReference()).toThrowableOrNull(), e)
}
}
@@ -3,9 +3,6 @@ package test.wasm.unsafe
import kotlin.wasm.unsafe.*
import kotlin.test.*
private fun jsConcatStrings(a: String, b: String): String =
js("a + b")
@OptIn(UnsafeWasmMemoryApi::class)
class MemoryAllocationTest {
val pageSize = 65_536
@@ -128,14 +125,6 @@ class MemoryAllocationTest {
assertTrue(max1 < min1_1)
}
@Test
fun testJsIntropInsideAllocations() {
withScopedMemoryAllocator { allocator ->
assertEquals(jsConcatStrings("str1", "str2"), "str1str2")
allocator.allocate(10)
}
}
@Test
fun testNestedAllocatorThrows() {
var leakedAllocator1: MemoryAllocator? = null