whatwg / webidl

Web IDL Standard
https://webidl.spec.whatwg.org/
Other
410 stars 164 forks source link

Dictionary with required members as optional argument #1378

Open Ms2ger opened 11 months ago

Ms2ger commented 11 months ago

What is the issue with the Web IDL Standard?

CSP has this IDL code (:

[Exposed=(Window,Worker)]
interface SecurityPolicyViolationEvent : Event {
    constructor (DOMString type, optional SecurityPolicyViolationEventInit eventInitDict = {});
    // ...
};

dictionary SecurityPolicyViolationEventInit : EventInit {
    required USVString      documentURI;
    // ...
};

which IDL doesn't, as far as I can tell, expect or handle well.

If I'm not mistaken, when handling new SecurityPolicyViolationEvent("type"), the overload resolution algorithm just passes "that default value" in step 15.4.1, and nothing really defines what that value is ("which represents a default-initialized (as if from ES null or an object with no properties) dictionary value").

The behavior of the constructor is specified in DOM, which doesn't pay attention to the requiredness of dictionary members.

It appears to me that as currently specified, the required tokens are essentially ignored when the argument is omitted. This seems unexpected at least.

evilpie commented 11 months ago

It seems like a more explicit definition would be good, but "an object with no properties" seems like the obvious default initialization for a dictionary parameter?

domenic commented 11 months ago

This is a dupe of https://github.com/whatwg/dom/issues/600.

domenic commented 11 months ago

Hmm, I guess this is about the web-developer-facing interfaces, whereas https://github.com/whatwg/dom/issues/600 is about the spec interface.

But for the web developer-facing interface, this seems like a bug in the CSP spec, not the Web IDL spec.

Ms2ger commented 11 months ago

I think there's an IDL bug here that's wider than just events if optional Dict foo = {} is legal IDL when Dict has required members