Skip to content

Commit 917ab57

Browse files
Concurrency: Annotate jsObject property of JSError as nonisolated(unsafe)
Even though `JSObject` is not a `Sendable` type, `JSError` must be `Sendable` because of `Error` conformance. For this reason, we need to annotate the `jsObject` property as `nonisolated(unsafe)` to suppress the compiler error. Accessing this property from a different isolation domain scheduled on a different thread will result in a runtime assertion failure, but better than corrupting memory.
1 parent 28f3471 commit 917ab57

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Sources/JavaScriptKit/BasicObjects/JSError.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ public final class JSError: Error, JSBridgedClass {
88
private static let _constructor = LazyThreadLocal(initialize: { JSObject.global.Error.function })
99

1010
/// The underlying JavaScript `Error` object.
11-
public let jsObject: JSObject
11+
///
12+
/// NOTE: This property must be accessed from the thread that
13+
/// the thrown `Error` object was created on. Otherwise,
14+
/// it will result in a runtime assertion failure.
15+
public nonisolated(unsafe) let jsObject: JSObject
1216

1317
/// Creates a new instance of the JavaScript `Error` class with a given message.
1418
public init(message: String) {

0 commit comments

Comments
 (0)