Skip to content

Commit e68d137

Browse files
Make JSFunctionRef inherit JSObjectRef
1 parent c87cf07 commit e68d137

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

Diff for: Sources/JavaScriptKit/JSFunction.swift

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
import _CJavaScriptKit
22

33
@dynamicCallable
4-
public class JSFunctionRef: Equatable {
5-
let id: UInt32
6-
7-
init(id: UInt32) {
8-
self.id = id
9-
}
10-
11-
public static func == (lhs: JSFunctionRef, rhs: JSFunctionRef) -> Bool {
12-
return lhs.id == rhs.id
13-
}
4+
public class JSFunctionRef: JSObjectRef {
145

156
@discardableResult
167
public func dynamicallyCall(withArguments arguments: [JSValueConvertible]) -> JSValue {
@@ -72,6 +63,10 @@ public class JSFunctionRef: Equatable {
7263

7364
return JSFunctionRef(id: funcRef)
7465
}
66+
67+
public override func jsValue() -> JSValue {
68+
.function(self)
69+
}
7570
}
7671

7772

Diff for: Sources/JavaScriptKit/JSObject.swift

+4
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,8 @@ public class JSObjectRef: Equatable {
4949
public static func == (lhs: JSObjectRef, rhs: JSObjectRef) -> Bool {
5050
return lhs.id == rhs.id
5151
}
52+
53+
public func jsValue() -> JSValue {
54+
.object(self)
55+
}
5256
}

Diff for: Sources/JavaScriptKit/JSValueConvertible.swift

+2-5
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@ extension String: JSValueConvertible {
2121
}
2222

2323
extension JSObjectRef: JSValueConvertible {
24-
public func jsValue() -> JSValue { .object(self) }
25-
}
26-
27-
extension JSFunctionRef: JSValueConvertible {
28-
public func jsValue() -> JSValue { .function(self) }
24+
// `JSObjectRef.jsValue` is defined in JSObjectRef.swift to be able to overridden
25+
// from `JSFunctionRef`
2926
}
3027

3128
private let Object = JSObjectRef.global.Object.function!

0 commit comments

Comments
 (0)