Conversation
| internal fun JsArray<*>.isEmpty() = length == 0 | ||
| internal fun JsArray<*>.isNotEmpty() = !isEmpty() |
There was a problem hiding this comment.
Does JsArray not already have these functions?
There was a problem hiding this comment.
Not in webMain or wasmMain. You do get them in jsMain (where it's just a typealias for Array), but the common interface is quite limited.
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package kotlin.js
/** JavaScript Array for WasmJs Interop */
@SinceKotlin("2.2")
@ExperimentalWasmJsInterop
public expect class JsArray<T : JsAny?> : JsAny
@SinceKotlin("2.2")
@ExperimentalWasmJsInterop
public expect fun <T: JsAny?> JsArray(): JsArray<T>
@SinceKotlin("2.2")
@ExperimentalWasmJsInterop
public expect val JsArray<*>.length: Int
@SinceKotlin("2.2")
@ExperimentalWasmJsInterop
public expect operator fun <T : JsAny?> JsArray<T>.get(index: Int): T?
@SinceKotlin("2.2")
@ExperimentalWasmJsInterop
public expect operator fun <T : JsAny?> JsArray<T>.set(index: Int, value: T)
/** Returns a new [Array] containing all the elements of this [JsArray]. */
@SinceKotlin("2.2")
@ExperimentalWasmJsInterop
public expect fun <T : JsAny?> JsArray<T>.toArray(): Array<T>
/** Returns a new [JsArray] containing all the elements of this [Array]. */
@SinceKotlin("2.2")
@ExperimentalWasmJsInterop
public expect fun <T : JsAny?> Array<T>.toJsArray(): JsArray<T>
/** Returns a new [List] containing all the elements of this [JsArray]. */
@SinceKotlin("2.2")
@ExperimentalWasmJsInterop
public expect fun <T : JsAny?> JsArray<T>.toList(): List<T>
/** Returns a new [JsArray] containing all the elements of this [List]. */
@SinceKotlin("2.2")
@ExperimentalWasmJsInterop
public expect fun <T : JsAny?> List<T>.toJsArray(): JsArray<T>
kable-core/src/androidMain/kotlin/BluetoothDeviceAndroidPeripheral.kt
Outdated
Show resolved
Hide resolved
| private val watchAdvertisements: JsAny? = | ||
| js("BluetoothDevice.prototype.watchAdvertisements") | ||
|
|
||
| private val unwatchAdvertisements: JsAny? = | ||
| js("BluetoothDevice.prototype.unwatchAdvertisements") | ||
|
|
There was a problem hiding this comment.
These should probably be marked with get() to keep the previous lazy behavior in associated can.. vals?
| private val watchAdvertisements: JsAny? = | |
| js("BluetoothDevice.prototype.watchAdvertisements") | |
| private val unwatchAdvertisements: JsAny? = | |
| js("BluetoothDevice.prototype.unwatchAdvertisements") | |
| private val watchAdvertisements: JsAny? | |
| get() = js("BluetoothDevice.prototype.watchAdvertisements") | |
| private val unwatchAdvertisements: JsAny? | |
| get() = js("BluetoothDevice.prototype.unwatchAdvertisements") | |
There was a problem hiding this comment.
I wasn't sure how to handle these. Trying to keep the get() = syntax produces the following error:
e: <path>/WatchingAdvertisementsSupport.kt:8:13 Calls to 'js(code)' must be a single expression inside a top-level function body or a property initializer in Kotlin/Wasm.
I erred on the side of call it once and store the value. I could change it over to a fun which would preserve behavior more closely, but it's kind of ugly to add the parenthesis? 🤷 Happy to change it if you prefer.
| jna = "5.18.1" | ||
| jvm-toolchain = "17" | ||
| kotlin = "2.2.20" | ||
| kotlin = "2.2.21" |
There was a problem hiding this comment.
This is fine, just curious if this bump was needed?
There was a problem hiding this comment.
2.2.21 contained some fixes around exception handling for WASM in Safari based browsers
| /** Wrapper around `kotlinx.coroutines.await` which exists in both js and wasm, but has no expect-actual. */ | ||
| internal expect suspend fun <T : JsAny?> Promise<T>.await(): T |
There was a problem hiding this comment.
Wow, wild that this isn't provided for us in webMain world. 🤦
Adds support for Kotlin/Wasm. Tested that Sensortag (see: JuulLabs/sensortag#531) works on both JS and WasmJS targets.
Highest risk in this PR is probably around exception handling. I think I got the pattern correct, it's just the place I'm least confident about and hard to test.
Solves #765