JavaScriptKit Documentation Beta

Classes

JSArray

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

JSArray.​Iterator
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 that exposes its functions in a type-safe and Swifty way. The JSPromise API is generic over both Success and Failure types, which improves compatibility with other statically-typed APIs such as Combine. If you don't know the exact type of your Success value, you should use JSValue, e.g. JSPromise<JSValue, JSError>. In the rare case, where you can't guarantee that the error thrown is of actual JavaScript Error type, you should use JSPromise<JSValue, JSValue>.

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. FIXME: BigInt-based TypedArrays are currently not supported.

JSOneshot​Closure

JSOneshotClosure is a JavaScript function that can be called only once.

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. Note that the lifetime of JSClosure should be managed by users manually due to GC boundary between Swift and JavaScript. For further discussion, see also swiftwasm/JavaScriptKit #33

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.

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.

JSClosure​Protocol

JSClosureProtocol abstracts closure object in JavaScript, whose lifetime is manualy managed

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:​)

Extensions

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