Skip to content

Commit

Permalink
Close #123: remove feature detection from add() and add supports()
Browse files Browse the repository at this point in the history
This change replaces the feature detection method for DOMTokenLists:

* It removes references to "validation steps" from add(), toggle(), replace() and object creation.
* It adds supports() as discussed.
* When associated attribute has no supported tokens, TypeError is thrown (by "validation steps").
  • Loading branch information
yoavweiss authored and annevk committed Dec 15, 2015
1 parent 8e97cc3 commit ff4f0e8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 50 deletions.
54 changes: 27 additions & 27 deletions dom.bs
Original file line number Diff line number Diff line change
Expand Up @@ -8531,10 +8531,11 @@ interface DOMTokenList {
readonly attribute unsigned long length;
getter DOMString? item(unsigned long index);
boolean contains(DOMString token);
boolean add(DOMString... tokens);
void add(DOMString... tokens);
void remove(DOMString... tokens);
boolean toggle(DOMString token, optional boolean force);
void replace(DOMString token, DOMString newToken);
boolean supports(DOMString token);
stringifier;
iterable<DOMString>;
};
Expand All @@ -8556,7 +8557,7 @@ associated <a>attribute</a>'s <a for=Attr>local name</a>.

<ol>
<li><p>If the associated <a>attribute</a>'s <a for=Attr>local name</a> does not define
<a>supported tokens</a>, return true.
<a>supported tokens</a>, <a>throw</a> a <code>TypeError</code>.

<li><p>Let <var>lowercase token</var> be a copy of <var>token</var>,
<a>converted to ASCII lowercase</a>.
Expand Down Expand Up @@ -8591,16 +8592,8 @@ are to:
<a lt="named attribute"><var>associated attribute's local name</var> attribute</a> or
associated <a for="/">element</a>'s
<a lt="named attribute"><var>associated attribute's local name</var> attribute</a> is
<a lt="attribute is set">set</a>, run these substeps:

<ol>
<li><p>Let <var>temporary tokens</var> be the new <a for=Attr>value</a>,
<a lt="ordered set parser">parsed</a>.

<li><p>For each <var>token</var> in <var>temporary tokens</var>, run
<a>validation steps</a> with <var>token</var>. If the return value is true, append <var>token</var>
to <a>tokens</a>.
</ol>
<a lt="attribute is set">set</a>, set <a>tokens</a> to the new <a for=Attr>value</a>,
<a lt="ordered set parser">parsed</a>.

<p>When an associated <a for="/">element</a>'s
<a lt="named attribute"><var>associated attribute's local name</var> attribute</a> is
Expand All @@ -8623,11 +8616,10 @@ associated <a for="/">element</a>'s

<dt><code><var>tokenlist</var> . <a for=DOMTokenList lt="add()">add(<var>tokens</var>&hellip;)</a></code>
<dd>
<p>Adds all valid arguments passed, except those already present.
<p>Adds all arguments passed, except those already present.
<p>Throws a {{SyntaxError}} exception if one if the arguments is the empty string.
<p>Throws an {{InvalidCharacterError}} exception if one of the arguments contains any
<a>ASCII whitespace</a>.
<p>Returns false if any invalid arguments passed, true otherwise.

<dt><code><var>tokenlist</var> . <a for=DOMTokenList lt="remove()">remove(<var>tokens</var>&hellip;)</a></code>
<dd>
Expand All @@ -8639,8 +8631,8 @@ associated <a for="/">element</a>'s
<dt><code><var>tokenlist</var> . <a method for=DOMTokenList lt="toggle()">toggle(<var>token</var> [, <var>force</var>])</a></code>
<dd>
<p>If <var>force</var> is not given, "toggles" <var>token</var>, removing it if it's present and
adding it if it's not present and is valid. If <var>force</var> is true, adds <var>token</var>
if it is valid (same as {{add()}}). If <var>force</var> is false, removes <var>token</var> (same
adding it if it's not present. If <var>force</var> is true, adds <var>token</var>
(same as {{add()}}). If <var>force</var> is false, removes <var>token</var> (same
as {{DOMTokenList/remove()}}).
<p>Returns true if <var>token</var> is now present, and false otherwise.
<p>Throws a {{SyntaxError}} exception if <var>token</var> is empty.
Expand All @@ -8652,6 +8644,12 @@ associated <a for="/">element</a>'s
<p>Throws a {{SyntaxError}} exception if one if the arguments is the empty string.
<p>Throws an {{InvalidCharacterError}} exception if one of the arguments contains any
<a>ASCII whitespace</a>.

<dt><code><var>tokenlist</var> . <a method for=DOMTokenList lt="supports()">supports(<var>token</var>)</a></code>
<dd>
<p>Returns true if <var>token</var> is in the associated attribute's supported tokens. Returns
false otherwise.
<p>Throws a <code>TypeError</code> exception if the associated attribute has no supported tokens defined.
</dl>

<p>The <dfn attribute for=DOMTokenList><code>length</code></dfn> attribute' getter must return the
Expand Down Expand Up @@ -8698,15 +8696,10 @@ method, when invoked, must run these steps:
{{InvalidCharacterError}} exception.
</ol>

<li>Let <var>valid</var> be true.

<li><p>For each <var>token</var> in <var>tokens</var>, in given order, that is not in
<a>tokens</a>, run <a>validation steps</a> with <var>token</var>. If the return value is false,
set <var>valid</var> to false. Otherwise, append <var>token</var> to <a>tokens</a>.
<a>tokens</a>, append <var>token</var> to <a>tokens</a>.

<li><p>Run the <a>update steps</a>.

<li><p>Return <var>valid</var>.
</ol>

<p>The
Expand Down Expand Up @@ -8754,9 +8747,6 @@ method, when invoked, must run these steps:
<ol>
<li><p>If <var>force</var> is passed and is false, return false.

<li><p>Otherwise, run <a>validation steps</a> with <var>token</var>. If the return value is
false, return false.

<li><p>Otherwise, append <var>token</var> to <a>tokens</a>, run the <a>update steps</a>, and
return true.
</ol>
Expand All @@ -8774,14 +8764,24 @@ method, when invoked, must run these steps:
<li><p>If either <var>token</var> or <var>newToken</var> contains any <a>ASCII whitespace</a>,
<a>throw</a> an {{InvalidCharacterError}} exception.

<li><p>If <var>token</var> is not in <a>tokens</a> or running the <a>validation steps</a> for
<var>newToken</var> return false, terminate these steps.
<li><p>If <var>token</var> is not in <a>tokens</a>, terminate these steps.

<li><p>Replace <var>token</var> in <a>tokens</a> with <var>newToken</var>.

<li><p>Run the <a>update steps</a>.
</ol>

<p>The
<dfn method for="DOMTokenList" lt="supports(token)"><code>supports(<var>token</var>&hellip;)</code></dfn>
method, when invoked, must run these steps:

<ol>
<li><p>Let <var>result</var> be the return value of <a>validation steps</a> called with
<var>token</var>. Rethrow any exceptions.

<li><p>Return <var>result</var>.
</ol>

<p>The <dfn export for=DOMTokenList id=dom-domtokenlist-stringifier>stringification behavior</dfn>
must return the result of running <a>context object</a>'s <a>serialize steps</a>.

Expand Down
Loading

3 comments on commit ff4f0e8

@ArkadiuszMichalski
Copy link
Contributor

Choose a reason for hiding this comment

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

@yoavweiss supports() takes single token or we can pass more than one token? I see ... in prose (https://dom.spec.whatwg.org/#dom-domtokenlist-supports) but not in IDL.

@yoavweiss
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's supposed to take a single token. I no longer see that, so I'm assuming it was fixed in the mean time?

@annevk
Copy link
Member

@annevk annevk commented on ff4f0e8 Jan 4, 2016

Choose a reason for hiding this comment

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

Yeah I fixed this in a97debc.

Please sign in to comment.