Bug 1681518 - Error message for DOMTokenList#add could be better. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D148961
This commit is contained in:
@@ -105,33 +105,32 @@ void nsDOMTokenList::SetValue(const nsAString& aValue, ErrorResult& rv) {
|
|||||||
rv = mElement->SetAttr(kNameSpaceID_None, mAttrAtom, aValue, true);
|
rv = mElement->SetAttr(kNameSpaceID_None, mAttrAtom, aValue, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult nsDOMTokenList::CheckToken(const nsAString& aStr) {
|
void nsDOMTokenList::CheckToken(const nsAString& aToken, ErrorResult& aRv) {
|
||||||
if (aStr.IsEmpty()) {
|
if (aToken.IsEmpty()) {
|
||||||
return NS_ERROR_DOM_SYNTAX_ERR;
|
return aRv.ThrowSyntaxError("The empty string is not a valid token.");
|
||||||
}
|
}
|
||||||
|
|
||||||
nsAString::const_iterator iter, end;
|
nsAString::const_iterator iter, end;
|
||||||
aStr.BeginReading(iter);
|
aToken.BeginReading(iter);
|
||||||
aStr.EndReading(end);
|
aToken.EndReading(end);
|
||||||
|
|
||||||
while (iter != end) {
|
while (iter != end) {
|
||||||
if (nsContentUtils::IsHTMLWhitespace(*iter))
|
if (nsContentUtils::IsHTMLWhitespace(*iter)) {
|
||||||
return NS_ERROR_DOM_INVALID_CHARACTER_ERR;
|
return aRv.ThrowInvalidCharacterError(
|
||||||
|
"The token can not contain whitespace.");
|
||||||
|
}
|
||||||
++iter;
|
++iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult nsDOMTokenList::CheckTokens(const nsTArray<nsString>& aTokens) {
|
void nsDOMTokenList::CheckTokens(const nsTArray<nsString>& aTokens,
|
||||||
|
ErrorResult& aRv) {
|
||||||
for (uint32_t i = 0, l = aTokens.Length(); i < l; ++i) {
|
for (uint32_t i = 0, l = aTokens.Length(); i < l; ++i) {
|
||||||
nsresult rv = CheckToken(aTokens[i]);
|
CheckToken(aTokens[i], aRv);
|
||||||
if (NS_FAILED(rv)) {
|
if (aRv.Failed()) {
|
||||||
return rv;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool nsDOMTokenList::Contains(const nsAString& aToken) {
|
bool nsDOMTokenList::Contains(const nsAString& aToken) {
|
||||||
@@ -179,7 +178,7 @@ void nsDOMTokenList::AddInternal(const nsAttrValue* aAttr,
|
|||||||
|
|
||||||
void nsDOMTokenList::Add(const nsTArray<nsString>& aTokens,
|
void nsDOMTokenList::Add(const nsTArray<nsString>& aTokens,
|
||||||
ErrorResult& aError) {
|
ErrorResult& aError) {
|
||||||
aError = CheckTokens(aTokens);
|
CheckTokens(aTokens, aError);
|
||||||
if (aError.Failed()) {
|
if (aError.Failed()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -216,7 +215,7 @@ void nsDOMTokenList::RemoveInternal(const nsAttrValue* aAttr,
|
|||||||
|
|
||||||
void nsDOMTokenList::Remove(const nsTArray<nsString>& aTokens,
|
void nsDOMTokenList::Remove(const nsTArray<nsString>& aTokens,
|
||||||
ErrorResult& aError) {
|
ErrorResult& aError) {
|
||||||
aError = CheckTokens(aTokens);
|
CheckTokens(aTokens, aError);
|
||||||
if (aError.Failed()) {
|
if (aError.Failed()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -237,7 +236,7 @@ void nsDOMTokenList::Remove(const nsAString& aToken, ErrorResult& aError) {
|
|||||||
|
|
||||||
bool nsDOMTokenList::Toggle(const nsAString& aToken,
|
bool nsDOMTokenList::Toggle(const nsAString& aToken,
|
||||||
const Optional<bool>& aForce, ErrorResult& aError) {
|
const Optional<bool>& aForce, ErrorResult& aError) {
|
||||||
aError = CheckToken(aToken);
|
CheckToken(aToken, aError);
|
||||||
if (aError.Failed()) {
|
if (aError.Failed()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -271,16 +270,16 @@ bool nsDOMTokenList::Replace(const nsAString& aToken,
|
|||||||
// characters, and aNewToken is empty, the returned error should be a
|
// characters, and aNewToken is empty, the returned error should be a
|
||||||
// SyntaxError, not an InvalidCharacterError.
|
// SyntaxError, not an InvalidCharacterError.
|
||||||
if (aNewToken.IsEmpty()) {
|
if (aNewToken.IsEmpty()) {
|
||||||
aError.Throw(NS_ERROR_DOM_SYNTAX_ERR);
|
aError.ThrowSyntaxError("The empty string is not a valid token.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
aError = CheckToken(aToken);
|
CheckToken(aToken, aError);
|
||||||
if (aError.Failed()) {
|
if (aError.Failed()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
aError = CheckToken(aNewToken);
|
CheckToken(aNewToken, aError);
|
||||||
if (aError.Failed()) {
|
if (aError.Failed()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,8 +80,9 @@ class nsDOMTokenList : public nsISupports, public nsWrapperCache {
|
|||||||
protected:
|
protected:
|
||||||
virtual ~nsDOMTokenList();
|
virtual ~nsDOMTokenList();
|
||||||
|
|
||||||
nsresult CheckToken(const nsAString& aStr);
|
void CheckToken(const nsAString& aToken, mozilla::ErrorResult& aRv);
|
||||||
nsresult CheckTokens(const nsTArray<nsString>& aStr);
|
void CheckTokens(const nsTArray<nsString>& aTokens,
|
||||||
|
mozilla::ErrorResult& aRv);
|
||||||
void AddInternal(const nsAttrValue* aAttr, const nsTArray<nsString>& aTokens);
|
void AddInternal(const nsAttrValue* aAttr, const nsTArray<nsString>& aTokens);
|
||||||
void RemoveInternal(const nsAttrValue* aAttr,
|
void RemoveInternal(const nsAttrValue* aAttr,
|
||||||
const nsTArray<nsString>& aTokens);
|
const nsTArray<nsString>& aTokens);
|
||||||
|
|||||||
Reference in New Issue
Block a user