Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Definition of {} is slightly ambiguous #1344

Open
jyasskin opened this issue Jul 17, 2023 · 2 comments
Open

Definition of {} is slightly ambiguous #1344

jyasskin opened this issue Jul 17, 2023 · 2 comments

Comments

@jyasskin
Copy link
Member

We have "If the argument at index i is declared with a default value, then append to values that default value." in https://webidl.spec.whatwg.org/#dfn-overload-resolution-algorithm. When the default value is {}, the only meaning I can find is in https://webidl.spec.whatwg.org/#dfn-optional-argument-default-value

Optional argument default values can also be specified using the two token value {}, which represents a default-initialized (as if from ES null or an object with no properties) dictionary value.

Conversion from ES null is fully defined by https://webidl.spec.whatwg.org/#es-to-dictionary, but an "object with no properties"--if that means what you get by typing {} in ECMAScript--can be modified by changing Object.prototype. We should ensure this is specified so that Object.prototype doesn't affect it. A simple way to do that might be to remove "or an object with no properties" from the parenthetical, but it might be better to actually spell it out.

@bathos
Copy link
Contributor

bathos commented Jul 17, 2023

I think “as if from ES null” covers it unambiguously and that the “or an object” part would be more misleading than helpful even if “corrected.” There’s a lot more than just Object.prototype which could impact conversion behavior. Unlike conversion from ES object, conversion from ES null has no observable steps. As there are no ES-observable steps when creating a default dictionary, it should probably not mention object conversion at all.

@domenic
Copy link
Member

domenic commented Jul 18, 2023

The intent of that section, if I recall, was that the {} is a purely syntactic decoration that makes it clearer for readers. (See #602.) The sentence you quote was not meant to be a definition, but instead a statement about what that syntactic decoration "represents". In this context, "represents" means "how you should think about it when reading", not anything normative.

Note that "object with no properties" is mean to indicate an object with no properties, not an object which inherits its properties from Object.prototype.

Some more background can be found by digging through #750 and the linked threads.

That said, it seems like there is some gap in the normative requirements here, which fails to translate the default values {} and [] into actual ECMAScript values, of the type that you could put into the overload resolution algorithm's outputs. (Arguably, it's also not very rigorous to take the Web IDL token false and translate that into the ECMAScript boolean value false, either.) We should probably have an explicit procedure that does that conversion between value spaces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants
@jyasskin @domenic @bathos and others