@@ -11,14 +11,15 @@ import _CJavaScriptKit
1111/// ```
1212///
1313public class JSFunction : JSObject {
14+
1415 /// Call this function with given `arguments` and binding given `this` as context.
1516 /// - Parameters:
1617 /// - this: The value to be passed as the `this` parameter to this function.
1718 /// - arguments: Arguments to be passed to this function.
1819 /// - Returns: The result of this call.
1920 @discardableResult
2021 public func callAsFunction( this: JSObject ? = nil , arguments: [ ConvertibleToJSValue ] ) -> JSValue {
21- invokeNonThrowingJSFunction ( self , arguments: arguments, this: this) . jsValue
22+ invokeNonThrowingJSFunction ( self , arguments: arguments, this: this)
2223 }
2324
2425 /// A variadic arguments version of `callAsFunction`.
@@ -40,7 +41,7 @@ public class JSFunction: JSObject {
4041 public func new( arguments: [ ConvertibleToJSValue ] ) -> JSObject {
4142 arguments. withRawJSValues { rawValues in
4243 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) ) )
4445 }
4546 }
4647 }
@@ -74,7 +75,7 @@ public class JSFunction: JSObject {
7475 fatalError ( " unavailable " )
7576 }
7677
77- override public class func construct( from value: JSValue ) -> Self ? {
78+ public override class func construct( from value: JSValue ) -> Self ? {
7879 return value. function as? Self
7980 }
8081
@@ -83,18 +84,18 @@ public class JSFunction: JSObject {
8384 }
8485}
8586
86- func invokeNonThrowingJSFunction( _ jsFunc: JSFunction , arguments: [ ConvertibleToJSValue ] , this: JSObject ? ) -> RawJSValue {
87+ private func invokeNonThrowingJSFunction( _ jsFunc: JSFunction , arguments: [ ConvertibleToJSValue ] , this: JSObject ? ) -> JSValue {
8788 arguments. withRawJSValues { rawValues in
88- rawValues. withUnsafeBufferPointer { bufferPointer in
89+ rawValues. withUnsafeBufferPointer { bufferPointer -> ( JSValue ) in
8990 let argv = bufferPointer. baseAddress
9091 let argc = bufferPointer. count
9192 var kindAndFlags = JavaScriptValueKindAndFlags ( )
9293 var payload1 = JavaScriptPayload1 ( )
9394 var payload2 = JavaScriptPayload2 ( )
9495 if let thisId = this? . id {
9596 _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)
9899 } else {
99100 _call_function_no_catch (
100101 jsFunc. id, argv, Int32 ( argc) ,
@@ -103,7 +104,7 @@ func invokeNonThrowingJSFunction(_ jsFunc: JSFunction, arguments: [ConvertibleTo
103104 }
104105 assert ( !kindAndFlags. isException)
105106 let result = RawJSValue ( kind: kindAndFlags. kind, payload1: payload1, payload2: payload2)
106- return result
107+ return result. jsValue ( )
107108 }
108109 }
109110}
0 commit comments