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 JavaScriptDate
API that are not consistent across browsers and JS implementations are not exposed in a type-safe manner, you should access the underlyingjsObject
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. TheJSPromise
API is generic over bothSuccess
andFailure
types, which improves compatibility with other statically-typed APIs such as Combine. If you don't know the exact type of yourSuccess
value, you should useJSValue
, e.g.JSPromise<JSValue, JSError>
. In the rare case, where you can't guarantee that the error thrown is of actual JavaScriptError
type, you should useJSPromise<JSValue, JSValue>
. - JSTimer
-
This timer is an abstraction over
setInterval
/clearInterval
andsetTimeout
/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 callJSClosure.release()
on it when the timer is deallocated. As a user, you have to hold a reference to aJSTimer
instance for it to stay valid. TheJSTimer
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 theJSTimer
instance to zero. For invalidation you should either store the timer in an optional property and assignnil
to it, or deallocate the object that owns the timer. - JSTypedArray
-
A wrapper around all JavaScript TypedArray classes that exposes their properties in a type-safe way. FIXME: BigInt-based TypedArrays are currently not supported.
- JSOneshotClosure
-
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 ofJSClosure
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 usingcallAsFunction
. - JSObject
-
JSObject
represents an object in JavaScript and supports dynamic member lookup. Any member access likeobject.foo
will dynamically request the JavaScript and Swift runtime bridge library for a member with the specified name in this object. - JSThrowingObject
-
A
JSObject
wrapper that enables throwing method calls capturingthis
. Exceptions produced by JavaScript functions will be thrown asJSValue
. - JSThrowingFunction
-
A
JSFunction
wrapper that enables throwing function calls. Exceptions produced by JavaScript functions will be thrown asJSValue
. - JSValueDecoder
-
JSValueDecoder
facilitates the decoding of JavaScript value into semanticDecodable
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
- TypedArrayElement
-
A protocol that allows a Swift numeric type to be mapped to the JavaScript TypedArray that holds integers of its type
- ConstructibleFromJSValue
-
Types conforming to this protocol can be constructed from
JSValue
. - ConvertibleToJSValue
-
Objects that can be converted to a JavaScript value, preferably in a lossless manner.
- JSClosureProtocol
-
JSClosureProtocol abstracts closure object in JavaScript, whose lifetime is manualy managed
- JSBridgedType
-
Use this protocol when your type has no single JavaScript class. For example, a union type of multiple classes or primitive values.
- JSBridgedClass
-
Conform to this protocol when your Swift class wraps a JavaScript class.
Typealiases
- JSValueCompatible
- JSObjectRef
- JSArrayRef
- JSFunctionRef
- JSValueConvertible
- JSValueConstructible
- JSValueCodable
Functions
- getJSValue(this:name:)
- setJSValue(this:name:value:)
- getJSValue(this:index:)
- setJSValue(this:index:value:)