Skip to content

Commit 144bf2f

Browse files
committed
Add support for deleters (as a removeValue(forKey:) method)
1 parent 2b65edc commit 144bf2f

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

Sources/DOM/Generated.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3826,7 +3826,9 @@ public class DOMStringMap: JSBridgedClass {
38263826
}
38273827
}
38283828

3829-
// XXX: unsupported deleter for keys of type String
3829+
@inlinable public func removeValue(forKey key: String) {
3830+
_ = JSObject.global.Reflect.deleteProperty(jsObject, _toJSValue(key))
3831+
}
38303832
}
38313833

38323834
public class DOMTokenList: JSBridgedClass, Sequence {
@@ -14771,7 +14773,9 @@ public class Storage: JSBridgedClass {
1477114773
}
1477214774
}
1477314775

14774-
// XXX: unsupported deleter for keys of type String
14776+
@inlinable public func removeValue(forKey key: String) {
14777+
_ = JSObject.global.Reflect.deleteProperty(jsObject, _toJSValue(key))
14778+
}
1477514779

1477614780
@inlinable public func clear() {
1477714781
let this = jsObject

Sources/WebIDLToSwift/WebIDL+SwiftRepresentation.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,13 @@ extension IDLOperation: SwiftRepresentable, Initializable {
456456
}
457457
"""
458458
case "deleter":
459-
return "// XXX: unsupported deleter for keys of type \(arguments[0].idlType)"
459+
// Use Reflect.deleteProperty since `delete` would require wiring up a hook in JSKit,
460+
// and this is used rarely enough that perf should be irrelevant.
461+
return """
462+
@inlinable public func removeValue(forKey key: \(arguments[0].idlType)) {
463+
_ = JSObject.global.Reflect.deleteProperty(jsObject, _toJSValue(key))
464+
}
465+
"""
460466
default:
461467
fatalError("Unsupported special operation \(special)")
462468
}

0 commit comments

Comments
 (0)