Skip to content

Commit a0cd56c

Browse files
committed
Make classRef required
1 parent 3eb0c04 commit a0cd56c

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 object.instanceof(constructor)
34-
}
35-
return true
31+
return object.instanceof(Self.classRef)
3632
}
3733
return false
3834
}

Sources/JavaScriptKit/Support.swift

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

239239
public func dynamicCast<Type: JSBridgedType>(_ ref: JSBridgedType) -> Type? {
240-
guard let constructor = Type.classRef, ref.objectRef.instanceof(constructor) else {
240+
guard ref.objectRef.instanceof(Type.classRef) else {
241241
return nil
242242
}
243243
return staticCast(ref)

0 commit comments

Comments
 (0)