JsArray

abstract class JsArray : JsObject(source)

A JavaScript array seen from Kotlin.

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard
abstract val engine: KiteJs

The engine this object belongs to.

Link copied to clipboard
abstract val keys: List<String>

The object's own enumerable string keys, in the order Object.keys gives them.

Link copied to clipboard

The array's exact length, including lengths too large for a Kotlin collection.

Link copied to clipboard
open val size: Int

The array's length as an Int, or JsEngineError when it exceeds Int.MAX_VALUE.

Link copied to clipboard

The value this wrapper holds, for handing back to the engine.

Functions

Link copied to clipboard
fun JsObject.accessor(name: String, flags: PropertyFlags = PropertyFlags(), read: () -> Any?, write: (JsValue) -> Unit)

A property with both halves.

Link copied to clipboard
fun add(value: Any?)

Appends at length, or refuses an array already at JavaScript's maximum length.

Link copied to clipboard
fun <T : Any> JsObject.bind(name: String, instance: T, build: BindScope<T>.() -> Unit): JsObject

Binds a Kotlin object into a fresh JavaScript object.

Link copied to clipboard
abstract fun call(name: String, vararg args: Any?): JsValue

Calls a method on this object, the way obj.name(...) does in a script.

Link copied to clipboard
fun JsObject.constant(name: String, value: Any?)

Puts a value that a script can read but not change.

Link copied to clipboard
fun JsObject.constructor(name: String, arity: Int = 0, flags: PropertyFlags = PropertyFlags(enumerable = false), build: (JsObject, List<JsValue>) -> Unit): JsFunction

A host constructor, callable with new. build fills in the object it is given.

Link copied to clipboard
abstract fun defineAccessor(name: String, read: () -> Any??, write: (JsValue) -> Unit?, flags: PropertyFlags)

Defines an accessor property whose halves call back into the host. Either can be null.

Link copied to clipboard
abstract fun defineValue(name: String, value: Any?, flags: PropertyFlags)

Defines a data property, as Object.defineProperty would.

Link copied to clipboard
abstract fun delete(name: String)

Deletes name from the object, as the delete operator does.

Link copied to clipboard
abstract operator override fun equals(other: Any?): Boolean

Two handles are equal when they hold the same object.

Link copied to clipboard
inline fun <reified A, reified R> JsObject.function(name: String, crossinline body: (A) -> R): JsFunction

A one-argument host function, with the argument and the answer converted for you.

inline fun <reified A, reified B, reified R> JsObject.function(name: String, crossinline body: (A, B) -> R): JsFunction

A two-argument host function.

inline fun <reified A, reified B, reified C, reified R> JsObject.function(name: String, crossinline body: (A, B, C) -> R): JsFunction

A three-argument host function.

fun JsObject.function(name: String, arity: Int = 0, flags: PropertyFlags = PropertyFlags(enumerable = false), body: (List<JsValue>) -> Any?): JsFunction

A host function that takes the arguments as they came.

Link copied to clipboard
abstract operator fun get(index: Int): JsValue
abstract operator fun get(name: String): JsValue
Link copied to clipboard
fun JsObject.getter(name: String, flags: PropertyFlags = PropertyFlags(), read: () -> Any?)

A property computed on every read.

Link copied to clipboard
abstract fun has(name: String): Boolean

Whether the object has name, its own or inherited, as the in operator answers.

Link copied to clipboard
abstract override fun hashCode(): Int
Link copied to clipboard
abstract fun inertText(): String

What the object prints as where it cannot be touched: [object Class], running nothing.

Link copied to clipboard
abstract fun isUsableHere(): Boolean

True when the engine is open and this is its thread, so the object can be touched here.

Link copied to clipboard
fun JsObject.method(name: String, arity: Int = 0, flags: PropertyFlags = PropertyFlags(enumerable = false), body: (self: JsValue, args: List<JsValue>) -> Any?): JsFunction

A host function that also wants the this it was called on.

Link copied to clipboard
fun JsObject.obj(name: String, build: JsObject.() -> Unit = {}): JsObject

A nested object, built by build. Returns it so you can keep a handle.

Link copied to clipboard
fun JsObject.property(name: String, value: Any?, flags: PropertyFlags = PropertyFlags())

Puts a value on the object.

Link copied to clipboard
abstract operator fun set(index: Int, value: Any?)
abstract operator fun set(name: String, value: Any?)
Link copied to clipboard
fun JsObject.setter(name: String, flags: PropertyFlags = PropertyFlags(), write: (JsValue) -> Unit)

A property that only accepts writes.

Link copied to clipboard

A copy of the bytes this object views when it is an ArrayBuffer, a typed array or a DataView, read without running any script, or null for any other object. A detached buffer, or a view past the end of its buffer, gives no bytes.

Link copied to clipboard
fun toList(): List<Any?>

A plain Kotlin list, all the way down.

Link copied to clipboard
fun toMap(): Map<String, Any?>

A plain Kotlin map, all the way down. Cycles come back as the JsObject that closed them.

Link copied to clipboard
abstract fun toPrimitive(hint: PrimitiveHint): JsValue

ToPrimitive with hint, which can run the object's script.

Link copied to clipboard
open override fun toString(): String

What String(obj) gives, without ever throwing. Where the engine cannot be used, or the object's own conversion fails, it prints its class instead, without running any script.

Link copied to clipboard

Every element as a JsValue, or JsEngineError if length exceeds Int.MAX_VALUE.