File tree Expand file tree Collapse file tree 4 files changed +18
-3
lines changed Expand file tree Collapse file tree 4 files changed +18
-3
lines changed Original file line number Diff line number Diff line change 1- // Use this protocol when your type has no single JavaScript class.
2- // For example, a union type of multiple classes.
1+ /// Use this protocol when your type has no single JavaScript class.
2+ /// For example, a union type of multiple classes or primitive values .
33public protocol JSBridgedType : JSValueCodable , CustomStringConvertible {
4+ /// This is the value your class wraps.
45 var value : JSValue { get }
6+
7+ /// If your class is incompatible with the provided value, return `nil`.
58 init ? ( from value: JSValue )
69}
710
@@ -15,10 +18,17 @@ extension JSBridgedType {
1518 public var description : String { value. description }
1619}
1720
18-
21+ /// Conform to this protocol when your Swift class wraps a JavaScript class.
1922public protocol JSBridgedClass : JSBridgedType {
23+ /// The constructor function for the JavaScript class
2024 static var constructor : JSFunction { get }
25+
26+ /// The JavaScript object wrapped by this instance.
27+ /// You may assume that `jsObject instanceof Self.constructor`
2128 var jsObject : JSObject { get }
29+
30+ /// Create an instannce wrapping the given JavaScript object.
31+ /// You may assume that `jsObject instanceof Self.constructor`
2232 init ( withCompatibleObject jsObject: JSObject )
2333}
2434
Original file line number Diff line number Diff line change 1+ /// Objects that can be constructed from a JavaScript value
12public protocol JSValueConstructible {
3+ /// Return `nil` if the value is not compatible with the conforming Swift type.
24 static func construct( from value: JSValue ) -> Self ?
35}
46
Original file line number Diff line number Diff line change 11import _CJavaScriptKit
22
3+ /// Objects that can be converted to a JavaScript value, preferably in a lossless manner.
34public protocol JSValueConvertible {
5+ /// Create a JSValue that represents this object
46 func jsValue( ) -> JSValue
57}
68
Original file line number Diff line number Diff line change 11protocol _AnyJSValueConvertible : JSValueConvertible { }
22
3+ /// A type-erased wrapper for types conforming to JSValueConvertible
34public struct AnyJSValueConvertible : JSValueCodable , ExpressibleByNilLiteral {
45 public static let void = AnyJSValueConvertible . construct ( from: . undefined)
56
You can’t perform that action at this time.
0 commit comments