Skip to content

Commit e31a989

Browse files
committed
wip
1 parent fbf9f76 commit e31a989

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

Diff for: Sources/JavaScriptKit/JSBridgedType.swift

+5-6
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@
33
public protocol JSBridgedType: JSValueCodable, CustomStringConvertible {
44
var objectRef: JSObject { get }
55
init?(objectRef: JSObject)
6-
static func canDecode(_ object: JSObject) -> Bool
76
}
87

98
extension JSBridgedType {
109
public static func construct(from value: JSValue) -> Self? {
11-
guard let object = value.object, canDecode(object) else {
12-
return nil
13-
}
10+
guard let object = value.object else { return nil }
1411
return Self.init(objectRef: object)
1512
}
1613

@@ -26,11 +23,13 @@ extension JSBridgedType {
2623

2724
public protocol JSBridgedClass: JSBridgedType {
2825
static var classRef: JSFunction { get }
26+
init(withCompatibleObject objectRef: JSObject)
2927
}
3028

3129
extension JSBridgedClass {
32-
public static func canDecode(from jsValue: JSValue) -> Bool {
33-
jsValue.isInstanceOf(Self.classRef)
30+
public init?(objectRef: JSObject) {
31+
guard objectRef.isInstanceOf(Self.classRef) else { return nil }
32+
self.init(withCompatibleObject: objectRef)
3433
}
3534
}
3635

0 commit comments

Comments
 (0)