forked from JavaScriptKit/JavaScriptCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSError.swift
More file actions
27 lines (24 loc) · 731 Bytes
/
Copy pathJSError.swift
File metadata and controls
27 lines (24 loc) · 731 Bytes
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
#if os(Linux)
import CJavaScriptCore
#else
import JavaScriptCore
#endif
public struct JSError: Error, CustomStringConvertible {
public var description: String
init(context: JSContextRef, pointer: JSValueRef) {
let value = JSValue(context: context, pointer: pointer)
do {
guard value.isObject else {
description = "not an object"
return
}
guard let message = value["message"] else {
self.description = "failed to access error.message"
return
}
self.description = try message.toString()
} catch {
self.description = "failed to convert JSError"
}
}
}