Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions 8 IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,11 @@ try test("TypedArray_Mutation") {
}
try expectEqual(toString(array.jsValue().object!), jsStringify(Array(0..<100)))
}

try test("Error") {
let message = "test error"
let error = JSError(message: message)
try expectEqual(error.name, "Error")
try expectEqual(error.message, message)
try expectEqual(error.description, "Error: test error")
}
20 changes: 20 additions & 0 deletions 20 Sources/JavaScriptKit/BasicObjects/JSError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
public final class JSError {
private let ref: JSObject
private static let constructor = JSObject.global.Error.function!

public init(message: String) {
ref = Self.constructor.new([message])
}

public var message: String {
ref.message.string!
}

public var name: String {
ref.name.string!
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although it’s not standard, all engines that I know of implement error.stack to provide a stack trace as a string. It might be useful to access it.


extension JSError: CustomStringConvertible {
public var description: String { ref.description }
}
3 changes: 3 additions & 0 deletions 3 Sources/JavaScriptKit/FundamentalObjects/JSObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ public class JSObject: Equatable {
}
}

extension JSObject: CustomStringConvertible {
public var description: String { self.toString!().string! }
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.