@@ -2,11 +2,10 @@ import _CJavaScriptKit
22
33@dynamicCallable
44public class JSFunctionRef : JSObjectRef {
5-
65 @discardableResult
76 public func dynamicallyCall( withArguments arguments: [ JSValueConvertible ] ) -> JSValue {
87 let result = arguments. withRawJSValues { rawValues -> RawJSValue in
9- return rawValues. withUnsafeBufferPointer { bufferPointer -> RawJSValue in
8+ rawValues. withUnsafeBufferPointer { bufferPointer -> RawJSValue in
109 let argv = bufferPointer. baseAddress
1110 let argc = bufferPointer. count
1211 var result = RawJSValue ( )
@@ -23,16 +22,16 @@ public class JSFunctionRef: JSObjectRef {
2322 public func apply( this: JSObjectRef , arguments: JSValueConvertible ... ) -> JSValue {
2423 apply ( this: this, argumentList: arguments)
2524 }
25+
2626 public func apply( this: JSObjectRef , argumentList: [ JSValueConvertible ] ) -> JSValue {
2727 let result = argumentList. withRawJSValues { rawValues in
2828 rawValues. withUnsafeBufferPointer { bufferPointer -> RawJSValue in
2929 let argv = bufferPointer. baseAddress
3030 let argc = bufferPointer. count
3131 var result = RawJSValue ( )
3232 _call_function_with_this ( this. id,
33- self . id, argv, Int32 ( argc) ,
34- & result. kind, & result. payload1, & result. payload2, & result. payload3
35- )
33+ self . id, argv, Int32 ( argc) ,
34+ & result. kind, & result. payload1, & result. payload2, & result. payload3)
3635 return result
3736 }
3837 }
@@ -55,17 +54,16 @@ public class JSFunctionRef: JSObjectRef {
5554 }
5655
5756 @available ( * , unavailable, message: " Please use JSClosure instead " )
58- public static func from( _ body : @escaping ( [ JSValue ] ) -> JSValue ) -> JSFunctionRef {
57+ public static func from( _: @escaping ( [ JSValue ] ) -> JSValue ) -> JSFunctionRef {
5958 fatalError ( " unavailable " )
6059 }
6160
62- public override func jsValue( ) -> JSValue {
61+ override public func jsValue( ) -> JSValue {
6362 . function( self )
6463 }
6564}
6665
6766public class JSClosure : JSFunctionRef {
68-
6967 static var sharedFunctions : [ JavaScriptHostFuncRef : ( [ JSValue ] ) -> JSValue ] = [ : ]
7068
7169 private var hostFuncRef : JavaScriptHostFuncRef = 0
@@ -79,16 +77,15 @@ public class JSClosure: JSFunctionRef {
7977 var objectRef : JavaScriptObjectRef = 0
8078 _create_function ( funcRef, & objectRef)
8179
82- self . hostFuncRef = funcRef
83- self . id = objectRef
80+ hostFuncRef = funcRef
81+ id = objectRef
8482 }
8583
8684 public func release( ) {
8785 Self . sharedFunctions [ hostFuncRef] = nil
8886 }
8987}
9088
91-
9289@_cdecl ( " swjs_prepare_host_function_call " )
9390public func _prepare_host_function_call( _ argc: Int32 ) -> UnsafeMutableRawPointer {
9491 let argumentSize = MemoryLayout< RawJSValue> . size * Int( argc)
@@ -104,7 +101,8 @@ public func _cleanup_host_function_call(_ pointer: UnsafeMutableRawPointer) {
104101public func _call_host_function(
105102 _ hostFuncRef: JavaScriptHostFuncRef ,
106103 _ argv: UnsafePointer < RawJSValue > , _ argc: Int32 ,
107- _ callbackFuncRef: JavaScriptObjectRef ) {
104+ _ callbackFuncRef: JavaScriptObjectRef
105+ ) {
108106 guard let hostFunc = JSClosure . sharedFunctions [ hostFuncRef] else {
109107 fatalError ( " The function was already released " )
110108 }
0 commit comments