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 .
3
3
public protocol JSBridgedType : JSValueCodable , CustomStringConvertible {
4
+ /// This is the value your class wraps.
4
5
var value : JSValue { get }
6
+
7
+ /// If your class is incompatible with the provided value, return `nil`.
5
8
init ? ( from value: JSValue )
6
9
}
7
10
@@ -15,10 +18,17 @@ extension JSBridgedType {
15
18
public var description : String { value. description }
16
19
}
17
20
18
-
21
+ /// Conform to this protocol when your Swift class wraps a JavaScript class.
19
22
public protocol JSBridgedClass : JSBridgedType {
23
+ /// The constructor function for the JavaScript class
20
24
static var constructor : JSFunction { get }
25
+
26
+ /// The JavaScript object wrapped by this instance.
27
+ /// You may assume that `jsObject instanceof Self.constructor`
21
28
var jsObject : JSObject { get }
29
+
30
+ /// Create an instannce wrapping the given JavaScript object.
31
+ /// You may assume that `jsObject instanceof Self.constructor`
22
32
init ( withCompatibleObject jsObject: JSObject )
23
33
}
24
34
Original file line number Diff line number Diff line change
1
+ /// Objects that can be constructed from a JavaScript value
1
2
public protocol JSValueConstructible {
3
+ /// Return `nil` if the value is not compatible with the conforming Swift type.
2
4
static func construct( from value: JSValue ) -> Self ?
3
5
}
4
6
Original file line number Diff line number Diff line change 1
1
import _CJavaScriptKit
2
2
3
+ /// Objects that can be converted to a JavaScript value, preferably in a lossless manner.
3
4
public protocol JSValueConvertible {
5
+ /// Create a JSValue that represents this object
4
6
func jsValue( ) -> JSValue
5
7
}
6
8
Original file line number Diff line number Diff line change 1
1
protocol _AnyJSValueConvertible : JSValueConvertible { }
2
2
3
+ /// A type-erased wrapper for types conforming to JSValueConvertible
3
4
public struct AnyJSValueConvertible : JSValueCodable , ExpressibleByNilLiteral {
4
5
public static let void = AnyJSValueConvertible . construct ( from: . undefined)
5
6
You can’t perform that action at this time.
0 commit comments