Skip to content

Commit ddcd9dc

Browse files
committed
Rename constructor
1 parent fc991c2 commit ddcd9dc

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)
@@ -21,11 +21,7 @@ public typealias JSValueCodable = JSValueConvertible & JSValueConstructible
2121

2222
extension JSBridgedType {
2323
public static func canDecode(from jsValue: JSValue) -> Bool {
24-
if let constructor = Self.constructor {
25-
return jsValue.isInstanceOf(constructor)
26-
} else {
27-
return jsValue.isObject
28-
}
24+
jsValue.isInstanceOf(Self.classRef)
2925
}
3026

3127
public init(jsValue: JSValue) {

Sources/JavaScriptKit/Support.swift

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

5252
public func dynamicCast<Type: JSBridgedType>(_ ref: JSBridgedType) -> Type? {
53-
guard let constructor = Type.constructor, ref.objectRef.isInstanceOf(constructor) else {
53+
guard ref.objectRef.isInstanceOf(Type.classRef) else {
5454
return nil
5555
}
5656
return staticCast(ref)

0 commit comments

Comments
 (0)