@@ -17,16 +17,31 @@ public class JSFunction: JSObject {
17
17
/// - arguments: Arguments to be passed to this function.
18
18
/// - Returns: The result of this call.
19
19
@discardableResult
20
- public func callAsFunction( this: JSObject ? = nil , arguments: [ ConvertibleToJSValue ] ) -> JSValue {
21
- invokeNonThrowingJSFunction ( self , arguments: arguments, this: this) . jsValue
20
+ public func callAsFunction( this: JSObject , arguments: [ ConvertibleToJSValue ] ) -> JSValue {
21
+ invokeNonThrowingJSFunction ( arguments: arguments, this: this) . jsValue
22
+ }
23
+
24
+ /// Call this function with given `arguments`.
25
+ /// - Parameters:
26
+ /// - arguments: Arguments to be passed to this function.
27
+ /// - Returns: The result of this call.
28
+ @discardableResult
29
+ public func callAsFunction( arguments: [ ConvertibleToJSValue ] ) -> JSValue {
30
+ invokeNonThrowingJSFunction ( arguments: arguments) . jsValue
22
31
}
23
32
24
33
/// A variadic arguments version of `callAsFunction`.
25
34
@discardableResult
26
- public func callAsFunction( this: JSObject ? = nil , _ arguments: ConvertibleToJSValue ... ) -> JSValue {
35
+ public func callAsFunction( this: JSObject , _ arguments: ConvertibleToJSValue ... ) -> JSValue {
27
36
self ( this: this, arguments: arguments)
28
37
}
29
38
39
+ /// A variadic arguments version of `callAsFunction`.
40
+ @discardableResult
41
+ public func callAsFunction( _ arguments: ConvertibleToJSValue ... ) -> JSValue {
42
+ self ( arguments: arguments)
43
+ }
44
+
30
45
/// Instantiate an object from this function as a constructor.
31
46
///
32
47
/// Guaranteed to return an object because either:
@@ -81,30 +96,42 @@ public class JSFunction: JSObject {
81
96
override public var jsValue : JSValue {
82
97
. function( self )
83
98
}
84
- }
85
99
86
- func invokeNonThrowingJSFunction( _ jsFunc: JSFunction , arguments: [ ConvertibleToJSValue ] , this: JSObject ? ) -> RawJSValue {
87
- arguments. withRawJSValues { rawValues in
88
- rawValues. withUnsafeBufferPointer { bufferPointer in
89
- let argv = bufferPointer. baseAddress
90
- let argc = bufferPointer. count
91
- var kindAndFlags = JavaScriptValueKindAndFlags ( )
92
- var payload1 = JavaScriptPayload1 ( )
93
- var payload2 = JavaScriptPayload2 ( )
94
- if let thisId = this? . id {
95
- _call_function_with_this_no_catch ( thisId,
96
- jsFunc. id, argv, Int32 ( argc) ,
97
- & kindAndFlags, & payload1, & payload2)
98
- } else {
99
- let result = _call_function_no_catch (
100
- jsFunc. id, argv, Int32 ( argc) ,
100
+ final func invokeNonThrowingJSFunction( arguments: [ ConvertibleToJSValue ] ) -> RawJSValue {
101
+ arguments. withRawJSValues { rawValues in
102
+ rawValues. withUnsafeBufferPointer { bufferPointer in
103
+ let argv = bufferPointer. baseAddress
104
+ let argc = bufferPointer. count
105
+ var kindAndFlags = JavaScriptValueKindAndFlags ( )
106
+ var payload1 = JavaScriptPayload1 ( )
107
+ var payload2 = JavaScriptPayload2 ( )
108
+ let resultBitPattern = _call_function_no_catch (
109
+ id, argv, Int32 ( argc) ,
101
110
& payload1, & payload2
102
111
)
103
- kindAndFlags = unsafeBitCast ( result, to: JavaScriptValueKindAndFlags . self)
112
+ kindAndFlags = unsafeBitCast ( resultBitPattern, to: JavaScriptValueKindAndFlags . self)
113
+ assert ( !kindAndFlags. isException)
114
+ let result = RawJSValue ( kind: kindAndFlags. kind, payload1: payload1, payload2: payload2)
115
+ return result
116
+ }
117
+ }
118
+ }
119
+
120
+ final func invokeNonThrowingJSFunction( arguments: [ ConvertibleToJSValue ] , this: JSObject ) -> RawJSValue {
121
+ arguments. withRawJSValues { rawValues in
122
+ rawValues. withUnsafeBufferPointer { bufferPointer in
123
+ let argv = bufferPointer. baseAddress
124
+ let argc = bufferPointer. count
125
+ var kindAndFlags = JavaScriptValueKindAndFlags ( )
126
+ var payload1 = JavaScriptPayload1 ( )
127
+ var payload2 = JavaScriptPayload2 ( )
128
+ _call_function_with_this_no_catch ( this. id,
129
+ id, argv, Int32 ( argc) ,
130
+ & kindAndFlags, & payload1, & payload2)
131
+ assert ( !kindAndFlags. isException)
132
+ let result = RawJSValue ( kind: kindAndFlags. kind, payload1: payload1, payload2: payload2)
133
+ return result
104
134
}
105
- assert ( !kindAndFlags. isException)
106
- let result = RawJSValue ( kind: kindAndFlags. kind, payload1: payload1, payload2: payload2)
107
- return result
108
135
}
109
136
}
110
137
}
0 commit comments