The Wayback Machine - https://web.archive.org/web/20220411151018/https://github.com/whatwg/html/issues/5266
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

"determine the value of a named property" should not imply a new object each time #5266

Open
bzbarsky opened this issue Feb 10, 2020 · 6 comments
Labels
good first issue needs tests topic: forms

Comments

@bzbarsky
Copy link
Contributor

@bzbarsky bzbarsky commented Feb 10, 2020

Some people seem to read https://html.spec.whatwg.org/multipage/forms.html#dom-form-nameditem as implying that a new nodelist should be returned each time when there are multiple matching elements. That's not the intent, I assume, and it might be worth clarifying the spec to make it clear.

All browsers I tested (Firefox, Chrome, Safari) return the same nodelist on multiple accesses.

@domenic
Copy link
Member

@domenic domenic commented Feb 10, 2020

Is this another map-of-weak references situation? Or will they cache the nodelist indefinitely?

@bzbarsky
Copy link
Contributor Author

@bzbarsky bzbarsky commented Feb 10, 2020

Gecko caches indefinitely. I think Chrome does the same if I read https://cs.chromium.org/chromium/src/third_party/blink/renderer/core/dom/container_node.cc?l=1530-1535&rcl=9d179ecc8ad5e63a9dc77942810961a6a18705e9 and its callees correctly, but I could be wrong...

@annevk
Copy link
Member

@annevk annevk commented Feb 11, 2020

If the list changes such that it contains a single node, would you then no longer return the list? Would you return the same list again if it were to contain multiple nodes again? I guess this needs some tests.

If we continue returning the same list forever once we decide to return a list it'd be pretty straightforward to keep a map on the form element to make this explicit.

@bzbarsky
Copy link
Contributor Author

@bzbarsky bzbarsky commented Feb 11, 2020

If the list changes such that it contains a single node, would you then no longer return the list?

That's a good question. In Gecko, it looks like yes: when the list becomes length-1 we forget the list and just point to the one element; if the length then becomes longer than 1 we create a new list. I don't know what other browsers do.

@annevk annevk added good first issue needs tests labels Feb 11, 2020
@annevk
Copy link
Member

@annevk annevk commented Feb 11, 2020

Tentatively marking as a good first issue.

This is for someone with some background in JavaScript and interested in writing web-platform-tests to explore various scenarios around form's namedItem() method to see what kind of caching browsers implement for returned lists.

Once that step is complete we'd modify the existing algorithm in the HTML Standard to add that caching (and invalidation, if any), using the map primitive from https://infra.spec.whatwg.org/.

@Ayush2020012016
Copy link

@Ayush2020012016 Ayush2020012016 commented Jul 7, 2021

hello
I want to work in this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue needs tests topic: forms
5 participants
@domenic @bzbarsky @annevk @Ayush2020012016 and others