[K/N] Remove jsinterop because K/N wasm32 target is removed ^KT-59008

See https://kotl.in/native-targets-tiers for details
This commit is contained in:
Alexander Shabalin
2023-08-14 11:16:52 +02:00
committed by Space Team
parent 857bfeb92c
commit 3ec4f2e0ee
15 changed files with 46 additions and 1299 deletions
@@ -1,97 +0,0 @@
/*
* Copyright 2010-2018 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
konan.libraries.push ({
arenas: new Map(),
nextArena: 0,
Konan_js_allocateArena: function (array) {
var index = konan_dependencies.env.nextArena++;
konan_dependencies.env.arenas.set(index, array || []);
return index;
},
Konan_js_freeArena: function(arenaIndex) {
var arena = konan_dependencies.env.arenas.get(arenaIndex);
arena.forEach(function(element, index) {
arena[index] = null;
});
konan_dependencies.env.arenas.delete(arenaIndex);
},
Konan_js_pushIntToArena: function (arenaIndex, value) {
var arena = konan_dependencies.env.arenas.get(arenaIndex);
arena.push(value);
return arena.length - 1;
},
Konan_js_addObjectToArena: function (arenaIndex, object) {
var arena = konan_dependencies.env.arenas.get(arenaIndex);
arena.push(object);
return arena.length - 1;
},
Konan_js_wrapLambda: function (functionArenaIndex, index) {
return (function () {
var functionArena = konan_dependencies.env.arenas.get(functionArenaIndex);
// convert Arguments to an array
// to be provided by launcher.js
var argumentArenaIndex = konan_dependencies.env.Konan_js_allocateArena(Array.prototype.slice.call(arguments));
var resultIndex = instance.exports.Konan_js_runLambda(index, argumentArenaIndex, arguments.length);
var result = kotlinObject(argumentArenaIndex, resultIndex);
konan_dependencies.env.Konan_js_freeArena(argumentArenaIndex);
return result;
});
},
Konan_js_getInt: function(arenaIndex, objIndex, propertyNamePtr, propertyNameLength) {
// TODO: The toUTF16String() is to be resolved by launcher.js runtime.
var property = toUTF16String(propertyNamePtr, propertyNameLength);
var value = kotlinObject(arenaIndex, objIndex)[property];
return value;
},
Konan_js_getProperty: function(arenaIndex, objIndex, propertyNamePtr, propertyNameLength) {
// TODO: The toUTF16String() is to be resolved by launcher.js runtime.
var property = toUTF16String(propertyNamePtr, propertyNameLength);
var arena = konan_dependencies.env.arenas.get(arenaIndex);
var value = arena[objIndex][property];
arena.push(value);
return arena.length - 1;
},
Konan_js_setFunction: function (arena, obj, propertyName, propertyNameLength, func) {
var name = toUTF16String(propertyName, propertyNameLength);
kotlinObject(arena, obj)[name] = konan_dependencies.env.Konan_js_wrapLambda(arena, func);
},
Konan_js_setString: function (arena, obj, propertyName, propertyNameLength, stringPtr, stringLength) {
var name = toUTF16String(propertyName, propertyNameLength);
var string = toUTF16String(stringPtr, stringLength);
kotlinObject(arena, obj)[name] = string;
},
});
// TODO: This is just a shorthand notation.
function kotlinObject(arenaIndex, objectIndex) {
var arena = konan_dependencies.env.arenas.get(arenaIndex);
if (typeof arena == "undefined") {
console.log("No arena index " + arenaIndex + "for object" + objectIndex);
console.trace()
}
return arena[objectIndex]
}
function toArena(arenaIndex, object) {
return konan_dependencies.env.Konan_js_addObjectToArena(arenaIndex, object);
}
@@ -14,7 +14,7 @@
* limitations under the License.
*/
@file:Suppress("DEPRECATION", "TYPEALIAS_EXPANSION_DEPRECATION") // Everything is scheduled for removal
@file:Suppress("DEPRECATION_ERROR", "TYPEALIAS_EXPANSION_DEPRECATION_ERROR", "UNUSED_PARAMETER") // Everything is scheduled for removal
@file:OptIn(ExperimentalForeignApi::class)
package kotlinx.wasm.jsinterop
@@ -23,74 +23,60 @@ import kotlin.native.*
import kotlin.native.internal.*
import kotlinx.cinterop.*
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.ERROR)
typealias Arena = Int
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.ERROR)
typealias Object = Int
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.ERROR)
typealias Pointer = Int
private const val WASM_TARGET_IS_DEPRECATED = "K/N WASM target and all related API is deprecated for removal. " +
private const val WASM_TARGET_IS_DEPRECATED = "K/N WASM target was removed 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
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.ERROR)
public fun allocateArena(): Arena = error(WASM_TARGET_IS_DEPRECATED)
@RetainForTarget("wasm32")
@GCUnsafeCall("Konan_js_freeArena")
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
external public fun freeArena(arena: Arena)
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.ERROR)
public fun freeArena(arena: Arena) { error(WASM_TARGET_IS_DEPRECATED) }
@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.ERROR)
public fun pushIntToArena(arena: Arena, value: Int) { error(WASM_TARGET_IS_DEPRECATED) }
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.ERROR)
const val upperWord = 0xffffffff.toLong() shl 32
@ExportForCppRuntime
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.ERROR)
fun doubleUpper(value: Double): Int =
((value.toBits() and upperWord) ushr 32) .toInt()
@ExportForCppRuntime
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.ERROR)
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
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.ERROR)
public fun ReturnSlot_getDouble(): Double = error(WASM_TARGET_IS_DEPRECATED)
@RetainForTarget("wasm32")
@GCUnsafeCall("Kotlin_String_utf16pointer")
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.ERROR)
external public fun stringPointer(message: String): Pointer
@RetainForTarget("wasm32")
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.ERROR)
@GCUnsafeCall("Kotlin_String_utf16length")
external public fun stringLengthBytes(message: String): Int
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.ERROR)
typealias KtFunction <R> = ((ArrayList<JsValue>)->R)
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.ERROR)
fun <R> wrapFunction(func: KtFunction<R>): Int {
val ptr: Long = StableRef.create(func).asCPointer().toLong()
return ptr.toInt() // TODO: LP64 unsafe.
}
@RetainForTarget("wasm32")
@ExportForCppRuntime("Konan_js_runLambda")
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.ERROR)
fun runLambda(pointer: Int, argumentsArena: Arena, argumentsArenaSize: Int): Int {
val arguments = arrayListOf<JsValue>()
for (i in 0 until argumentsArenaSize) {
@@ -106,7 +92,7 @@ fun runLambda(pointer: Int, argumentsArena: Arena, argumentsArenaSize: Int): Int
return result.index
}
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.ERROR)
open class JsValue(val arena: Arena, val index: Object) {
fun getInt(property: String): Int {
return getInt(ArenaManager.currentArena, index, stringPointer(property), stringLengthBytes(property))
@@ -116,7 +102,7 @@ open class JsValue(val arena: Arena, val index: Object) {
}
}
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.ERROR)
open class JsArray(arena: Arena, index: Object): JsValue(arena, index) {
constructor(jsValue: JsValue): this(jsValue.arena, jsValue.index)
operator fun get(index: Int): JsValue {
@@ -127,48 +113,40 @@ open class JsArray(arena: Arena, index: Object): JsValue(arena, index) {
get() = this.getInt("length")
}
@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;
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.ERROR)
public fun getInt(arena: Arena, obj: Object, propertyPtr: Pointer, propertyLen: Int): Int = error(WASM_TARGET_IS_DEPRECATED)
@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;
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.ERROR)
public fun Konan_js_getProperty(arena: Arena, obj: Object, propertyPtr: Pointer, propertyLen: Int): Int = error(WASM_TARGET_IS_DEPRECATED)
@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)
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.ERROR)
public fun setFunction(arena: Arena, obj: Object, propertyName: Pointer, propertyLength: Int , function: Int) { error(WASM_TARGET_IS_DEPRECATED) }
@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.ERROR)
public fun setString(arena: Arena, obj: Object, propertyName: Pointer, propertyLength: Int, stringPtr: Pointer, stringLength: Int ) { error(WASM_TARGET_IS_DEPRECATED) }
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.ERROR)
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)
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.ERROR)
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)
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.ERROR)
fun JsValue.setter(property: String, lambda: KtFunction<Unit>) {
setter(this, property, lambda)
}
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.ERROR)
fun JsValue.setter(property: String, string: String) {
setter(this, property, string)
}
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.ERROR)
object ArenaManager {
val globalArena = allocateArena()