Skip to content

Commit 4ee27e6

Browse files
Suppress concurrency warning about JSObject.global
1 parent 20f97ed commit 4ee27e6

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Sources/JavaScriptKit/FundamentalObjects/JSObject.swift

+10-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,16 @@ public class JSObject: Equatable {
137137

138138
/// A `JSObject` of the global scope object.
139139
/// This allows access to the global properties and global names by accessing the `JSObject` returned.
140-
public static let global = JSObject(id: _JS_Predef_Value_Global)
140+
public static var global: JSObject { return _global }
141+
142+
// `JSObject` storage itself is immutable, and use of `JSObject.global` from other
143+
// threads maintains the same semantics as `globalThis` in JavaScript.
144+
#if compiler(>=5.10)
145+
nonisolated(unsafe)
146+
static let _global = JSObject(id: _JS_Predef_Value_Global)
147+
#else
148+
static let _global = JSObject(id: _JS_Predef_Value_Global)
149+
#endif
141150

142151
deinit { swjs_release(id) }
143152

0 commit comments

Comments
 (0)