Skip to content

Commit cb1aaf2

Browse files
authoredOct 1, 2020
Make JSError conform to JSBridgedClass (#86)
The lack of this conformance makes it impossible to attach `catch` callbacks to `JSPromise` when `Failure: JSError`, as `catch` methods have `Failure: JSValueConstructible` constraints.
1 parent 6e84a70 commit cb1aaf2

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed
 

Diff for: ‎IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,12 @@ try test("Promise") {
487487

488488
try test("Error") {
489489
let message = "test error"
490+
let expectedDescription = "Error: test error"
490491
let error = JSError(message: message)
491492
try expectEqual(error.name, "Error")
492493
try expectEqual(error.message, message)
493-
try expectEqual(error.description, "Error: test error")
494+
try expectEqual(error.description, expectedDescription)
494495
try expectEqual(error.stack?.isEmpty, false)
496+
try expectEqual(JSError(from: .string("error"))?.description, nil)
497+
try expectEqual(JSError(from: .object(error.jsObject))?.description, expectedDescription)
495498
}

Diff for: ‎Sources/JavaScriptKit/BasicObjects/JSError.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
class](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) that
33
exposes its properties in a type-safe way.
44
*/
5-
public final class JSError: Error, JSValueConvertible {
5+
public final class JSError: Error, JSBridgedClass {
66
/// The constructor function used to create new JavaScript `Error` objects.
77
public static let constructor = JSObject.global.Error.function!
88

0 commit comments

Comments
 (0)
Please sign in to comment.