Support `{}` as a default value for a union containing a record
Categories
(Core :: DOM: Bindings (WebIDL), enhancement)
Tracking
()
People
(Reporter: jesup, Unassigned)
References
Details
The WebIDL spec allows = {} as a default for a dictionary, a record, or a union that has a dictionary or record member type. Our parser (dom/bindings/parser/WebIDL.py, IDLDefaultDictionaryValue.coerceToType) only coerces {} to a dictionary type, so it fails for HeadersInit (a union of sequence<sequence<ByteString>> and record<ByteString, ByteString>):
WebIDLError: Cannot coerce default dictionary value to type ByteStringSequenceSequenceOrByteStringByteStringRecord.
The WebTransport spec declares HeadersInit headers = {}; in WebTransportOptions. Bug 2081470 ships HeadersInit headers; instead, with a comment pointing here. The behavior is the same since the headers handling is a no-op for an empty record, but the generated binding differs (Optional<> vs. a value).
Fix: teach coerceToType to handle record types (and unions with a record member), add codegen for an empty-record default, and add a parser test under dom/bindings/parser/test. Once landed, switch WebTransportOptions.headers to = {} and drop the WasPassed() check in WebTransport::Constructor.
Description
•