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

Exclude undefined from the PrimitiveType in grammar #1140

Merged
merged 2 commits into from
May 5, 2022

Conversation

EdgarChen
Copy link
Member

@EdgarChen EdgarChen commented May 4, 2022

Closes #1139.


Preview | Diff

@EdgarChen EdgarChen requested a review from domenic May 4, 2022 18:53
@domenic
Copy link
Member

domenic commented May 4, 2022

This also removes undefined from ConstType, which I think is incorrect.

@EdgarChen
Copy link
Member Author

but

The type of a constant (matching ConstType) must not be any type other than a primitive type. If an identifier is used, it must reference a typedef whose type is a primitive type.

and undefined is not a primitive type in

The primitive types are bigint, boolean and the numeric types.

So could a constant type be undefined?

@domenic
Copy link
Member

domenic commented May 4, 2022

It seems the intention was to allow that, per

undefined constant values in IDL are represented with the undefined token.

Probably we should just make undefined a primitive type? It's certainly a primitive type in JavaScript, and I'm not sure why we'd depart.

@petervanderbeken
Copy link

It seems the intention was to allow that, per

undefined constant values in IDL are represented with the undefined token.

And yet https://webidl.spec.whatwg.org/#prod-ConstValue has:

ConstValue ::
     BooleanLiteral
     FloatLiteral
     integer

@petervanderbeken
Copy link

Also, are there actual use cases for constants with undefined as the value?

It's certainly a primitive type in JavaScript, and I'm not sure why we'd depart.

So are String and Symbol, but unless there's a clear use case I don't think we would add those either?

@domenic
Copy link
Member

domenic commented May 4, 2022

Ah yeah. Actually allowing const undefined = undefined seems pretty dumb.

What's not dumb is allowing undefined as a DefaultValue.

@petervanderbeken
Copy link

Ah, yes, good point. So let's add it to DefaultValue (which actually has string too ;-)).

@petervanderbeken
Copy link

Note that DefaultValue is also used for dictionary members, which can't be undefined, so we might need some prose excluding it. Although undefined is not explicitly in:

When a boolean literal token (true or false), the null token, an integer token, a decimal token, one of the three special floating point literal values (Infinity, -Infinity or NaN), a string token, the two token sequence [], or the two token sequence {} is used as the default value, it is interpreted in the same way as for an operation’s optional argument default value.

so maybe that's good enough?

@EdgarChen
Copy link
Member Author

I add undefined into DefaultValue (thanks for the patch from @petervanderbeken).

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

Successfully merging this pull request may close these issues.

Grammar and prose are inconsistent about whether undefined is a primitive type
3 participants