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

Do indexed getters ever return null? #532

Open
annevk opened this issue Mar 13, 2018 · 4 comments
Open

Do indexed getters ever return null? #532

annevk opened this issue Mar 13, 2018 · 4 comments

Comments

@annevk
Copy link
Member

annevk commented Mar 13, 2018

That'd be interesting to know for whatwg/dom#284. At least whenever I use indexed getters for some legacy object I'm pretty sure that the properties always correspond to an object and not null. It's only the item() method that can return null.

(If it turns out that they cannot return null, we should allow the types of iterables and indexed getters to slightly differ. Or perhaps say that the type of the indexed getter is the same as the method declaration it might share, minus nullability.)

@bzbarsky
Copy link
Collaborator

Is this a question about practical usage in APIs right now?

@annevk
Copy link
Member Author

annevk commented Mar 13, 2018

Yeah, I basically want to know if we want/can make this an invariant or whether I should change the IDL in https://dom.spec.whatwg.org/#interface-nodelist to say Node? rather than Node even though it can never be null.

@bzbarsky
Copy link
Collaborator

OK. So looking at Firefox, the indexed getters we have that return nullable things are:

 ChromeNodeList.item
 CSSRuleList.item
 CSSValueList.item
 DOMRectList.item
 DOMStringList.item
 DOMTokenList.item
 FileList.item
 GridLines.item
 GridTracks.item
 HTMLAllCollection anonymous getter
 HTMLCollection.item
 HTMLFormControlsCollection.item
 HTMLOptionsCollection.item
 HTMLSelectElement.item
 MediaList.item
 MimeTypeArray.item
 NamedNodeMap.item
 NodeList.item
 PaintRequestList.item
 PluginArray.item
 Plugin.item
 RadioNodeList.item
 StyleSheetList.item
 TouchList.item
 TreeColumns.getColumnAt

(not all of these are defined in specs; I did check the two obvious non-spec ones in ChromeNodeList and TreeColumns and they don't return null).

Also, I have no idea why HTMLAllCollection's anonymous indexed getter is defined to maybe return null. It can't, obviously.

@bzbarsky
Copy link
Collaborator

I tried going through that list, and it does seem like for all of them we never return null from the getter.

So I guess the real question is whether we ever expect to support a list of "something-or-null"...

annevk added a commit to whatwg/html that referenced this issue Mar 13, 2018
domenic pushed a commit to whatwg/html that referenced this issue Mar 14, 2018
alice pushed a commit to alice/html that referenced this issue Jan 8, 2019
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

2 participants