<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>20104</bug_id>
          
          <creation_ts>2012-11-27 18:35:31 +0000</creation_ts>
          <short_desc>Algorithm for DOMTokenList.add seems wrong if tokens are present multiple times in the list</short_desc>
          <delta_ts>2012-12-04 15:55:21 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebAppsWG</product>
          <component>DOM</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows 3.1</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Boris Zbarsky">bzbarsky</reporter>
          <assigned_to name="Anne">annevk</assigned_to>
          <cc>bugs</cc>
    
    <cc>erik.arvidsson</cc>
    
    <cc>ian</cc>
    
    <cc>james</cc>
    
    <cc>jonas</cc>
    
    <cc>mike</cc>
    
    <cc>ojan</cc>
    
    <cc>www-dom</cc>
    
    <cc>zcorpan</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>78935</commentid>
    <comment_count>0</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2012-11-27 18:35:31 +0000</bug_when>
    <thetext>Consider this script:

  var d = document.createElement(&quot;div&quot;);
  d.classList.add(&quot;a&quot;, &quot;a&quot;);

If I read the spec right, the result of this will serialize as:

  &lt;div class=&quot;a a&quot;&gt;&lt;/div&gt;

which seems slightly odd.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>78938</commentid>
    <comment_count>1</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-11-27 18:43:11 +0000</bug_when>
    <thetext>Do we want to catch this? Is the extra validation step negligible?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>78947</commentid>
    <comment_count>2</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2012-11-27 19:29:18 +0000</bug_when>
    <thetext>I don&apos;t know.  None of this stuff is exactly super-fast, as currently specced.  How UAs optimize it is an interesting question; Gecko doesn&apos;t try very hard at the moment afaict, though I might change that.

One related question is whether we want:

  d.classList.add.apply(d.classList, args);

to have different behavior from:

  args.map(function(x) { d.classList.add(x); });

and in general what invariants we want this token list stuff to preserve.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>78974</commentid>
    <comment_count>3</comment_count>
    <who name="Jonas Sicking (Not reading bugmail)">jonas</who>
    <bug_when>2012-11-28 04:15:26 +0000</bug_when>
    <thetext>Optimizing the existing stuff for performance seems better to me than slowing things down even more. I don&apos;t have any concrete suggestions though.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>78987</commentid>
    <comment_count>4</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-11-28 11:40:51 +0000</bug_when>
    <thetext>Would there be a problem with changing the model of DOMTokenList to an ordered set instead?

The moment you start modifying class=&quot;&quot; through DOMTokenList, class=&quot;&quot; would simply become a simple serialization of DOMTokenList rather than preserving all the things it tries to do now.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79025</commentid>
    <comment_count>5</comment_count>
    <who name="Erik Arvidsson">erik.arvidsson</who>
    <bug_when>2012-11-28 18:44:53 +0000</bug_when>
    <thetext>The whole idea of trying to preserve the whitespaces of the class attribute when we mutate the DOMTokenList is something that has been bothered all along.

Let&apos;s remove duplicates and simply serialize by adding a space between each token.

This is what JS libs did for years and polyfills still do so it should be safe.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79033</commentid>
    <comment_count>6</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-11-28 19:35:03 +0000</bug_when>
    <thetext>The following is my plan:

DOMTokenList represents an ordered set (with set guaranteeing uniqueness, of course).

Manipulating its associated attribute (e.g. class=&quot;&quot;) seeds DOMTokenList.

Manipulating DOMTokenList seeds its associated attribute (a simple serialization of the ordered set, tokens separated by U+0020).

Somehow we avoid loops. DOMSettableTokenList does the same.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79125</commentid>
    <comment_count>7</comment_count>
    <who name="Olli Pettay">bugs</who>
    <bug_when>2012-11-29 15:15:58 +0000</bug_when>
    <thetext>To have sane toggle handling we need to remove duplicates.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79408</commentid>
    <comment_count>8</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-12-04 15:55:21 +0000</bug_when>
    <thetext>DOMTokenList is now defined as representing an ordered set. See bug 20105 for how that serializes to a string and parses from a string.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>