Skip to content

Commit 2cd0a2c

Browse files
Merge pull request #293 from swiftwasm/yt/fix-compiler-crash-6.0.3
Workaround Swift 6.0 compiler crash
2 parents 20ecd3a + 97fc40f commit 2cd0a2c

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Sources/JavaScriptKit/FundamentalObjects/JSClosure.swift

+9-3
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,18 @@ public class JSOneshotClosure: JSObject, JSClosureProtocol {
6464
public class JSClosure: JSFunction, JSClosureProtocol {
6565

6666
class SharedJSClosure {
67-
private var storage: [JavaScriptHostFuncRef: (object: JSObject, body: (sending [JSValue]) -> JSValue)] = [:]
67+
// Note: 6.0 compilers built with assertions enabled crash when calling
68+
// `removeValue(forKey:)` on a dictionary with value type containing
69+
// `sending`. Wrap the value type with a struct to avoid the crash.
70+
struct Entry {
71+
let item: (object: JSObject, body: (sending [JSValue]) -> JSValue)
72+
}
73+
private var storage: [JavaScriptHostFuncRef: Entry] = [:]
6874
init() {}
6975

7076
subscript(_ key: JavaScriptHostFuncRef) -> (object: JSObject, body: (sending [JSValue]) -> JSValue)? {
71-
get { storage[key] }
72-
set { storage[key] = newValue }
77+
get { storage[key]?.item }
78+
set { storage[key] = newValue.map { Entry(item: $0) } }
7379
}
7480
}
7581

0 commit comments

Comments
 (0)