Skip to content

Commit 0906080

Browse files
committed
Rename constructor
1 parent 6896e3a commit 0906080

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

Sources/JavaScriptKit/JSValueConvertible.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import _CJavaScriptKit
22

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

66
var objectRef: JSObjectRef { get }
77
init(objectRef: JSObjectRef)
@@ -27,11 +27,7 @@ public typealias JSValueCodable = JSValueEncodable & JSValueDecodable
2727

2828
extension JSBridgedType {
2929
public static func canDecode(from jsValue: JSValue) -> Bool {
30-
if let constructor = Self.constructor {
31-
return jsValue.isInstanceOf(constructor)
32-
} else {
33-
return jsValue.isObject
34-
}
30+
jsValue.isInstanceOf(Self.classRef)
3531
}
3632

3733
public init(jsValue: JSValue) {

Sources/JavaScriptKit/Support.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public func staticCast<Type: JSBridgedType>(_ ref: JSBridgedType) -> Type {
222222
}
223223

224224
public func dynamicCast<Type: JSBridgedType>(_ ref: JSBridgedType) -> Type? {
225-
guard let constructor = Type.constructor, ref.objectRef.isInstanceOf(constructor) else {
225+
guard ref.objectRef.isInstanceOf(Type.classRef) else {
226226
return nil
227227
}
228228
return staticCast(ref)

0 commit comments

Comments
 (0)