[whatwg] DOMTokenList: mutation clarification
sylvain.pasche at gmail.com
Mon Aug 10 10:48:57 PDT 2009
On Mon, Aug 10, 2009 at 1:09 AM, Ian Hickson<ian at hixie.ch> wrote:
> I've reworded it to imply only one mutation event fires.
>> 2) (using the class attribute for the discussion) What should happen when you
>> do a remove("foo") on an element which has no class attribute?
>> My understanding is that it shouldn't add a class attribute with an empty
>> string. That's because the remove() algorithm starts with an empty string and
>> doesn't change it, so the " when the object mutates this empty string, " case
>> shouldn't be true (and thus no attribute modification should happen).
>> However Simon's testcase  doesn't agree with this, and adds an empty
>> string. So maybe it's worth clarifying this situation?
> I think that the spec now implies that you set the attribute to the empty
> string. Do you agree?
I don't think it changes the interpretation of this border case and I
still think the spec implies that no attribute is added.
Maybe the ambiguity is about the definition of mutation in the "when
the object mutates this empty string" sentence. If we have an element
with no class attribute and call .remove("foo"),
we start the remove() algorithm with the empty string and it doesn't
modify that string. So I would say that there wasn't a mutation and
that no attribute should be added.
One way to clarify that no attribute should be added might be (the
change is between the parentheses):
"When the attribute is absent, then the string represented by the
object is the empty string; when the object mutates this empty string
(that is, the algorithm changes the underlying string to a non-empty
string), the user agent must add the corresponding content attribute,
with its value set to the value it would have been set to after
mutating the empty string."
I also assume an "otherwise, do nothing" at the end of that sentence.
Do you think somebody could interpret this as an "otherwise add an
attribute set to the empty string"?
More information about the whatwg