Explicitly declare stability levels of declarations in kotlinx.cinterop package
* @ExperimentalForeignApi for all declarations that operate on
unmanaged memory (i.e. pointers and references)
* @BetaInteropApi for the rest of the interoperability declarations,
namely Swift/CInterop-specific interfaces and convenience-functions
### Implementation details
* Some typealiases are not marked explicitly because it crashes the compiler,
yet their experimentality is properly propagated
* License header is adjusted where it previously had been existing
* Deprecated with ERROR interop declarations that are deprecated for more than
two years are removed
* WASM target interop declarations are deprecated
* Deliberately make Boolean.toByte and Byte.toBoolean foreign-experimental to scare
people away
^KT-57728 fixed
Merge-request: KT-MR-9788
Merged-by: Vsevolod Tolstopyatov <qwwdfsad@gmail.com>
This commit is contained in:
committed by
Space Team
parent
82611ad124
commit
f4e8ae5191
@@ -14,7 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
@file:Suppress("DEPRECATION") // RetainForTarget
|
||||
@file:Suppress("DEPRECATION", "TYPEALIAS_EXPANSION_DEPRECATION") // Everything is scheduled for removal
|
||||
@file:OptIn(ExperimentalForeignApi::class)
|
||||
|
||||
package kotlinx.wasm.jsinterop
|
||||
|
||||
@@ -22,49 +23,66 @@ import kotlin.native.*
|
||||
import kotlin.native.internal.*
|
||||
import kotlinx.cinterop.*
|
||||
|
||||
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||
typealias Arena = Int
|
||||
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||
typealias Object = Int
|
||||
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||
typealias Pointer = Int
|
||||
|
||||
private const val WASM_TARGET_IS_DEPRECATED = "K/N WASM target and all related API is deprecated for removal. " +
|
||||
"See https://blog.jetbrains.com/kotlin/2023/02/update-regarding-kotlin-native-targets for additional details"
|
||||
|
||||
/**
|
||||
* @Retain annotation is required to preserve functions from internalization and DCE.
|
||||
*/
|
||||
@RetainForTarget("wasm32")
|
||||
@GCUnsafeCall("Konan_js_allocateArena")
|
||||
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||
external public fun allocateArena(): Arena
|
||||
|
||||
@RetainForTarget("wasm32")
|
||||
@GCUnsafeCall("Konan_js_freeArena")
|
||||
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||
external public fun freeArena(arena: Arena)
|
||||
|
||||
@RetainForTarget("wasm32")
|
||||
@GCUnsafeCall("Konan_js_pushIntToArena")
|
||||
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||
external public fun pushIntToArena(arena: Arena, value: Int)
|
||||
|
||||
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||
const val upperWord = 0xffffffff.toLong() shl 32
|
||||
|
||||
@ExportForCppRuntime
|
||||
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||
fun doubleUpper(value: Double): Int =
|
||||
((value.toBits() and upperWord) ushr 32) .toInt()
|
||||
|
||||
@ExportForCppRuntime
|
||||
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||
fun doubleLower(value: Double): Int =
|
||||
(value.toBits() and 0x00000000ffffffff) .toInt()
|
||||
|
||||
@RetainForTarget("wasm32")
|
||||
@GCUnsafeCall("ReturnSlot_getDouble")
|
||||
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||
external public fun ReturnSlot_getDouble(): Double
|
||||
|
||||
@RetainForTarget("wasm32")
|
||||
@GCUnsafeCall("Kotlin_String_utf16pointer")
|
||||
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||
external public fun stringPointer(message: String): Pointer
|
||||
|
||||
@RetainForTarget("wasm32")
|
||||
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||
@GCUnsafeCall("Kotlin_String_utf16length")
|
||||
external public fun stringLengthBytes(message: String): Int
|
||||
|
||||
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||
typealias KtFunction <R> = ((ArrayList<JsValue>)->R)
|
||||
|
||||
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||
fun <R> wrapFunction(func: KtFunction<R>): Int {
|
||||
val ptr: Long = StableRef.create(func).asCPointer().toLong()
|
||||
return ptr.toInt() // TODO: LP64 unsafe.
|
||||
@@ -72,6 +90,7 @@ fun <R> wrapFunction(func: KtFunction<R>): Int {
|
||||
|
||||
@RetainForTarget("wasm32")
|
||||
@ExportForCppRuntime("Konan_js_runLambda")
|
||||
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||
fun runLambda(pointer: Int, argumentsArena: Arena, argumentsArenaSize: Int): Int {
|
||||
val arguments = arrayListOf<JsValue>()
|
||||
for (i in 0 until argumentsArenaSize) {
|
||||
@@ -87,6 +106,7 @@ fun runLambda(pointer: Int, argumentsArena: Arena, argumentsArenaSize: Int): Int
|
||||
return result.index
|
||||
}
|
||||
|
||||
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||
open class JsValue(val arena: Arena, val index: Object) {
|
||||
fun getInt(property: String): Int {
|
||||
return getInt(ArenaManager.currentArena, index, stringPointer(property), stringLengthBytes(property))
|
||||
@@ -96,6 +116,7 @@ open class JsValue(val arena: Arena, val index: Object) {
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||
open class JsArray(arena: Arena, index: Object): JsValue(arena, index) {
|
||||
constructor(jsValue: JsValue): this(jsValue.arena, jsValue.index)
|
||||
operator fun get(index: Int): JsValue {
|
||||
@@ -108,37 +129,46 @@ open class JsArray(arena: Arena, index: Object): JsValue(arena, index) {
|
||||
|
||||
@RetainForTarget("wasm32")
|
||||
@GCUnsafeCall("Konan_js_getInt")
|
||||
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||
external public fun getInt(arena: Arena, obj: Object, propertyPtr: Pointer, propertyLen: Int): Int;
|
||||
|
||||
@RetainForTarget("wasm32")
|
||||
@GCUnsafeCall("Konan_js_getProperty")
|
||||
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||
external public fun Konan_js_getProperty(arena: Arena, obj: Object, propertyPtr: Pointer, propertyLen: Int): Int;
|
||||
|
||||
@RetainForTarget("wasm32")
|
||||
@GCUnsafeCall("Konan_js_setFunction")
|
||||
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||
external public fun setFunction(arena: Arena, obj: Object, propertyName: Pointer, propertyLength: Int , function: Int)
|
||||
|
||||
@RetainForTarget("wasm32")
|
||||
@GCUnsafeCall("Konan_js_setString")
|
||||
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||
external public fun setString(arena: Arena, obj: Object, propertyName: Pointer, propertyLength: Int, stringPtr: Pointer, stringLength: Int )
|
||||
|
||||
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||
fun setter(obj: JsValue, property: String, string: String) {
|
||||
setString(obj.arena, obj.index, stringPointer(property), stringLengthBytes(property), stringPointer(string), stringLengthBytes(string))
|
||||
}
|
||||
|
||||
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||
fun setter(obj: JsValue, property: String, lambda: KtFunction<Unit>) {
|
||||
val pointer = wrapFunction(lambda);
|
||||
setFunction(obj.arena, obj.index, stringPointer(property), stringLengthBytes(property), pointer)
|
||||
}
|
||||
|
||||
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||
fun JsValue.setter(property: String, lambda: KtFunction<Unit>) {
|
||||
setter(this, property, lambda)
|
||||
}
|
||||
|
||||
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||
fun JsValue.setter(property: String, string: String) {
|
||||
setter(this, property, string)
|
||||
}
|
||||
|
||||
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||
object ArenaManager {
|
||||
val globalArena = allocateArena()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user