-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Restore DOMStringList so ancestorOrigins can use it #2192
Conversation
This requires several follow-up changes: * To DOM, so it’s no longer marked obsolete. * To Indexed DB, to start making use of this definition and remove its own version. * To Service Workers, which can no longer use “ancestor origins array”. Fixes #2179.
I'll take care of Indexed DB (of course) assuming the PR above lands before I vanish for the holidays. |
@@ -7643,6 +7643,48 @@ https://software.hixie.ch/utilities/js/live-dom-viewer/?%3C%21DOCTYPE%20html%3E. | |||
</div> | |||
|
|||
|
|||
<h4>The <code>DOMStringList</code> interface</h4> | |||
|
|||
<p>The <code>DOMStringList</code> interface is a non-fashionable-retro way of representing a list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think this should be "non-fashionable retro" or "non-fashionable, retro" :)
<p>Each <code>DOMStringList</code> object has an associated <span>list</span>.</p> | ||
|
||
<p>The <span>supported property indices</span> for a <code>DOMStringList</code> object are the | ||
numbers zero to the number of items in its associated list minus one. If its associated list <span |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the size concept from infra
<p>The <dfn data-x="dom-DOMStringList-item"><code>item(<var>index</var>)</code></dfn> method, when | ||
invoked, must return the <var>index</var>th item in this <code>DOMStringList</code> object's | ||
associated list, or null if there are less than <var>index</var> plus one items in this | ||
<code>DOMStringList</code> object's associated list.</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use size I think
produce:</p> | ||
data-x="concept-location-ancestor-origins-list">ancestor origins list</span> must be set to a | ||
<code>DOMStringList</code> object whose associated list is the list of strings that the following | ||
steps would produce:</p> | ||
|
||
<ol> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe spruce this up to xref infra while you're here? I think "[list] of strings" x2 and [Append] would suffice. Maybe remove "as a new value".
readonly attribute unsigned long <span data-x="dom-DOMStringList-length">length</span>; | ||
getter DOMString? <span data-x="dom-DOMStringList-item">item</span>(unsigned long index); | ||
boolean <span data-x="dom-DOMStringList-contains">contains</span>(DOMString string); | ||
};</pre> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we still need a domintro for this (like IndexedDB has, and like HTMLCollection has). Even if new APIs should not use this, developers should still be told how it works, since it's the only way to get ancestor origins.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes a lot of sense.
<dt><var>strings</var> . <code subdfn data-x="dom-DOMStringList-length">length</code></dt> | ||
<dd><p>Returns the number of strings in <var>strings</var>.</p></dd> | ||
|
||
<dt><var>strings</var> . <code subdfn data-x="dom-DOMStringList-item">item</code>(<var>index</var>)</dt> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we document strings[index]
as well? (as I had in Indexed DB, and we do for DOMTokenList)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I didn't is that getters are even more old-fashioned than DOMStringList and you don't need them to use the API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I think the getter is more modern than the item() function. Ideally we'd like people to stop using item() so that we could get rid of this API---at least, that was the original thinking. Anyway, consistency with DOMTokenList seems important.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can remove it from DOMTokenList too. I don't think we should market these "legacy" (hopefully soon marked as such through IDL) features anywhere. E.g., consider strings["item"]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point is, I think item() is more legacy than indexing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @domenic - I think we want to steer developers towards the Array-like API to interact with this wart so we could maybe drop it, but even if we can't for compat we're not making developers learn a new way of interacting with an Array-like thing. (Making it iterable and adding includes()
as an alias for contains()
would also help.)
I think IDL getters are just plain bad, but I'll fix this. |
I guess it's slightly less bad here because it's not names, just numbers. |
This rewrites ancestorOrigins using DOMStringList instead of FrozenArray to USVString reflecting the changes in HTML. Related pull request: whatwg/html#2192. Related issue: #1051.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, needs tests
Isn't this just restoring the status quo? I guess I can look into tests at some point... |
Probably not a priority for me if Firefox doesn't actually plan on shipping this. |
I think this is OK to merge without tests as it's just moving from one spec to another. But tests would be good; filed web-platform-tests/wpt#4522 |
Part of the issue here I believe is that WebKit tried to follow the new web platform tests and ran into web compat problems, so it seems important to address that. |
<pre class="idl">[Exposed=(Window,Worker)] | ||
interface <dfn>DOMStringList</dfn> { | ||
readonly attribute unsigned long <span data-x="dom-DOMStringList-length">length</span>; | ||
getter DOMString? <span data-x="dom-DOMStringList-item">item</span>(unsigned long index); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IndexedDB has separate getter
and item()
to handle the difference in behavior when an index out of range is specified (getter returns undefined, item() returns null).
Maybe that's automagically handled by WebIDL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's handled by saying what the supported property indices are.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But WebIDL says:
If an indexed property getter was specified using an operation with an identifier, then the value returned when indexing the object with a given supported property index is the value that would be returned by invoking the operation, passing the index as its only argument.
But that's not true given the behavior in Chrome, where dsl[999]
returns undefined
while dsl.item(999)
returns null
.
(Unless, as usual, I'm missing something.)
Ignoring that issue, the determine the value of an indexed property in this patch is irrelevant; that's only needed if the operation did not have an identifier:
If the operation used to declare the indexed property getter did not have an identifier, then the interface definition must be accompanied by a description of how to determine the value of an indexed property for a given index.
(BTW, thanks to everyone for being nitpicky along with me! I can't wait to tear this out of IndexedDB)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
999 is not a supported property index
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What @domenic said. I know it is confusing. ^_^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I'm parsing it correctly now. Yes, null
vs. undefined
falls out; if not a supported property index, item() produces null (per prose) and indexing with [] does a normal property lookup and produces undefined. Thanks for bearing with me.
I still believe the prose for determine the value of an indexed property is unnecessary as that clause should not apply.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think that paragraph can be dropped. https://dom.spec.whatwg.org/#interface-nodelist doesn't have "determine the value of an indexed property".
Can whoever merges this hit the merge button for web-platform-tests/wpt#4534 too? (could do it now but might as well coordinate) |
The getter has an identifier ("item"), so that is invoked per https://heycam.github.io/webidl/#idl-indexed-properties
See whatwg/html#2192. Fixes #4522.
Per whatwg/html#2192 it's now in HTML.
* Use DOMStringList for ancestorOrigins This reflects the change in HTML that restored ancestor origins list. This change uses the ancestor origins list to create a frozen array for windowClient.ancestorOrigins. Related pull request: whatwg/html#2192. Fixes #1051.
This requires several follow-up changes:
own version.
Fixes #2179.