File tree Expand file tree Collapse file tree 2 files changed +7
-8
lines changed
Sources/JavaScriptKit/JS Types Expand file tree Collapse file tree 2 files changed +7
-8
lines changed Original file line number Diff line number Diff line change @@ -30,8 +30,6 @@ public final class JSBluetooth: JSType {
30
30
//services: [] = [],
31
31
acceptAllDevices: Bool = true ) -> JSPromise < JSBluetoothDevice > {
32
32
33
- JSObjectRef . global. console. object? . log. function ? ( " \( #file) \( String ( reflecting: type ( of: self ) ) ) \( #function) \( #line) " )
34
-
35
33
enum Option : String {
36
34
case filters
37
35
case optionalServices
@@ -47,14 +45,12 @@ public final class JSBluetooth: JSType {
47
45
// FIXME: Improve, support all options
48
46
let options = JSObject ( )
49
47
options [ Option . acceptAllDevices. rawValue] = JSBoolean ( acceptAllDevices) . jsValue ( )
50
- options [ Option . optionalServices. rawValue] = [ " device_information " ] . jsValue ( )
51
48
52
- let result = function ( options. jsValue ( ) )
53
- JSObjectRef . global. console. object? . log. function ? ( " \( #file) \( String ( reflecting: type ( of: self ) ) ) \( #function) \( #line) " )
49
+ let result = function. apply ( this: jsObject, arguments: options)
54
50
55
51
guard let promise = result. object. flatMap ( { JSPromise < JSBluetoothDevice > ( $0) } )
56
52
else { fatalError ( " Invalid object \( result) " ) }
57
- JSObjectRef . global . console . object ? . log . function ? ( " \( #file ) \( String ( reflecting : type ( of : self ) ) ) \( #function ) \( #line ) " )
53
+
58
54
return promise
59
55
}
60
56
}
Original file line number Diff line number Diff line change @@ -91,11 +91,14 @@ public final class JSPromise<Success: JSType>: JSType {
91
91
*/
92
92
public func then/*<T: JSType>*/( onFulfilled: @escaping ( Success ) -> ( ) /* onRejected: ((Error) -> ())? */) /* -> JSPromise<T> */ {
93
93
94
+ guard let function = jsObject. then. function
95
+ else { fatalError ( " Invalid function \( jsObject. requestDevice) " ) }
96
+
94
97
let success = JSFunctionRef . from { ( arguments) in
95
98
if let value = arguments. first. flatMap ( { Success . construct ( from: $0) } ) {
96
99
onFulfilled ( value)
97
100
}
98
- return . null
101
+ return . undefined
99
102
}
100
103
/*
101
104
let errorFunction = onRejected.flatMap { (onRejected) in
@@ -104,7 +107,7 @@ public final class JSPromise<Success: JSType>: JSType {
104
107
return .undefined
105
108
}
106
109
}*/
107
- let result = jsObject . then . function ? ( success , JSValue . null ) //, errorFunction )
110
+ let result = function. apply ( this : jsObject , argumentList : [ success . jsValue ( ) ] )
108
111
}
109
112
110
113
public func `catch`( _ completion: ( Error ) -> ( ) ) {
You can’t perform that action at this time.
0 commit comments