Skip to content

Commit f08c56c

Browse files
committed
Make classRef required
1 parent bbf990b commit f08c56c

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

Sources/JavaScriptKit/JSValueConvertible.swift

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import _CJavaScriptKit
22

33
public protocol JSBridgedType: JSValueCodable, CustomStringConvertible {
4-
static var classRef: JSFunctionRef? { get }
4+
static var classRef: JSFunctionRef { get }
55

66
var objectRef: JSObjectRef { get }
77
init(objectRef: JSObjectRef)
88
}
99

1010
extension JSBridgedType {
11-
static var classRef: JSFunctionRef? { nil }
1211
public var description: String {
1312
return objectRef.toString!().fromJSValue()
1413
}
@@ -29,10 +28,7 @@ public typealias JSValueCodable = JSValueEncodable & JSValueDecodable
2928
extension JSBridgedType {
3029
public static func canDecode(from jsValue: JSValue) -> Bool {
3130
if let object = jsValue.object {
32-
if let constructor = Self.classRef {
33-
return JSObjectRef.instanceof(object, constructor: constructor)
34-
}
35-
return true
31+
return JSObjectRef.instanceof(object, constructor: Self.classRef)
3632
}
3733
return false
3834
}

Sources/JavaScriptKit/Support.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public func staticCast<Type: JSBridgedType>(_ ref: JSBridgedType) -> Type {
234234
}
235235

236236
public func dynamicCast<Type: JSBridgedType>(_ ref: JSBridgedType) -> Type? {
237-
guard let constructor = Type.classRef, JSObjectRef.instanceof(ref.objectRef, constructor: constructor) else {
237+
guard JSObjectRef.instanceof(ref.objectRef, constructor: Type.classRef) else {
238238
return nil
239239
}
240240
return staticCast(ref)

0 commit comments

Comments
 (0)