JavaScriptKit Documentation

Classes

Java​Script​Event​Loop

Singleton type responsible for integrating JavaScript event loop as a Swift concurrency executor, conforming to SerialExecutor protocol from the standard library. To utilize it:

JSArray

A wrapper around the JavaScript Array class that exposes its properties in a type-safe and Swifty way.

JSArray.​Iterator

Iterator type for JSArray, conforming to IteratorProtocol from the standard library, which allows easy iteration over elements of JSArray instances.

JSDate

A wrapper around the JavaScript Date class that exposes its properties in a type-safe way. This doesn't 100% match the JS API, for example getMonth/setMonth etc accessor methods are converted to properties, but the rest of it matches in the naming. Parts of the JavaScript Date API that are not consistent across browsers and JS implementations are not exposed in a type-safe manner, you should access the underlying jsObject property if you need those.

JSError

A wrapper around the JavaScript Error class that exposes its properties in a type-safe way.

JSPromise

A wrapper around the JavaScript Promise class

JSTimer

This timer is an abstraction over setInterval / clearInterval and setTimeout / clearTimeout JavaScript functions. It intentionally doesn't match the JavaScript API, as a special care is needed to hold a reference to the timer closure and to call JSClosure.release() on it when the timer is deallocated. As a user, you have to hold a reference to a JSTimer instance for it to stay valid. The JSTimer API is also intentionally trivial, the timer is started right away, and the only way to invalidate the timer is to bring the reference count of the JSTimer instance to zero. For invalidation you should either store the timer in an optional property and assign nil to it, or deallocate the object that owns the timer.

JSTyped​Array

A wrapper around all JavaScript TypedArray classes that exposes their properties in a type-safe way.

JSUInt8Clamped​Array

A wrapper around the JavaScript Uint8ClampedArray class that exposes its properties in a type-safe and Swifty way.

JSBig​Int

A wrapper around the JavaScript BigInt class that exposes its properties in a type-safe and Swifty way.

JSOneshot​Closure

JSOneshotClosure is a JavaScript function that can be called only once. This class can be used for optimized memory management when compared to the common JSClosure.

JSClosure

JSClosure represents a JavaScript function the body of which is written in Swift. This type can be passed as a callback handler to JavaScript functions.

JSFunction

JSFunction represents a function in JavaScript and supports new object instantiation. This type can be callable as a function using callAsFunction.

JSObject

JSObject represents an object in JavaScript and supports dynamic member lookup. Any member access like object.foo will dynamically request the JavaScript and Swift runtime bridge library for a member with the specified name in this object.

JSThrowing​Object

A JSObject wrapper that enables throwing method calls capturing this. Exceptions produced by JavaScript functions will be thrown as JSValue.

JSSymbol

A wrapper around the JavaScript Symbol class that exposes its properties in a type-safe and Swifty way.

JSThrowing​Function

A JSFunction wrapper that enables throwing function calls. Exceptions produced by JavaScript functions will be thrown as JSValue.

JSValue​Decoder

JSValueDecoder facilitates the decoding of JavaScript value into semantic Decodable types.

Structures

JSString

JSString represents a string in JavaScript and supports bridging string between JavaScript and Swift.

Enumerations

JSValue

JSValue represents a value in JavaScript.

Protocols

Typed​Array​Element

A protocol that allows a Swift numeric type to be mapped to the JavaScript TypedArray that holds integers of its type

Constructible​From​JSValue

Types conforming to this protocol can be constructed from JSValue.

Convertible​ToJSValue

Objects that can be converted to a JavaScript value, preferably in a lossless manner.

JSBig​Int​Extended
JSClosure​Protocol

JSClosureProtocol wraps Swift closure objects for use in JavaScript. Conforming types are responsible for managing the lifetime of the closure they wrap, but can delegate that task to the user by requiring an explicit release() call.

JSBridged​Type

Use this protocol when your type has no single JavaScript class. For example, a union type of multiple classes or primitive values.

JSBridged​Class

Conform to this protocol when your Swift class wraps a JavaScript class.

Typealiases

JSValue​Compatible
JSObject​Ref
JSArray​Ref
JSFunction​Ref
JSValue​Convertible
JSValue​Constructible
JSValue​Codable

Functions

get​JSValue(this:​name:​)
set​JSValue(this:​name:​value:​)
get​JSValue(this:​index:​)
set​JSValue(this:​index:​value:​)
get​JSValue(this:​symbol:​)
set​JSValue(this:​symbol:​value:​)

Extensions

Array
BinaryFloatingPoint
Bool
Dictionary
Double
Float
Float32
Float64
Int
Int16
Int32
Int64
Int8
Optional
RawJSValue
SignedInteger
String
UInt
UInt16
UInt32
UInt64
UInt8
UnsignedInteger