classList.toggle(name, force) treats undefined `force` argument as false
https://bugs.webkit.org/show_bug.cgi?id=148582
<rdar://problem/
22545600>
Reviewed by Ryosuke Niwa.
Source/WebCore:
classList.toggle(name, force) treats undefined `force` argument as false.
However, according to the Web IDL specification, we should treat undefined
as if the value was missing for optional parameters that do not have a
default value:
https://heycam.github.io/webidl/#dfn-overload-resolution-algorithm (Step 14.4).
For optional parameters that have a default value, undefined should be
converted into the default value. This is supported as of r189957.
In this patch, we use custom bindings to provide a spec-compliant version
of DOMTokenList.toggle(). Unfortunately, adding such support in the
bindings generator would be a non-trivial task (I guess, we would have to
generalize using WTF::Optional<> type for all optional parameters in our
implementation. Also we cannot use the default value support added in
r189957 because the toggle() implementation needs to be able to
distinguish all 3 states for the 'force' parameter: true, false or
missing.
The new behavior matches the behavior of Firefox and the specification.
Test: fast/dom/Element/class-list-toggle.html
* CMakeLists.txt:
* WebCore.vcxproj/WebCore.vcxproj:
* WebCore.vcxproj/WebCore.vcxproj.filters:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSBindingsAllInOne.cpp:
* bindings/js/JSDOMTokenListCustom.cpp: Added.
(WebCore::JSDOMTokenList::toggle):
* html/DOMTokenList.h:
* html/DOMTokenList.idl:
LayoutTests:
Add decent test coverage for DOMTokenList.toggle() via Element.classList.
* fast/dom/Element/class-list-toggle-expected.txt: Added.
* fast/dom/Element/class-list-toggle.html: Added.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@189969
268f45cc-cd09-0410-ab3c-
d52691b4dbfc