Skip to content

Commit

Permalink
Make dyamicMember return a JSFunctionRef in the disfavoredOverload
Browse files Browse the repository at this point in the history
  • Loading branch information
j-f1 committed Aug 4, 2020
1 parent 9b47115 commit ab414d7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
13 changes: 4 additions & 9 deletions Sources/JavaScriptKit/JSObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,14 @@ public class JSObjectRef: Equatable {
}

@_disfavoredOverload
public subscript(_ name: String) -> ((JSValueEncodable...) -> JSValue)? {
public subscript(_ name: String) -> JSFunctionRef? {
guard let function = self[name].function else { return nil }
return { (arguments: JSValueEncodable...) in
function(this: self, args: arguments)
}
return function
}

@_disfavoredOverload
public subscript(dynamicMember name: String) -> ((JSValueEncodable...) -> JSValue)? {
guard let function = self[name].function else { return nil }
return { (arguments: JSValueEncodable...) in
function(this: self, args: arguments)
}
public subscript(dynamicMember name: String) -> JSFunctionRef? {
self[name]
}

public subscript(dynamicMember name: String) -> JSValue {
Expand Down
3 changes: 1 addition & 2 deletions Sources/JavaScriptKit/JSValueConvertible.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,9 @@ extension Dictionary: JSValueDecodable where Value: JSValueDecodable, Key == Str

public init(jsValue: JSValue) {
let objectRef: JSObjectRef = jsValue.object!

let keys: [String] = JSObject.keys!(objectRef.jsValue()).fromJSValue()
self = Dictionary(uniqueKeysWithValues: keys.map {
($0, objectRef[dynamicMember: $0].fromJSValue())
($0, objectRef[$0].fromJSValue())
})
}
}
Expand Down

0 comments on commit ab414d7

Please sign in to comment.