Skip to content

Commit 235a4fe

Browse files
committed
Updated JSPromise
1 parent b1a06cb commit 235a4fe

File tree

2 files changed

+3
-23
lines changed

2 files changed

+3
-23
lines changed

Sources/JavaScriptKit/JS Types/JSError.swift

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,3 @@ internal extension JSError {
4343
// MARK: - CustomStringConvertible
4444

4545
extension JSError: CustomStringConvertible { }
46-
47-
// MARK: - Extensions
48-
49-
public extension JSValue {
50-
51-
/// Cast error to JavaScript value.
52-
init(error: Error) {
53-
if let value = error as? JSValueConvertible {
54-
// convert to JavaScript value if supported.
55-
self = value.jsValue()
56-
} else if let stringConvertible = error as? CustomStringConvertible {
57-
// use decription for error
58-
self = stringConvertible.description.jsValue()
59-
} else {
60-
// default to printing description
61-
self = String(reflecting: error).jsValue()
62-
}
63-
}
64-
}
65-

Sources/JavaScriptKit/JS Types/JSPromise.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ public final class JSPromise<Success>: JSType where Success: JSValueConvertible,
2828

2929
- parameter executor: A function to be executed by the Promise. The executor is custom code that ties an outcome to a promise. You, the programmer, write the executor.
3030
*/
31-
public init(executor block: @escaping ((Success) -> (), (Error) -> ()) -> ()) {
31+
public init(executor block: @escaping ((Success) -> (), (JSError) -> ()) -> ()) {
3232
let executor = JSFunctionRef.from { (arguments) in
3333
let resolutionFunc = arguments[0].function
3434
let rejectionFunc = arguments[1].function
35-
block({ resolutionFunc?($0.jsValue()) }, { rejectionFunc?(JSValue(error: $0)) })
35+
block({ resolutionFunc?($0.jsValue()) }, { rejectionFunc?($0.jsValue()) })
3636
return .null
3737
}
3838
self.jsObject = JSPromiseClassObject.new(executor)
@@ -43,7 +43,7 @@ public final class JSPromise<Success>: JSType where Success: JSValueConvertible,
4343

4444
- parameter executor: A function to be executed by the Promise. The executor is custom code that ties an outcome to a promise. You, the programmer, write the executor.
4545
*/
46-
public convenience init(executor block: @escaping ((Result<Success, Swift.Error>) -> ()) -> ()) {
46+
public convenience init(executor block: @escaping ((Result<Success, JSError>) -> ()) -> ()) {
4747
self.init { (resolution, rejection) in
4848
block({
4949
switch $0 {

0 commit comments

Comments
 (0)