@@ -35,9 +35,9 @@ public class JSObject: Equatable {
35
35
/// - Parameter name: The name of this object's member to access.
36
36
/// - Returns: The `name` member method binding this object as `this` context.
37
37
@_disfavoredOverload
38
- public subscript( _ name: String ) -> ( ( ConvertibleToJSValue . . . ) -> JSValue ) ? {
38
+ public subscript( _ name: String ) -> DiscardableResultClosure ? {
39
39
guard let function = self [ name] . function else { return nil }
40
- return { ( arguments: ConvertibleToJSValue ... ) in
40
+ return DiscardableResultClosure { arguments in
41
41
function ( this: self , arguments: arguments)
42
42
}
43
43
}
@@ -53,17 +53,17 @@ public class JSObject: Equatable {
53
53
/// - Parameter name: The name of this object's member to access.
54
54
/// - Returns: The `name` member method binding this object as `this` context.
55
55
@_disfavoredOverload
56
- public subscript( _ name: JSString ) -> ( ( ConvertibleToJSValue . . . ) -> JSValue ) ? {
56
+ public subscript( _ name: JSString ) -> DiscardableResultClosure ? {
57
57
guard let function = self [ name] . function else { return nil }
58
- return { ( arguments: ConvertibleToJSValue ... ) in
58
+ return DiscardableResultClosure { arguments in
59
59
function ( this: self , arguments: arguments)
60
60
}
61
61
}
62
62
63
63
/// A convenience method of `subscript(_ name: String) -> ((ConvertibleToJSValue...) -> JSValue)?`
64
64
/// to access the member through Dynamic Member Lookup.
65
65
@_disfavoredOverload
66
- public subscript( dynamicMember name: String ) -> ( ( ConvertibleToJSValue . . . ) -> JSValue ) ? {
66
+ public subscript( dynamicMember name: String ) -> DiscardableResultClosure ? {
67
67
self [ name]
68
68
}
69
69
#endif
@@ -232,6 +232,19 @@ public class JSThrowingObject {
232
232
#endif
233
233
234
234
235
+ #if !hasFeature(Embedded)
236
+ /// A swift closure wrapper that can be called as function.
237
+ /// This prevents the warnings for unused results through `@discardableResult` which means you no longer need `_ =` everywhere.
238
+ public struct DiscardableResultClosure {
239
+ var closure : ( [ ConvertibleToJSValue ] ) -> JSValue
240
+
241
+ @discardableResult
242
+ public func callAsFunction( _ args: ConvertibleToJSValue ... ) -> JSValue {
243
+ return self . closure ( args)
244
+ }
245
+ }
246
+ #endif
247
+
235
248
#if hasFeature(Embedded)
236
249
// NOTE: once embedded supports variadic generics, we can remove these overloads
237
250
public extension JSObject {
0 commit comments