1
1
import _CJavaScriptKit
2
2
3
- public class JSFunctionRef : JSObjectRef {
3
+ public class JSFunction : JSObject {
4
4
@discardableResult
5
- public func callAsFunction( this: JSObjectRef ? = nil , arguments: [ JSValueConvertible ] ) -> JSValue {
5
+ public func callAsFunction( this: JSObject ? = nil , arguments: [ JSValueConvertible ] ) -> JSValue {
6
6
let result = arguments. withRawJSValues { rawValues in
7
7
rawValues. withUnsafeBufferPointer { bufferPointer -> RawJSValue in
8
8
let argv = bufferPointer. baseAddress
@@ -25,19 +25,19 @@ public class JSFunctionRef: JSObjectRef {
25
25
}
26
26
27
27
@discardableResult
28
- public func callAsFunction( this: JSObjectRef ? = nil , _ arguments: JSValueConvertible ... ) -> JSValue {
28
+ public func callAsFunction( this: JSObject ? = nil , _ arguments: JSValueConvertible ... ) -> JSValue {
29
29
self ( this: this, arguments: arguments)
30
30
}
31
31
32
- public func new( _ arguments: JSValueConvertible ... ) -> JSObjectRef {
32
+ public func new( _ arguments: JSValueConvertible ... ) -> JSObject {
33
33
new ( arguments: arguments)
34
34
}
35
35
36
36
// Guaranteed to return an object because either:
37
37
// a) the constructor explicitly returns an object, or
38
38
// b) the constructor returns nothing, which causes JS to return the `this` value, or
39
39
// c) the constructor returns undefined, null or a non-object, in which case JS also returns `this`.
40
- public func new( arguments: [ JSValueConvertible ] ) -> JSObjectRef {
40
+ public func new( arguments: [ JSValueConvertible ] ) -> JSObject {
41
41
arguments. withRawJSValues { rawValues in
42
42
rawValues. withUnsafeBufferPointer { bufferPointer in
43
43
let argv = bufferPointer. baseAddress
@@ -47,13 +47,13 @@ public class JSFunctionRef: JSObjectRef {
47
47
self . id, argv, Int32 ( argc) ,
48
48
& resultObj
49
49
)
50
- return JSObjectRef ( id: resultObj)
50
+ return JSObject ( id: resultObj)
51
51
}
52
52
}
53
53
}
54
54
55
55
@available ( * , unavailable, message: " Please use JSClosure instead " )
56
- public static func from( _: @escaping ( [ JSValue ] ) -> JSValue ) -> JSFunctionRef {
56
+ public static func from( _: @escaping ( [ JSValue ] ) -> JSValue ) -> JSFunction {
57
57
fatalError ( " unavailable " )
58
58
}
59
59
@@ -62,7 +62,7 @@ public class JSFunctionRef: JSObjectRef {
62
62
}
63
63
}
64
64
65
- public class JSClosure : JSFunctionRef {
65
+ public class JSClosure : JSFunction {
66
66
static var sharedFunctions : [ JavaScriptHostFuncRef : ( [ JSValue ] ) -> JSValue ] = [ : ]
67
67
68
68
private var hostFuncRef : JavaScriptHostFuncRef = 0
@@ -128,6 +128,6 @@ public func _call_host_function(
128
128
$0. jsValue ( )
129
129
}
130
130
let result = hostFunc ( arguments)
131
- let callbackFuncRef = JSFunctionRef ( id: callbackFuncRef)
131
+ let callbackFuncRef = JSFunction ( id: callbackFuncRef)
132
132
_ = callbackFuncRef ( result)
133
133
}
0 commit comments