Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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‎

Lines changed: 2 additions & 6 deletions
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‎

Lines changed: 1 addition & 1 deletion
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)

AltStyle によって変換されたページ (->オリジナル) /