[Wasm] Add interop annotation @JsFun
This commit is contained in:
@@ -51,11 +51,11 @@ public class String constructor(public val string: String) : Comparable<String>,
|
||||
public override fun hashCode(): Int = 10
|
||||
}
|
||||
|
||||
@WasmImport("runtime", "String_plus")
|
||||
@JsFun("(it, other) => it + String(other)")
|
||||
private fun stringPlusImpl(it: String, other: String): String =
|
||||
implementedAsIntrinsic
|
||||
|
||||
@WasmImport("runtime", "String_getLength")
|
||||
@JsFun("(it) => it.length")
|
||||
private fun stringLengthImpl(it: String): Int =
|
||||
implementedAsIntrinsic
|
||||
|
||||
|
||||
@@ -72,11 +72,11 @@ internal fun JsArray_set_WasmExternRef(array: WasmExternRef, index: Int, value:
|
||||
internal fun JsArray_getSize(array: WasmExternRef): Int =
|
||||
implementedAsIntrinsic
|
||||
|
||||
@WasmImport("runtime", "identity")
|
||||
@JsFun("(x) => x")
|
||||
internal fun Any?.toWasmExternRef(): WasmExternRef =
|
||||
implementedAsIntrinsic
|
||||
|
||||
@WasmImport("runtime", "identity")
|
||||
@JsFun("(x) => x")
|
||||
internal fun WasmExternRefToAny(ref: WasmExternRef): Any? =
|
||||
implementedAsIntrinsic
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2010-2020 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
|
||||
|
||||
/**
|
||||
* Implements annotated function in JavaScript and automatically imports is to Wasm.
|
||||
* [code] string must contain JS expression that evaluates to JS function with signature that matches annotated kotlin function
|
||||
*
|
||||
* For example, a function that adds two Doubles via JS:
|
||||
*
|
||||
* @JsFun("(x, y) => x + y")
|
||||
* fun jsAdd(x: Double, y: Double): Double =
|
||||
* error("...")
|
||||
*
|
||||
* This is a temporary annotation because K/Wasm <-> JS interop is not designed yet.
|
||||
*/
|
||||
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER)
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
public annotation class JsFun(val code: String)
|
||||
Reference in New Issue
Block a user