JSValue
JSValue
represents a value in JavaScript.
@dynamicMemberLookup enum JSValue
JSValue
represents a value in JavaScript.
@dynamicMemberLookup enum JSValue
import JavaScriptKit
Swift framework to interact with JavaScript through WebAssembly.
case boolean(Bool)
case string(JSString)
case number(Double)
case object(JSObject)
case null
case undefined
case function(JSFunction)
case symbol(JSSymbol)
case bigInt(JSBigInt)
@dynamicMemberLookup class 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.
class 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.
protocol ConstructibleFromJSValue
Types conforming to this protocol can be constructed from JSValue
.
protocol ConvertibleToJSValue
Objects that can be converted to a JavaScript value, preferably in a lossless manner.
protocol Copyable
A type whose values can be implicitly or explicitly copied.
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Escapable
protocol ExpressibleByExtendedGraphemeClusterLiteral : ExpressibleByUnicodeScalarLiteral
A type that can be initialized with a string literal containing a single extended grapheme cluster.
protocol ExpressibleByFloatLiteral
A type that can be initialized with a floating-point literal.
protocol ExpressibleByIntegerLiteral
A type that can be initialized with an integer literal.
protocol ExpressibleByNilLiteral : ~Copyable
A type that can be initialized using the nil literal, nil
.
protocol ExpressibleByStringLiteral : ExpressibleByExtendedGraphemeClusterLiteral
A type that can be initialized with a string literal.
protocol ExpressibleByUnicodeScalarLiteral
A type that can be initialized with a string literal containing a single Unicode scalar value.
init(floatLiteral value: Double)
init(integerLiteral value: Int32)
init(nilLiteral _: ())
init(stringLiteral value: String)
static func construct(from value: JSValue) -> Self?
static func string(_ value: String) -> JSValue
var array: JSArray? { get }
var bigInt: JSBigInt? { get }
Returns the JSBigInt
of this JS value if its type is function. If not, returns nil
.
var boolean: Bool? { get }
Returns the Bool
value of this JS value if its type is boolean. If not, returns nil
.
var description: String { get }
var function: JSFunction? { get }
Returns the JSFunction
of this JS value if its type is function. If not, returns nil
.
var isNull: Bool { get }
Returns the true
if this JS value is null. If not, returns false
.
var isUndefined: Bool { get }
Returns the true
if this JS value is undefined. If not, returns false
.
var jsString: JSString? { get }
Returns the JSString
value of this JS value if the type is string. If not, returns nil
.
var jsValue: JSValue { get }
var number: Double? { get }
Returns the Double
value of this JS value if the type is number. If not, returns nil
.
var object: JSObject? { get }
Returns the JSObject
of this JS value if its type is object. If not, returns nil
.
var string: String? { get }
Returns the String
value of this JS value if the type is string. If not, returns nil
.
var symbol: JSSymbol? { get }
Returns the JSSymbol
of this JS value if its type is function. If not, returns nil
.
subscript(index: Int) -> JSValue { get set }
An unsafe convenience method of JSObject.subscript(_ index: Int) -> JSValue
subscript(dynamicMember name: String) -> JSValue { get set }
An unsafe convenience method of JSObject.subscript(_ index: Int) -> JSValue
subscript(dynamicMember name: String) -> ((ConvertibleToJSValue...) -> JSValue) { get }
An unsafe convenience method of JSObject.subscript(_ name: String) -> ((ConvertibleToJSValue...) -> JSValue)?
func fromJSValue<Type>() -> Type? where Type : ConstructibleFromJSValue
func isInstanceOf(_ constructor: JSFunction) -> Bool
Return true
if this value is an instance of the passed constructor
function. Returns false
for everything except objects and functions.
static func function(_ body: @escaping ([JSValue]) -> JSValue) -> JSValue
Deprecated: Please create JSClosure
directly and manage its lifetime manually.
static func function(_ closure: JSClosure) -> JSValue
init(extendedGraphemeClusterLiteral value: Self.StringLiteralType)
init(unicodeScalarLiteral value: Self.ExtendedGraphemeClusterLiteralType)
static func != (lhs: Self, rhs: Self) -> Bool
Returns a Boolean value indicating whether two values are not equal.
func jsValue() -> JSValue