Commit 2de5a77d authored by Yuhong Sha's avatar Yuhong Sha Committed by Commit Bot

Return boolean for the replace method in DOMTokenList

The specification for DOMTokenList's replace() method
which would make it return a boolean.

Indicating true if a token was replaced, and false otherwise.

Bug: 820988
Signed-off-by: default avatarYuhong Sha <yuhong.sha@samsung.com>
Change-Id: I8e500a74a2504e13522c4e85b17d441cd2d4299f
Reviewed-on: https://chromium-review.googlesource.com/965683Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Reviewed-by: default avatarHayato Ito <hayato@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545018}
parent ba7b02ff
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -173,20 +173,20 @@ bool DOMTokenList::toggle(const AtomicString& token,
}
// https://dom.spec.whatwg.org/#dom-domtokenlist-replace
void DOMTokenList::replace(const AtomicString& token,
bool DOMTokenList::replace(const AtomicString& token,
const AtomicString& new_token,
ExceptionState& exception_state) {
// 1. If either token or newToken is the empty string, then throw a
// SyntaxError.
if (!CheckEmptyToken(token, exception_state) ||
!CheckEmptyToken(new_token, exception_state))
return;
return false;
// 2. If either token or newToken contains any ASCII whitespace, then throw an
// InvalidCharacterError.
if (!CheckTokenWithWhitespace(token, exception_state) ||
!CheckTokenWithWhitespace(new_token, exception_state))
return;
return false;
// https://infra.spec.whatwg.org/#set-replace
// To replace within an ordered set set, given item and replacement: if set
......@@ -217,13 +217,14 @@ void DOMTokenList::replace(const AtomicString& token,
}
}
// TODO(tkent): This check doesn't conform to the DOM specification, but it's
// interoperable with Firefox and Safari.
// https://github.com/whatwg/dom/issues/462
// 3. If context object's token set does not contain token, then return false.
if (!did_update)
return;
return false;
UpdateWithTokenSet(token_set_);
// 6. Return true.
return true;
}
bool DOMTokenList::supports(const AtomicString& token,
......
......@@ -56,7 +56,7 @@ class CORE_EXPORT DOMTokenList : public ScriptWrappable {
void remove(const Vector<String>&, ExceptionState&);
bool toggle(const AtomicString&, ExceptionState&);
bool toggle(const AtomicString&, bool force, ExceptionState&);
void replace(const AtomicString& token,
bool replace(const AtomicString& token,
const AtomicString& new_token,
ExceptionState&);
bool supports(const AtomicString&, ExceptionState&);
......
......@@ -34,7 +34,7 @@
[RaisesException, CEReactions, CustomElementCallbacks] void add(DOMString... tokens);
[RaisesException, CEReactions, CustomElementCallbacks] void remove(DOMString... tokens);
[RaisesException, CEReactions, CustomElementCallbacks] boolean toggle(DOMString token, optional boolean force);
[RaisesException, CEReactions] void replace(DOMString token, DOMString newToken);
[RaisesException, CEReactions] boolean replace(DOMString token, DOMString newToken);
[RaisesException, CustomElementCallbacks] boolean supports(DOMString token);
[CEReactions] attribute DOMString value;
stringifier;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment