Skip to content

Commit 128a862

Browse files
committed
Working on JSBluetooth
1 parent c88b849 commit 128a862

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

Sources/JavaScriptKit/JS Types/JSBluetooth.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ public final class JSBluetooth: JSType {
3030
//services: [] = [],
3131
acceptAllDevices: Bool = true) -> JSPromise<JSBluetoothDevice> {
3232

33-
JSObjectRef.global.console.object?.log.function?("\(#file) \(String(reflecting: type(of: self))) \(#function) \(#line)")
34-
3533
enum Option: String {
3634
case filters
3735
case optionalServices
@@ -47,14 +45,12 @@ public final class JSBluetooth: JSType {
4745
// FIXME: Improve, support all options
4846
let options = JSObject()
4947
options[Option.acceptAllDevices.rawValue] = JSBoolean(acceptAllDevices).jsValue()
50-
options[Option.optionalServices.rawValue] = ["device_information"].jsValue()
5148

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)
5450

5551
guard let promise = result.object.flatMap({ JSPromise<JSBluetoothDevice>($0) })
5652
else { fatalError("Invalid object \(result)") }
57-
JSObjectRef.global.console.object?.log.function?("\(#file) \(String(reflecting: type(of: self))) \(#function) \(#line)")
53+
5854
return promise
5955
}
6056
}

Sources/JavaScriptKit/JS Types/JSPromise.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,14 @@ public final class JSPromise<Success: JSType>: JSType {
9191
*/
9292
public func then/*<T: JSType>*/(onFulfilled: @escaping (Success) -> () /* onRejected: ((Error) -> ())? */) /* -> JSPromise<T> */ {
9393

94+
guard let function = jsObject.then.function
95+
else { fatalError("Invalid function \(jsObject.requestDevice)") }
96+
9497
let success = JSFunctionRef.from { (arguments) in
9598
if let value = arguments.first.flatMap({ Success.construct(from: $0) }) {
9699
onFulfilled(value)
97100
}
98-
return .null
101+
return .undefined
99102
}
100103
/*
101104
let errorFunction = onRejected.flatMap { (onRejected) in
@@ -104,7 +107,7 @@ public final class JSPromise<Success: JSType>: JSType {
104107
return .undefined
105108
}
106109
}*/
107-
let result = jsObject.then.function?(success, JSValue.null) //, errorFunction)
110+
let result = function.apply(this: jsObject, argumentList: [success.jsValue()])
108111
}
109112

110113
public func `catch`(_ completion: (Error) -> ()) {

0 commit comments

Comments
 (0)