Skip to content

Commit

Permalink
Rename constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
j-f1 committed Aug 4, 2020
1 parent 6896e3a commit 0906080
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
8 changes: 2 additions & 6 deletions Sources/JavaScriptKit/JSValueConvertible.swift
@@ -1,7 +1,7 @@
import _CJavaScriptKit

public protocol JSBridgedType: JSValueCodable, CustomStringConvertible {
static var constructor: JSFunctionRef? { get }
static var classRef: JSFunctionRef { get }

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

extension JSBridgedType {
public static func canDecode(from jsValue: JSValue) -> Bool {
if let constructor = Self.constructor {
return jsValue.isInstanceOf(constructor)
} else {
return jsValue.isObject
}
jsValue.isInstanceOf(Self.classRef)
}

public init(jsValue: JSValue) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/JavaScriptKit/Support.swift
Expand Up @@ -222,7 +222,7 @@ public func staticCast<Type: JSBridgedType>(_ ref: JSBridgedType) -> Type {
}

public func dynamicCast<Type: JSBridgedType>(_ ref: JSBridgedType) -> Type? {
guard let constructor = Type.constructor, ref.objectRef.isInstanceOf(constructor) else {
guard ref.objectRef.isInstanceOf(Type.classRef) else {
return nil
}
return staticCast(ref)
Expand Down

0 comments on commit 0906080

Please sign in to comment.