Closed Bug 1359780 Opened 7 years ago Closed 7 years ago

Update DOMTokenList for spec changes

Categories

(Core :: DOM: Core & HTML, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: ayg, Assigned: ayg)

References

Details

Attachments

(1 file)

https://github.com/whatwg/dom/pull/444

There's only one change relevant to us: .toggle() and .replace() always remove duplicates and whitespace from the DOM attribute, even if they're no-ops.  This matches .add() and .remove(), and sometimes .replace().  Per spec, .replace() used to rewrite the attribute if you replaced a token with itself, but not if the token to replace isn't in the set.
Attachment #8861918 - Flags: review?(michael)
Attachment #8861918 - Flags: review?(michael) → review?(masayuki)
Comment on attachment 8861918 [details]
Bug 1359780 - Always remove duplicates/whitespace in DOMTokenList methods

https://reviewboard.mozilla.org/r/133932/#review136816

::: dom/base/nsDOMTokenList.cpp:305
(Diff revision 1)
>    (*tokens.AppendElement()).Rebind(aToken.Data(), aToken.Length());
>  
> -  if (isPresent) {
> +  if (isPresent && !forceOn) {
> -    if (!forceOn) {
> -      RemoveInternal(attr, tokens);
> +    RemoveInternal(attr, tokens);
> -      isPresent = false;
> +    isPresent = false;

I think that use |return false;| is simpler.

::: dom/base/nsDOMTokenList.cpp:306
(Diff revision 1)
>  
> -  if (isPresent) {
> +  if (isPresent && !forceOn) {
> -    if (!forceOn) {
> -      RemoveInternal(attr, tokens);
> +    RemoveInternal(attr, tokens);
> -      isPresent = false;
> +    isPresent = false;
> -    }
> +  } else if (!isPresent && !forceOff) {

Then, this can be |if (!isPresent && !forceOff) {| (ommitting else).

::: dom/base/nsDOMTokenList.cpp:308
(Diff revision 1)
> -      isPresent = false;
> +    isPresent = false;
> -    }
> +  } else if (!isPresent && !forceOff) {
> -  } else {
> -    if (!forceOff) {
> -      AddInternal(attr, tokens);
> +    AddInternal(attr, tokens);
> -      isPresent = true;
> +    isPresent = true;

So, this should |return true;|.

::: dom/base/nsDOMTokenList.cpp:309
(Diff revision 1)
> -    }
> +  } else if (!isPresent && !forceOff) {
> -  } else {
> -    if (!forceOff) {
> -      AddInternal(attr, tokens);
> +    AddInternal(attr, tokens);
> -      isPresent = true;
> +    isPresent = true;
> +  } else if (attr) {

Then,

if (!attr) {
  return isPresent;
}

And reduce the following block's indent.
Attachment #8861918 - Flags: review?(masayuki) → review+
Comment on attachment 8861918 [details]
Bug 1359780 - Always remove duplicates/whitespace in DOMTokenList methods

https://reviewboard.mozilla.org/r/133932/#review136816

> Then,
> 
> if (!attr) {
>   return isPresent;
> }
> 
> And reduce the following block's indent.

We need to return isPresent whether attr is true or false, so the if (attr) { block needs to stay as it is.
Pushed by ayg@aryeh.name:
https://hg.mozilla.org/integration/autoland/rev/47b53e3d4b27
Always remove duplicates/whitespace in DOMTokenList methods r=masayuki
https://hg.mozilla.org/mozilla-central/rev/47b53e3d4b27
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla55
Target Milestone: mozilla55 → ---
This spec change was reverted: https://github.com/whatwg/dom/issues/451
Status: REOPENED → RESOLVED
Closed: 7 years ago7 years ago
Resolution: --- → INVALID
Removing leave-open keyword from resolved bugs, per :sylvestre.
Keywords: leave-open
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: