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

Restore DOMStringList so ancestorOrigins can use it #2192

Merged
merged 4 commits into from
Jan 13, 2017

Conversation

annevk
Copy link
Member

@annevk annevk commented Dec 17, 2016

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.

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.
@inexorabletash
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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>
Copy link
Member

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>
Copy link
Member

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>
Copy link
Member

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.

Copy link
Member Author

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>
Copy link
Member

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)

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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"].

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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.

Copy link
Member

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.)

@annevk
Copy link
Member Author

annevk commented Jan 10, 2017

I think IDL getters are just plain bad, but I'll fix this.

@annevk
Copy link
Member Author

annevk commented Jan 10, 2017

I guess it's slightly less bad here because it's not names, just numbers.

jungkees added a commit to w3c/ServiceWorker that referenced this pull request Jan 10, 2017
This rewrites ancestorOrigins using DOMStringList instead of FrozenArray
to USVString reflecting the changes in HTML.

Related pull request: whatwg/html#2192.
Related issue: #1051.
@domenic domenic added the needs tests Moving the issue forward requires someone to write tests label Jan 10, 2017
Copy link
Member

@domenic domenic left a 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

@annevk
Copy link
Member Author

annevk commented Jan 10, 2017

Isn't this just restoring the status quo? I guess I can look into tests at some point...

@annevk
Copy link
Member Author

annevk commented Jan 10, 2017

Probably not a priority for me if Firefox doesn't actually plan on shipping this.

@zcorpan
Copy link
Member

zcorpan commented Jan 10, 2017

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

@domenic
Copy link
Member

domenic commented Jan 11, 2017

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);
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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)

Copy link
Member

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

Copy link
Member

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. ^_^

Copy link
Member

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.

Copy link
Member

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".

@zcorpan zcorpan removed the needs tests Moving the issue forward requires someone to write tests label Jan 12, 2017
@inexorabletash
Copy link
Member

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
zcorpan pushed a commit to web-platform-tests/wpt that referenced this pull request Jan 13, 2017
@zcorpan zcorpan merged commit a830aef into master Jan 13, 2017
@zcorpan zcorpan deleted the annevk/DOMStringList branch January 13, 2017 00:55
annevk pushed a commit to whatwg/dom that referenced this pull request Jan 13, 2017
jungkees added a commit to w3c/ServiceWorker that referenced this pull request Feb 16, 2017
* 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.
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.

4 participants