Robert Jaros
03/05/2024, 8:18 AMorg.w3c.fetch.RequestInit()
defined in stdlib like this:
https://github.com/JetBrains/kotlin/blob/master/libraries/stdlib/wasm/js/src/org.w3c/org.w3c.fetch.kt#L107
But as undefined
is null
on Wasm, the generated object contains nulls and the browser doesn't like it:
Exception: TypeError: Window.fetch: 'null' (value of 'cache' member of RequestInit) is not a valid value for enumeration RequestCache.
Robert Jaros
03/05/2024, 3:21 PMRobert Jaros
03/05/2024, 3:24 PMJohn O'Reilly
03/05/2024, 6:56 PMT8522192
03/06/2024, 4:08 AMUncaught (in promise) TypeError: type incompatibility when transforming from/to JS
before? wonder how to solve itZoff
03/06/2024, 12:23 PMDarryl Miles
03/06/2024, 4:50 PMimplementation(project(":web-wasm"), configuration = "webjar")
But a bunch of errors concerning compatibilities are emitted.
I guess the colouring is to record wasm target platform info and ensure compatibility, but I don't think I need this and want to press the feature kill switch on it, and have it just export the JAR.
The only alternative solution I have is to copy the output JAR to somewhere outside of the project tree, and manually use a file JAR reference in dependencies. `implementation(files(layout.projectDirectory.file("../web-wasm-0.0.1-SNAPSHOT-webjar.jar")))``
Alternatively how do I describe the correct and compatible artifact colouring metadata that will allow it to match and be consumed, like a normal sibling dependency.Akram Bensalem
03/07/2024, 6:02 AM"localhist:8080/"
when running `"wasmJsBrowserDevelopmentRun`" ( that will help to control the navigation inside the app).
Meanwhile, it seems that the adding 'webpack.config.d' with the javascript doesn't work at all ?
Even when in the js file I add a simple print in console, it doesn't work !
Do you know how to fix this, please ?Darryl Miles
03/07/2024, 1:16 PMapi(kotlinx("coroutines-core-wasm-js:1.8.0"))
so the GAV axis is long hand
kotlin {
sourceSets {
val wasmJsMain by getting {
api("org.jetbrains.kotlinx:kotlinx-coroutines-core-wasm-js:1.8.0")
}
}
}
For example I see this project https://github.com/JuulLabs/indexeddb has existed sometime, for IndexedDB support, but it does not seem possible to consume it. This is back to the JAR having capability colouring.
The claim is my project has the colour "wasm" but the JAR has the colour "js", when I attempt to add the dependency.
The colouring attribute are termed "org.jetbrains.kotlin.platform.type"
If there such a thing as the following config snippet ? (if so, where is the example project of this?) :
kotlin {
js {
binaries.executable()
browser()
}
sourceSets {
val jsMain by getting {
}
}
}
When I enable this section the "js" part, my "src/commonMain/kotlin/Common.kt" file now has compile errors, as some basic imports are not longer available "org.w3c.fetch.*" and "kotlinx.browser.document". This .kt file is not actively used by the previous project, it exists to probe into understanding what is possible and what APIs exist there.
When I enable this "js" section I see additional items/directory produced, but it fails as the directory "build/js/..." doe s not exist and some Node task fails, jsBrowserProductionWebpack.
So back to where might an example project be demonstrating this ? Why does it fail if I enable it but I have no source files to process, surely it should detect this and emit a no-op valid output that has no functionality.
It is not clear how the "js" section interoperates with the "wasmJs" section, within the same gradle project.Akram Bensalem
03/09/2024, 11:15 PMYan Pujante
03/10/2024, 2:28 PMTom De Decker
03/11/2024, 5:29 PMRobert Jaros
03/11/2024, 11:12 PMDarryl Miles
03/12/2024, 4:51 PM// This snippet is from Kotlin/JS not WasmJS
window.fetch(
url, RequestInit(
method = method,
body = body,
headers = json( // THIS PART: Is there a WASM equivalent to kotlin.js.json
"Content-Type" to "application/json",
"Accept" to "application/json",
"pragma" to "no-cache"
)
)
)
Is it possible to perform something like:
@JsFun("(value) => JSON.stringify(value)")
external fun jsonStringify(value: JsAny?): JsString = definedExternally
How about:
@JsFun("(value, replacer, space) => JSON.stringify(value, replacer, space)")
external fun jsonStringify(value: JsAny?, replacer: (JsString, JsAny?) -> JsAny, space: JsAny): JsString = definedExternally
Robert Jaros
03/12/2024, 6:09 PMKotlin/JS/Node
and Kotlin/Wasm/Node
targets (compiled from exactly the same Kotlin sources). I'm really impressed seeing wasm code running more than 3 times faster (!!!).Robert Jaros
03/12/2024, 6:24 PMDarryl Miles
03/15/2024, 12:54 AMLazar Prijović
03/15/2024, 2:43 PM@OptIn(ExperimentalUnsignedTypes::class, UnsafeWasmMemoryApi::class)
fun wasmSimdShowcase(): UByteArray {
val vector1: Vec128
// (1) We can initialize v128 with the raw memory
withScopedMemoryAllocator { allocator ->
val pointer = allocator.allocate(16)
for (i in 0..15) {
pointer.plus(i).storeByte(0x03)
}
vector1 = pointer.loadV128()
}
// (2) We can initialize v128 with const UBytes
val vector2 = v128OfUBytes(
0x00_u, 0x00_u, 0x00_u, 0x00_u,
0x01_u, 0x02_u, 0x03_u, 0x04_u,
0xA0_u, 0xB0_u, 0xC0_u, 0xD0_u,
0xFF_u, 0xFF_u, 0xFF_u, 0xFF_u
)
return withScopedMemoryAllocator { allocator ->
val pointer = allocator.allocate(16)
// (3) We can add one v128 to another one and (4) store v128 within the raw memory
pointer.storeV128(vector1 + vector2)
val result = UByteArray(16)
for (i in 0..15) {
result[i] = (pointer + i).loadByte().toUByte()
}
result
}
println(wasmSimdShowcase().joinToString { it.toHexString() })
// Output:
// 03, 03, 03, 03, 04, 05, 06, 07, a3, b3, c3, d3, 02, 02, 02, 02
}
The WAT output of wasmSimdShowcase
function:
Interesting parts:
(local $0_vector1 v128)
(local $9_vector2 v128)
...
local.get $5_pointer ;; type: kotlin.wasm.unsafe.Pointer
v128.load align=1
local.set $0_vector1 ;; type: kotlin.wasm.internal.vectypes.Vec128
...
v128.const 0 0 0 0 1 2 3 4 160 176 192 208 255 255 255 255
local.set $9_vector2
...
;; Inlined call of `kotlin.wasm.internal.vectypes.Vec128.plus`
block (result v128)
nop
local.get $0_vector1 ;; type: kotlin.wasm.internal.vectypes.Vec128
local.set $15_this
local.get $9_vector2 ;; type: kotlin.wasm.internal.vectypes.Vec128
local.set $16_other
local.get $15_this ;; type: kotlin.wasm.internal.vectypes.Vec128
local.get $16_other ;; type: kotlin.wasm.internal.vectypes.Vec128
i8x16.add
br 0
end
v128.store align=1
The full WAT output:
https://gist.github.com/madrazzl3/704e96cba51a86221f9a862fae25a74exxfast
03/16/2024, 12:35 AMAbdul Basit
03/16/2024, 7:53 AMsecret.properties
and in CI/CD, i have added variables.
Now when wasmJsBrowserProductionExecutableDistributeResources
task is run, and i try to push the files, i get:
—— WorkOS Production API Key —————————————————————————
remote: locations:
remote: - commit: e1945e4582844cf57dbfd6c04b1d7d8d79d11c6d
remote: path: docs/skiko.wasm:40175
Now how i can obfuscate/protect my secret in skiko.wasm
?
or is there any way around ?Robert Jaros
03/18/2024, 9:53 AMwasmJS
or uses JS RegExp
class like Kotlin/JS?hamyn
03/18/2024, 10:14 PMsqldelight
in my kmp project with desktop
+ mobile
and wasmjs
targets sharing UI and my project won't build⬇️, since sqldelight
doesn't support wasm yet, how can I exclude the sqldelight requirement from wasm target only ? I will be using a different approach for persistence with wasm ui, but I haven't given much though to it yet.Matt Nelson
03/19/2024, 10:47 AMLaxystem
03/19/2024, 4:48 PMfun foo() = js("console.log('foo')")
Kotlin generates:
(func $js_code.foo (;3873;) (import "js_code" "foo"))
And (in an object containing all functions exported to Wasm):
'foo' : () => console.log('foo')
Is it possible to provide the foo
JS function the WebAssembly.Instance
?
That way, one can call the function named `bar`:
'foo': (instance) => instance.exports.bar
bashor
03/20/2024, 7:18 PMGopi S
03/25/2024, 9:21 AMCharlie Tapping
03/25/2024, 5:51 PMJose Garcia
03/26/2024, 3:59 PMsebastian.s.rieger
03/27/2024, 6:31 AMsoufianehamama9
03/29/2024, 7:08 AM