[Wasm] Support restricted version of js("code") (KT-56955)

This commit is contained in:
Svyatoslav Kuzmich
2023-01-14 14:24:47 +01:00
committed by Space Team
parent eb8c47343a
commit 71e6b19760
11 changed files with 184 additions and 12 deletions
@@ -34,4 +34,37 @@ import kotlin.wasm.internal.ExcludedFromCodegen
* ```
*/
@ExcludedFromCodegen
public external val definedExternally: Nothing
public external val definedExternally: Nothing
/**
* This function allows you to incorporate JavaScript [code] into Kotlin/Wasm codebase.
* It is used to implement top-level functions and initialize top-level properties.
*
* It is important to note, that calls to [js] function should be the only expression
* in a function body or a property initializer.
*
* [code] parameter should be a compile-time constant.
*
* When used in an expression context, [code] should contain a single JavaScript expression. For example:
*
* ``` kotlin
* val version: String = js("process.version")
* fun newEmptyJsArray(): JsValue = js("[]")
* ```
*
* When used in a function body, [code] is expected to be a list of JavaScript statements. For example:
*
* ``` kotlin
* fun log(message1: String, message2: String) {
* js("""
* console.log(message1);
* console.log(message2);
* """)
* }
* ```
*
* You can use parameters of calling function in JavaScript [code].
* However, other Kotlin declarations are not visible inside the [code] block.
*/
@ExcludedFromCodegen
public external fun js(code: String): Nothing