@@ -11,14 +11,15 @@ import _CJavaScriptKit
11
11
/// ```
12
12
///
13
13
public class JSFunction : JSObject {
14
+
14
15
/// Call this function with given `arguments` and binding given `this` as context.
15
16
/// - Parameters:
16
17
/// - this: The value to be passed as the `this` parameter to this function.
17
18
/// - arguments: Arguments to be passed to this function.
18
19
/// - Returns: The result of this call.
19
20
@discardableResult
20
21
public func callAsFunction( this: JSObject ? = nil , arguments: [ ConvertibleToJSValue ] ) -> JSValue {
21
- invokeNonThrowingJSFunction ( self , arguments: arguments, this: this) . jsValue
22
+ invokeNonThrowingJSFunction ( self , arguments: arguments, this: this)
22
23
}
23
24
24
25
/// A variadic arguments version of `callAsFunction`.
@@ -40,7 +41,7 @@ public class JSFunction: JSObject {
40
41
public func new( arguments: [ ConvertibleToJSValue ] ) -> JSObject {
41
42
arguments. withRawJSValues { rawValues in
42
43
rawValues. withUnsafeBufferPointer { bufferPointer in
43
- JSObject ( id: _call_new ( self . id, bufferPointer. baseAddress!, Int32 ( bufferPointer. count) ) )
44
+ return JSObject ( id: _call_new ( self . id, bufferPointer. baseAddress!, Int32 ( bufferPointer. count) ) )
44
45
}
45
46
}
46
47
}
@@ -74,7 +75,7 @@ public class JSFunction: JSObject {
74
75
fatalError ( " unavailable " )
75
76
}
76
77
77
- override public class func construct( from value: JSValue ) -> Self ? {
78
+ public override class func construct( from value: JSValue ) -> Self ? {
78
79
return value. function as? Self
79
80
}
80
81
@@ -83,18 +84,18 @@ public class JSFunction: JSObject {
83
84
}
84
85
}
85
86
86
- func invokeNonThrowingJSFunction( _ jsFunc: JSFunction , arguments: [ ConvertibleToJSValue ] , this: JSObject ? ) -> RawJSValue {
87
+ private func invokeNonThrowingJSFunction( _ jsFunc: JSFunction , arguments: [ ConvertibleToJSValue ] , this: JSObject ? ) -> JSValue {
87
88
arguments. withRawJSValues { rawValues in
88
- rawValues. withUnsafeBufferPointer { bufferPointer in
89
+ rawValues. withUnsafeBufferPointer { bufferPointer -> ( JSValue ) in
89
90
let argv = bufferPointer. baseAddress
90
91
let argc = bufferPointer. count
91
92
var kindAndFlags = JavaScriptValueKindAndFlags ( )
92
93
var payload1 = JavaScriptPayload1 ( )
93
94
var payload2 = JavaScriptPayload2 ( )
94
95
if let thisId = this? . id {
95
96
_call_function_with_this_no_catch ( thisId,
96
- jsFunc. id, argv, Int32 ( argc) ,
97
- & kindAndFlags, & payload1, & payload2)
97
+ jsFunc. id, argv, Int32 ( argc) ,
98
+ & kindAndFlags, & payload1, & payload2)
98
99
} else {
99
100
_call_function_no_catch (
100
101
jsFunc. id, argv, Int32 ( argc) ,
@@ -103,7 +104,7 @@ func invokeNonThrowingJSFunction(_ jsFunc: JSFunction, arguments: [ConvertibleTo
103
104
}
104
105
assert ( !kindAndFlags. isException)
105
106
let result = RawJSValue ( kind: kindAndFlags. kind, payload1: payload1, payload2: payload2)
106
- return result
107
+ return result. jsValue ( )
107
108
}
108
109
}
109
110
}
0 commit comments