Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions Sources/JavaScriptKit/FundamentalObjects/JSClosure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,18 @@ public class JSOneshotClosure: JSObject, JSClosureProtocol {
public class JSClosure: JSFunction, JSClosureProtocol {

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

subscript(_ key: JavaScriptHostFuncRef) -> (object: JSObject, body: (sending [JSValue]) -> JSValue)? {
get { storage[key] }
set { storage[key] = newValue }
get { storage[key]?.item }
set { storage[key] = newValue.map { Entry(item: $0) } }
}
}

Expand Down