[Wasm] Migrate usages of @JsFun to js("code")
This commit is contained in:
committed by
Space Team
parent
7a04999e4a
commit
7175b9f31c
@@ -40,5 +40,5 @@ public open class Throwable(open val message: String?, open val cause: kotlin.Th
|
||||
}
|
||||
}
|
||||
|
||||
@JsFun("() => new Error().stack")
|
||||
private external fun captureStackTrace(): ExternalInterfaceType
|
||||
private fun captureStackTrace(): ExternalInterfaceType =
|
||||
js("new Error().stack")
|
||||
|
||||
@@ -5,16 +5,16 @@
|
||||
|
||||
package kotlin.wasm.internal
|
||||
|
||||
@JsFun(
|
||||
"""(message, wasmTypeName, stack) => {
|
||||
const error = new Error();
|
||||
error.message = message;
|
||||
error.name = wasmTypeName;
|
||||
error.stack = stack;
|
||||
throw error;
|
||||
}"""
|
||||
)
|
||||
private external fun throwJsError(message: String?, wasmTypeName: String?, stack: String): Nothing
|
||||
@Suppress("UNUSED_PARAMETER") // TODO: Remove after bootstrap update
|
||||
private fun throwJsError(message: String?, wasmTypeName: String?, stack: String): Nothing {
|
||||
js("""
|
||||
const error = new Error();
|
||||
error.message = message;
|
||||
error.name = wasmTypeName;
|
||||
error.stack = stack;
|
||||
throw error;
|
||||
""")
|
||||
}
|
||||
|
||||
internal fun throwAsJsException(t: Throwable): Nothing {
|
||||
throwJsError(t.message, t::class.simpleName, t.stackTraceToString())
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@file:Suppress("UNUSED_PARAMETER") // TODO: Remove after bootstrap update
|
||||
|
||||
package kotlin.wasm.internal
|
||||
|
||||
import kotlin.wasm.internal.reftypes.anyref
|
||||
@@ -31,6 +33,7 @@ internal class JsExternalBox @WasmPrimitiveConstructor constructor(val ref: Exte
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
//language=js
|
||||
@JsFun("""
|
||||
(() => {
|
||||
@@ -85,41 +88,41 @@ return (obj) => {
|
||||
)
|
||||
private external fun externrefHashCode(ref: ExternalInterfaceType): Int
|
||||
|
||||
@JsFun("ref => String(ref)")
|
||||
private external fun externrefToString(ref: ExternalInterfaceType): String
|
||||
private fun externrefToString(ref: ExternalInterfaceType): String =
|
||||
js("String(ref)")
|
||||
|
||||
@JsFun("ref => Number(ref)")
|
||||
private external fun externrefToInt(ref: ExternalInterfaceType): Int
|
||||
private fun externrefToInt(ref: ExternalInterfaceType): Int =
|
||||
js("Number(ref)")
|
||||
|
||||
@JsFun("ref => Number(ref)")
|
||||
private external fun externrefToLong(ref: ExternalInterfaceType): Long
|
||||
private fun externrefToLong(ref: ExternalInterfaceType): Long =
|
||||
js("Number(ref)")
|
||||
|
||||
@JsFun("ref => Boolean(ref)")
|
||||
private external fun externrefToBoolean(ref: ExternalInterfaceType): Boolean
|
||||
private fun externrefToBoolean(ref: ExternalInterfaceType): Boolean =
|
||||
js("Boolean(ref)")
|
||||
|
||||
@JsFun("ref => Number(ref)")
|
||||
private external fun externrefToFloat(ref: ExternalInterfaceType): Float
|
||||
private fun externrefToFloat(ref: ExternalInterfaceType): Float =
|
||||
js("Number(ref)")
|
||||
|
||||
@JsFun("ref => Number(ref)")
|
||||
private external fun externrefToDouble(ref: ExternalInterfaceType): Double
|
||||
private fun externrefToDouble(ref: ExternalInterfaceType): Double =
|
||||
js("Number(ref)")
|
||||
|
||||
@JsFun("x => x")
|
||||
private external fun intToExternref(x: Int): ExternalInterfaceType
|
||||
private fun intToExternref(x: Int): ExternalInterfaceType =
|
||||
js("x")
|
||||
|
||||
@JsFun("x => x")
|
||||
private external fun longToExternref(x: Long): ExternalInterfaceType
|
||||
private fun longToExternref(x: Long): ExternalInterfaceType =
|
||||
js("x")
|
||||
|
||||
@JsFun("x => x")
|
||||
private external fun booleanToExternref(x: Boolean): ExternalInterfaceType
|
||||
private fun booleanToExternref(x: Boolean): ExternalInterfaceType =
|
||||
js("x")
|
||||
|
||||
@JsFun("x => x")
|
||||
private external fun floatToExternref(x: Float): ExternalInterfaceType
|
||||
private fun floatToExternref(x: Float): ExternalInterfaceType =
|
||||
js("x")
|
||||
|
||||
@JsFun("x => x")
|
||||
private external fun doubleToExternref(x: Double): ExternalInterfaceType
|
||||
private fun doubleToExternref(x: Double): ExternalInterfaceType =
|
||||
js("x")
|
||||
|
||||
@JsFun("(lhs, rhs) => lhs === rhs")
|
||||
private external fun externrefEquals(lhs: ExternalInterfaceType, rhs: ExternalInterfaceType): Boolean
|
||||
private fun externrefEquals(lhs: ExternalInterfaceType, rhs: ExternalInterfaceType): Boolean =
|
||||
js("lhs === rhs")
|
||||
|
||||
private external fun tryGetOrSetExternrefBox(ref: ExternalInterfaceType, ifNotCached: JsExternalBox): JsExternalBox?
|
||||
|
||||
@@ -136,8 +139,8 @@ private fun ExternalInterfaceType.externAsWasmAnyref(): anyref =
|
||||
private fun Any.asWasmExternRef(): ExternalInterfaceType =
|
||||
implementedAsIntrinsic
|
||||
|
||||
@JsFun("(ref) => ref == null")
|
||||
internal external fun isNullish(ref: ExternalInterfaceType?): Boolean
|
||||
internal fun isNullish(ref: ExternalInterfaceType?): Boolean =
|
||||
js("ref == null")
|
||||
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
@ExcludedFromCodegen
|
||||
@@ -179,18 +182,18 @@ internal fun anyToExternRef(x: Any): ExternalInterfaceType {
|
||||
x.asWasmExternRef()
|
||||
}
|
||||
|
||||
@JsFun("x => x.length")
|
||||
internal external fun stringLength(x: ExternalInterfaceType): Int
|
||||
internal fun stringLength(x: ExternalInterfaceType): Int =
|
||||
js("x.length")
|
||||
|
||||
// kotlin string to js string export
|
||||
// TODO Uint16Array may work with byte endian different with Wasm (i.e. little endian)
|
||||
@JsFun("""(address, length, prefix) => {
|
||||
internal fun importStringFromWasm(address: Int, length: Int, prefix: ExternalInterfaceType?): ExternalInterfaceType {
|
||||
js("""
|
||||
const mem16 = new Uint16Array(wasmExports.memory.buffer, address, length);
|
||||
const str = String.fromCharCode.apply(null, mem16);
|
||||
return (prefix == null) ? str : prefix + str;
|
||||
""")
|
||||
}
|
||||
""")
|
||||
internal external fun importStringFromWasm(address: Int, length: Int, prefix: ExternalInterfaceType?): ExternalInterfaceType
|
||||
|
||||
internal fun kotlinToJsStringAdapter(x: String?): ExternalInterfaceType? {
|
||||
// Using nullable String to represent default value
|
||||
@@ -224,21 +227,18 @@ internal fun jsCheckIsNullOrUndefinedAdapter(x: ExternalInterfaceType?): Externa
|
||||
|
||||
// js string to kotlin string import
|
||||
// TODO Uint16Array may work with byte endian different with Wasm (i.e. little endian)
|
||||
//language=js
|
||||
@JsFun(
|
||||
""" (src, srcOffset, srcLength, dstAddr) => {
|
||||
const mem16 = new Uint16Array(wasmExports.memory.buffer, dstAddr, srcLength);
|
||||
let arrayIndex = 0;
|
||||
let srcIndex = srcOffset;
|
||||
while (arrayIndex < srcLength) {
|
||||
mem16.set([src.charCodeAt(srcIndex)], arrayIndex);
|
||||
srcIndex++;
|
||||
arrayIndex++;
|
||||
}
|
||||
}
|
||||
"""
|
||||
)
|
||||
internal external fun jsExportStringToWasm(src: ExternalInterfaceType, srcOffset: Int, srcLength: Int, dstAddr: Int)
|
||||
internal fun jsExportStringToWasm(src: ExternalInterfaceType, srcOffset: Int, srcLength: Int, dstAddr: Int) {
|
||||
js("""
|
||||
const mem16 = new Uint16Array(wasmExports.memory.buffer, dstAddr, srcLength);
|
||||
let arrayIndex = 0;
|
||||
let srcIndex = srcOffset;
|
||||
while (arrayIndex < srcLength) {
|
||||
mem16.set([src.charCodeAt(srcIndex)], arrayIndex);
|
||||
srcIndex++;
|
||||
arrayIndex++;
|
||||
}
|
||||
""")
|
||||
}
|
||||
|
||||
private const val STRING_INTEROP_MEM_BUFFER_SIZE = 65_536 // 1 page 4KiB
|
||||
|
||||
@@ -269,14 +269,14 @@ internal fun jsToKotlinStringAdapter(x: ExternalInterfaceType): String {
|
||||
}
|
||||
|
||||
|
||||
@JsFun("() => ''")
|
||||
private external fun getJsEmptyString(): ExternalInterfaceType
|
||||
private fun getJsEmptyString(): ExternalInterfaceType =
|
||||
js("''")
|
||||
|
||||
@JsFun("() => true")
|
||||
private external fun getJsTrue(): ExternalInterfaceType
|
||||
private fun getJsTrue(): ExternalInterfaceType =
|
||||
js("true")
|
||||
|
||||
@JsFun("() => false")
|
||||
private external fun getJsFalse(): ExternalInterfaceType
|
||||
private fun getJsFalse(): ExternalInterfaceType =
|
||||
js("false")
|
||||
|
||||
private val jsEmptyString by lazy(::getJsEmptyString)
|
||||
private val jsTrue by lazy(::getJsTrue)
|
||||
@@ -335,8 +335,9 @@ internal fun kotlinShortToExternRefAdapter(x: Short): ExternalInterfaceType =
|
||||
internal fun kotlinCharToExternRefAdapter(x: Char): ExternalInterfaceType =
|
||||
intToExternref(x.toInt())
|
||||
|
||||
@JsFun("() => []")
|
||||
internal external fun newJsArray(): ExternalInterfaceType
|
||||
internal fun newJsArray(): ExternalInterfaceType =
|
||||
js("[]")
|
||||
|
||||
@JsFun("(array, element) => { array.push(element); }")
|
||||
internal external fun jsArrayPush(array: ExternalInterfaceType, element: ExternalInterfaceType)
|
||||
internal fun jsArrayPush(array: ExternalInterfaceType, element: ExternalInterfaceType) {
|
||||
js("array.push(element);")
|
||||
}
|
||||
|
||||
@@ -3,87 +3,89 @@
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@file:Suppress("UNUSED_PARAMETER") // TODO: Remove after bootstrap update
|
||||
|
||||
package kotlin.js
|
||||
|
||||
@PublishedApi
|
||||
@JsFun("(obj, index, value) => obj[index] = value")
|
||||
internal external fun dynamicSetBoolean(obj: Dynamic, index: String, value: Boolean)
|
||||
internal fun dynamicSetBoolean(obj: Dynamic, index: String, value: Boolean): Unit =
|
||||
js("obj[index] = value")
|
||||
|
||||
@PublishedApi
|
||||
@JsFun("(obj, index, value) => obj[index] = value")
|
||||
internal external fun dynamicSetByte(obj: Dynamic, index: String, value: Byte)
|
||||
internal fun dynamicSetByte(obj: Dynamic, index: String, value: Byte): Unit =
|
||||
js("obj[index] = value")
|
||||
|
||||
@PublishedApi
|
||||
@JsFun("(obj, index, value) => obj[index] = value")
|
||||
internal external fun dynamicSetShort(obj: Dynamic, index: String, value: Short)
|
||||
internal fun dynamicSetShort(obj: Dynamic, index: String, value: Short): Unit =
|
||||
js("obj[index] = value")
|
||||
|
||||
@PublishedApi
|
||||
@JsFun("(obj, index, value) => obj[index] = value")
|
||||
internal external fun dynamicSetChar(obj: Dynamic, index: String, value: Char)
|
||||
internal fun dynamicSetChar(obj: Dynamic, index: String, value: Char): Unit =
|
||||
js("obj[index] = value")
|
||||
|
||||
@PublishedApi
|
||||
@JsFun("(obj, index, value) => obj[index] = value")
|
||||
internal external fun dynamicSetInt(obj: Dynamic, index: String, value: Int)
|
||||
internal fun dynamicSetInt(obj: Dynamic, index: String, value: Int): Unit =
|
||||
js("obj[index] = value")
|
||||
|
||||
@PublishedApi
|
||||
@JsFun("(obj, index, value) => obj[index] = value")
|
||||
internal external fun dynamicSetLong(obj: Dynamic, index: String, value: Long)
|
||||
internal fun dynamicSetLong(obj: Dynamic, index: String, value: Long): Unit =
|
||||
js("obj[index] = value")
|
||||
|
||||
@PublishedApi
|
||||
@JsFun("(obj, index, value) => obj[index] = value")
|
||||
internal external fun dynamicSetFloat(obj: Dynamic, index: String, value: Float)
|
||||
internal fun dynamicSetFloat(obj: Dynamic, index: String, value: Float): Unit =
|
||||
js("obj[index] = value")
|
||||
|
||||
@PublishedApi
|
||||
@JsFun("(obj, index, value) => obj[index] = value")
|
||||
internal external fun dynamicSetDouble(obj: Dynamic, index: String, value: Double)
|
||||
internal fun dynamicSetDouble(obj: Dynamic, index: String, value: Double): Unit =
|
||||
js("obj[index] = value")
|
||||
|
||||
@PublishedApi
|
||||
@JsFun("(obj, index, value) => obj[index] = value")
|
||||
internal external fun dynamicSetString(obj: Dynamic, index: String, value: String?)
|
||||
internal fun dynamicSetString(obj: Dynamic, index: String, value: String?): Unit =
|
||||
js("obj[index] = value")
|
||||
|
||||
@PublishedApi
|
||||
@JsFun("(obj, index, value) => obj[index] = value")
|
||||
internal external fun dynamicSetAny(obj: Dynamic, index: String, value: Any?)
|
||||
internal fun dynamicSetAny(obj: Dynamic, index: String, value: Any?): Unit =
|
||||
js("obj[index] = value")
|
||||
|
||||
@PublishedApi
|
||||
@JsFun("(obj, index) => obj[index]")
|
||||
internal external fun dynamicGetBoolean(obj: Dynamic, index: String): Boolean
|
||||
internal fun dynamicGetBoolean(obj: Dynamic, index: String): Boolean =
|
||||
js("obj[index]")
|
||||
|
||||
@PublishedApi
|
||||
@JsFun("(obj, index) => obj[index]")
|
||||
internal external fun dynamicGetByte(obj: Dynamic, index: String): Byte
|
||||
internal fun dynamicGetByte(obj: Dynamic, index: String): Byte =
|
||||
js("obj[index]")
|
||||
|
||||
@PublishedApi
|
||||
@JsFun("(obj, index) => obj[index]")
|
||||
internal external fun dynamicGetShort(obj: Dynamic, index: String): Short
|
||||
internal fun dynamicGetShort(obj: Dynamic, index: String): Short =
|
||||
js("obj[index]")
|
||||
|
||||
@PublishedApi
|
||||
@JsFun("(obj, index) => obj[index]")
|
||||
internal external fun dynamicGetChar(obj: Dynamic, index: String): Char
|
||||
internal fun dynamicGetChar(obj: Dynamic, index: String): Char =
|
||||
js("obj[index]")
|
||||
|
||||
@PublishedApi
|
||||
@JsFun("(obj, index) => obj[index]")
|
||||
internal external fun dynamicGetInt(obj: Dynamic, index: String): Int
|
||||
internal fun dynamicGetInt(obj: Dynamic, index: String): Int =
|
||||
js("obj[index]")
|
||||
|
||||
@PublishedApi
|
||||
@JsFun("(obj, index) => obj[index]")
|
||||
internal external fun dynamicGetLong(obj: Dynamic, index: String): Long
|
||||
internal fun dynamicGetLong(obj: Dynamic, index: String): Long =
|
||||
js("obj[index]")
|
||||
|
||||
@PublishedApi
|
||||
@JsFun("(obj, index) => obj[index]")
|
||||
internal external fun dynamicGetFloat(obj: Dynamic, index: String): Float
|
||||
internal fun dynamicGetFloat(obj: Dynamic, index: String): Float =
|
||||
js("obj[index]")
|
||||
|
||||
@PublishedApi
|
||||
@JsFun("(obj, index) => obj[index]")
|
||||
internal external fun dynamicGetDouble(obj: Dynamic, index: String): Double
|
||||
internal fun dynamicGetDouble(obj: Dynamic, index: String): Double =
|
||||
js("obj[index]")
|
||||
|
||||
@PublishedApi
|
||||
@JsFun("(obj, index) => obj[index]")
|
||||
internal external fun dynamicGetString(obj: Dynamic, index: String): String?
|
||||
internal fun dynamicGetString(obj: Dynamic, index: String): String? =
|
||||
js("obj[index]")
|
||||
|
||||
@PublishedApi
|
||||
@JsFun("(obj, index) => obj[index]")
|
||||
internal external fun dynamicGetAny(obj: Dynamic, index: String): Any?
|
||||
internal fun dynamicGetAny(obj: Dynamic, index: String): Any? =
|
||||
js("obj[index]")
|
||||
|
||||
@PublishedApi
|
||||
internal fun Dynamic.getBoolean(index: String): Boolean = dynamicGetBoolean(this, index)
|
||||
@@ -184,14 +186,12 @@ operator fun Dynamic.set(index: Int, value: Any?) {
|
||||
this[index.toString()] = value
|
||||
}
|
||||
|
||||
@JsFun("(x) => x")
|
||||
private external fun <T> unsafeCastJs(x: String): Dynamic
|
||||
private fun <T> unsafeCastJs(x: String): Dynamic = js("x")
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun <T> String.unsafeCast(): T = unsafeCastJs<T>(this) as T
|
||||
|
||||
@JsFun("(x) => x")
|
||||
private external fun <T> unsafeCastJs(x: Boolean): Dynamic
|
||||
private fun <T> unsafeCastJs(x: Boolean): Dynamic = js("x")
|
||||
|
||||
/**
|
||||
* Reinterprets boolean value as a value of the specified type [T] without any actual type checking.
|
||||
@@ -210,10 +210,12 @@ fun <T> Nothing?.unsafeCast(): Dynamic? = null
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun <T> Dynamic.unsafeCast(): T = this as T
|
||||
|
||||
@JsFun("e => { throw e; }")
|
||||
private external fun jsThrow(e: Dynamic)
|
||||
private fun jsThrow(e: Dynamic) {
|
||||
js("throw e;")
|
||||
}
|
||||
|
||||
@JsFun("""(f) => {
|
||||
private fun jsCatch(f: () -> Unit): Dynamic? {
|
||||
js("""
|
||||
let result = null;
|
||||
try {
|
||||
f();
|
||||
@@ -221,8 +223,8 @@ private external fun jsThrow(e: Dynamic)
|
||||
result = e;
|
||||
}
|
||||
return result;
|
||||
}""")
|
||||
private external fun jsCatch(f: () -> Unit): Dynamic?
|
||||
""")
|
||||
}
|
||||
|
||||
/**
|
||||
* For a Dynamic value caught in JS, returns the corresponding [Throwable]
|
||||
|
||||
@@ -3,18 +3,20 @@
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@file:Suppress("UNUSED_PARAMETER") // TODO: Remove after bootstrap update
|
||||
|
||||
package kotlin.io
|
||||
|
||||
import kotlin.wasm.internal.*
|
||||
|
||||
@JsFun("(error) => console.error(error)")
|
||||
internal external fun printError(error: String?): Unit
|
||||
internal fun printError(error: String?): Unit =
|
||||
js("console.error(error)")
|
||||
|
||||
@JsFun("(message) => console.log(message)")
|
||||
private external fun printlnImpl(message: String?): Unit
|
||||
private fun printlnImpl(message: String?): Unit =
|
||||
js("console.log(message)")
|
||||
|
||||
@JsFun("(message) => typeof write !== 'undefined' ? write(message) : console.log(message)")
|
||||
private external fun printImpl(message: String?): Unit
|
||||
private fun printImpl(message: String?): Unit =
|
||||
js("typeof write !== 'undefined' ? write(message) : console.log(message)")
|
||||
|
||||
/** Prints the line separator to the standard output stream. */
|
||||
public actual fun println() {
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
|
||||
package kotlin.random
|
||||
|
||||
@JsFun("() => ((Math.random() * Math.pow(2, 32)) | 0)")
|
||||
private external fun initialSeed(): Int
|
||||
private fun initialSeed(): Int =
|
||||
js("((Math.random() * Math.pow(2, 32)) | 0)")
|
||||
|
||||
internal actual fun defaultPlatformRandom(): Random =
|
||||
Random(initialSeed())
|
||||
|
||||
@@ -3,17 +3,19 @@
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@file:Suppress("UNUSED_PARAMETER") // TODO: Remove after bootstrap update
|
||||
|
||||
package kotlin.time
|
||||
|
||||
import kotlin.math.*
|
||||
|
||||
internal actual inline val durationAssertionsEnabled: Boolean get() = true
|
||||
|
||||
@JsFun("(value, decimals) => value.toFixed(decimals)")
|
||||
private external fun toFixed(value: Double, decimals: Int): String
|
||||
private fun toFixed(value: Double, decimals: Int): String =
|
||||
js("value.toFixed(decimals)")
|
||||
|
||||
@JsFun("(value, decimals) => value.toPrecision(decimals)")
|
||||
private external fun toPrecision(value: Double, decimals: Int): String
|
||||
private fun toPrecision(value: Double, decimals: Int): String =
|
||||
js("value.toPrecision(decimals)")
|
||||
|
||||
internal actual fun formatToExactDecimals(value: Double, decimals: Int): String {
|
||||
val rounded = if (decimals == 0) {
|
||||
@@ -34,5 +36,5 @@ internal actual fun formatToExactDecimals(value: Double, decimals: Int): String
|
||||
}
|
||||
}
|
||||
|
||||
@JsFun("(value, decimals) => value.toLocaleString(\"en-us\", ({\"maximumFractionDigits\": decimals}))")
|
||||
external internal actual fun formatUpToDecimals(value: Double, decimals: Int): String
|
||||
internal actual fun formatUpToDecimals(value: Double, decimals: Int): String =
|
||||
js("(value, decimals) => value.toLocaleString(\"en-us\", ({\"maximumFractionDigits\": decimals}))")
|
||||
@@ -3,20 +3,22 @@
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@file:Suppress("UNUSED_PARAMETER") // TODO: Remove after bootstrap advance
|
||||
|
||||
package kotlin.time
|
||||
|
||||
import kotlin.wasm.internal.ExternalInterfaceType
|
||||
import kotlin.time.TimeSource.Monotonic.ValueTimeMark
|
||||
import kotlin.time.Duration.Companion.milliseconds
|
||||
|
||||
@JsFun("() => typeof globalThis !== 'undefined' && typeof globalThis.performance !== 'undefined' ? globalThis.performance : null")
|
||||
private external fun tryGetPerformance(): ExternalInterfaceType?
|
||||
private fun tryGetPerformance(): ExternalInterfaceType? =
|
||||
js("typeof globalThis !== 'undefined' && typeof globalThis.performance !== 'undefined' ? globalThis.performance : null")
|
||||
|
||||
@JsFun("(performance) => performance.now()")
|
||||
private external fun getPerformanceNow(performance: ExternalInterfaceType): Double
|
||||
private fun getPerformanceNow(performance: ExternalInterfaceType): Double =
|
||||
js("performance.now()")
|
||||
|
||||
@JsFun("() => Date.now()")
|
||||
private external fun dateNow(): Double
|
||||
private fun dateNow(): Double =
|
||||
js("Date.now()")
|
||||
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalTime
|
||||
|
||||
@@ -9,5 +9,5 @@ package kotlin.js
|
||||
internal val undefined: Nothing? = null
|
||||
|
||||
@PublishedApi
|
||||
@JsFun("() => ({})")
|
||||
internal external fun newJsObject(): Dynamic
|
||||
internal fun newJsObject(): Dynamic =
|
||||
js("({})")
|
||||
|
||||
@@ -3,11 +3,11 @@ package test.js
|
||||
import kotlin.js.*
|
||||
import kotlin.test.*
|
||||
|
||||
@JsFun("async () => 'foo'")
|
||||
internal external fun jsAsyncFoo(): Promise<Dynamic?>
|
||||
internal fun jsAsyncFoo(): Promise<Dynamic?> =
|
||||
js("(async () => 'foo')()")
|
||||
|
||||
@JsFun("() => 'foo'")
|
||||
internal external fun jsFoo(): Dynamic
|
||||
internal fun jsFoo(): Dynamic =
|
||||
js("'foo'")
|
||||
|
||||
var state: Dynamic? = null
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ package test.wasm.unsafe
|
||||
import kotlin.wasm.unsafe.*
|
||||
import kotlin.test.*
|
||||
|
||||
@JsFun("(a, b) => a + b")
|
||||
private external fun jsConcatStrings(a: String, b: String): String
|
||||
private fun jsConcatStrings(a: String, b: String): String =
|
||||
js("a + b")
|
||||
|
||||
@OptIn(UnsafeWasmMemoryApi::class)
|
||||
class MemoryAllocationTest {
|
||||
|
||||
Reference in New Issue
Block a user