Bug 1444909 part 1. Fix DOMTokenList.replace() to not do the attr set when the old token was not found. r=qdot

This fixes upcoming tests that will check when we actually mutate the attribute.

MozReview-Commit-ID: 7r5ErK9wvir
This commit is contained in:
Boris Zbarsky 2018-03-14 16:08:58 -04:00
Родитель 8a5136ff57
Коммит cbabf9ebea
1 изменённых файлов: 16 добавлений и 3 удалений

Просмотреть файл

@ -352,6 +352,20 @@ nsDOMTokenList::ReplaceInternal(const nsAttrValue* aAttr,
{
RemoveDuplicates(aAttr);
// Trying to do a single pass here leads to really complicated code. Just do
// the simple thing.
bool haveOld = false;
for (uint32_t i = 0; i < aAttr->GetAtomCount(); ++i) {
if (aAttr->AtomAt(i)->Equals(aToken)) {
haveOld = true;
break;
}
}
if (!haveOld) {
// Make sure to not touch the attribute value in this case.
return;
}
bool sawIt = false;
nsAutoString resultStr;
for (uint32_t i = 0; i < aAttr->GetAtomCount(); i++) {
@ -374,9 +388,8 @@ nsDOMTokenList::ReplaceInternal(const nsAttrValue* aAttr,
resultStr.Append(nsDependentAtomString(aAttr->AtomAt(i)));
}
if (sawIt) {
mElement->SetAttr(kNameSpaceID_None, mAttrAtom, resultStr, true);
}
MOZ_ASSERT(sawIt, "How could we not have found our token this time?");
mElement->SetAttr(kNameSpaceID_None, mAttrAtom, resultStr, true);
}
bool