webidl icon indicating copy to clipboard operation
webidl copied to clipboard

Should 'undefined' be disallowed as an attribute type?

Open marcoscaceres opened this issue 2 years ago • 2 comments

Over on WebGPU, there is the following IDL fragment specified:

interface mixin GPUObjectBase {
    attribute (USVString or undefined) label;
};

Leaving aside the issues with this label attribute itself, I'm wondering if we should outright ban undefined as an attribute type?

I personally can't think of any strong reason for an attribute to be declared undefined (unless it was settable to any). But I might be missing something obvious. It would be extremely confusing if an attribute was present and yet undefined (instead of null or "", in the case above for instance).

For the case above, Gecko, for instance, willfully violates the spec by null'ing the label attribute: https://searchfox.org/mozilla-central/source/dom/webidl/WebGPU.webidl#51

A quick grep of WPT's IDLs and also Gecko's IDLs, I can't find any place in the Platform the where there is a attribute undefined specified or a union that is includes undefined for an attribute type.

Thoughts?

marcoscaceres avatar Mar 02 '22 02:03 marcoscaceres

I think @domenic wanted (… or undefined) as type of an attribute. See https://github.com/whatwg/webidl/pull/906#issuecomment-670724983. Though in this particular case, I feel it would better adhere to convention if it instead said USVString?.

TimothyGu avatar Mar 02 '22 06:03 TimothyGu

For the case above, Gecko, for instance, willfully violates the spec by null'ing the label attribute: https://searchfox.org/mozilla-central/source/dom/webidl/WebGPU.webidl#51

The patch for switching Gecko's WebIDL parser/codegen to undefined hasn't landed yet, so taking that example as any sign one way or the other isn't right.

petervanderbeken avatar May 04 '22 15:05 petervanderbeken

ok, closing this for now.

marcoscaceres avatar Sep 21 '22 00:09 marcoscaceres