@@ -31,11 +31,10 @@ extension JSRemote where T == JSObject {
3131 #endif
3232 }
3333
34- #if compiler(>=6.4)
3534 public func withJSObject< R: Sendable , E: Error > (
3635 _ body: @Sendable @escaping ( JSObject) throws( E ) -> R
3736 ) async throws ( E) -> sending R {
38- #if _runtime(_multithreaded)
37+ #if compiler(>=6.1) && _runtime(_multithreaded)
3938 if storage. sourceTid == swjs_get_worker_thread_id_cached ( ) {
4039 return try body ( storage. sourceObject)
4140 }
@@ -55,37 +54,12 @@ extension JSRemote where T == JSObject {
5554 return try body ( storage. sourceObject)
5655 #endif
5756 }
58- #else
59- public func withJSObject< R: Sendable > (
60- _ body: @Sendable @escaping ( JSObject) throws -> R
61- ) async throws -> R {
62- #if compiler(>=6.1) && _runtime(_multithreaded)
63- if storage. sourceTid == swjs_get_worker_thread_id_cached ( ) {
64- return try body ( storage. sourceObject)
65- }
66- return try await withCheckedThrowingContinuation { continuation in
67- let context = _JSRemoteContext (
68- sourceObject: storage. sourceObject,
69- body: body,
70- continuation: continuation
71- )
72- swjs_request_remote_jsobject_body (
73- storage. sourceTid,
74- Unmanaged . passRetained ( context) . toOpaque ( )
75- )
76- }
77- #else
78- return try body ( storage. sourceObject)
79- #endif
80- }
81- #endif
8257}
8358
8459@available ( macOS 10 . 15 , iOS 13 . 0 , watchOS 6 . 0 , tvOS 13 . 0 , * )
8560private final class _JSRemoteContext : @unchecked Sendable {
8661 let invokeBody : ( ) -> Bool
8762
88- #if compiler(>=6.4)
8963 init < R: Sendable , E: Error > (
9064 sourceObject: JSObject ,
9165 body: @escaping @Sendable ( JSObject) throws( E ) -> R ,
@@ -94,30 +68,12 @@ private final class _JSRemoteContext: @unchecked Sendable {
9468 self . invokeBody = {
9569 do {
9670 continuation. resume ( returning: . success( try body ( sourceObject) ) )
97- return false
98- } catch {
99- continuation. resume ( returning: . failure( error as! E ) )
100- return true
71+ } catch let error {
72+ continuation. resume ( returning: . failure( error) )
10173 }
74+ return false
10275 }
10376 }
104- #else
105- init < R: Sendable > (
106- sourceObject: JSObject ,
107- body: @escaping @Sendable ( JSObject) throws -> R ,
108- continuation: CheckedContinuation < R , Error >
109- ) {
110- self . invokeBody = {
111- do {
112- continuation. resume ( returning: try body ( sourceObject) )
113- return false
114- } catch {
115- continuation. resume ( throwing: error)
116- return true
117- }
118- }
119- }
120- #endif
12177}
12278
12379#if compiler(>=6.1)
0 commit comments