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

Latest commit

 

History

History
History
45 lines (37 loc) · 1.45 KB

File metadata and controls

45 lines (37 loc) · 1.45 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/** A wrapper around [the JavaScript Error
class](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) that
exposes its properties in a type-safe way.
*/
public final class JSError: Error, JSBridgedClass {
/// The constructor function used to create new JavaScript `Error` objects.
public static let constructor = JSObject.global.Error.function
/// The underlying JavaScript `Error` object.
public let jsObject: JSObject
/// Creates a new instance of the JavaScript `Error` class with a given message.
public init(message: String) {
jsObject = Self.constructor!.new([message])
}
public init(unsafelyWrapping jsObject: JSObject) {
self.jsObject = jsObject
}
/// The error message of the underlying `Error` object.
public var message: String {
jsObject.message.string!
}
/// The name (usually corresponds to the name of the underlying class) of a given error.
public var name: String {
jsObject.name.string!
}
/// The JavaScript call stack that led to the creation of this error object.
public var stack: String? {
jsObject.stack.string
}
/// Creates a new `JSValue` from this `JSError` instance.
public var jsValue: JSValue {
.object(jsObject)
}
}
extension JSError: CustomStringConvertible {
/// The textual representation of this error.
public var description: String { jsObject.description }
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.