RESOLVED FIXED 148582
classList.toggle(name, force) treats undefined `force` argument as false
https://bugs.webkit.org/show_bug.cgi?id=148582
Summary classList.toggle(name, force) treats undefined `force` argument as false
Michał Gołębiowski-Owczarek
Reported 2015-08-28 11:25:51 PDT
Test case: var div = document.createElement('div'); div.classList.toggle('a', undefined); // <div></div> `toggle` should add the class and not treat `undefined` as false. Chrome & Edge also share this bug. Firefox implements it correctly. Chrome bug report: https://code.google.com/p/chromium/issues/detail?id=489665
Attachments
Patch (20.47 KB, patch)
2015-09-17 19:48 PDT, Chris Dumez
no flags
Patch (20.53 KB, patch)
2015-09-17 22:19 PDT, Chris Dumez
no flags
Patch (20.47 KB, patch)
2015-09-18 08:08 PDT, Chris Dumez
no flags
Michał Gołębiowski-Owczarek
Comment 1 2015-08-28 11:40:48 PDT
Chris Dumez
Comment 2 2015-08-28 13:33:15 PDT
Yes, this is not specific to this API but a general bug in our JS bindings code. undefined gets converted to 0 / false instead of being treated as no argument when the argument is optional. I will try and address this in the near future.
Michał Gołębiowski-Owczarek
Comment 3 2015-08-28 13:46:44 PDT
(In reply to comment #2) > I will try and address this in the near future. Great to hear that! This is very useful when you need to proxy the method. I'm developing an experimental jQuery plugin that replaces its class manipulation code with one utilizing classList and I had to write something like: if (force !== undefined) { this.classList.toggle(clazz, force); } else { this.classList.toggle(clazz); } instead of just passing the value. This is the full source: https://github.com/mzgol/jquery.classList/blob/3a7018254bf0545c54f6ff7d73eb21aadcfb8ec9/src/jquery.class_list.js#L108-L119
Chris Dumez
Comment 4 2015-09-02 14:22:07 PDT
Chris Dumez
Comment 5 2015-09-17 19:48:52 PDT
Chris Dumez
Comment 6 2015-09-17 22:19:18 PDT
Ryosuke Niwa
Comment 7 2015-09-18 00:09:36 PDT
Comment on attachment 261490 [details] Patch Does this match the behavior of other browsers?
Chris Dumez
Comment 8 2015-09-18 07:57:01 PDT
(In reply to comment #7) > Comment on attachment 261490 [details] > Patch > > Does this match the behavior of other browsers? It matches Firefox and the specification.
Chris Dumez
Comment 9 2015-09-18 08:08:55 PDT
WebKit Commit Bot
Comment 10 2015-09-18 09:53:27 PDT
Comment on attachment 261503 [details] Patch Clearing flags on attachment: 261503 Committed r189969: <http://trac.webkit.org/changeset/189969>
WebKit Commit Bot
Comment 11 2015-09-18 09:53:32 PDT
All reviewed patches have been landed. Closing bug.
Michał Gołębiowski-Owczarek
Comment 12 2015-09-18 10:04:43 PDT
Thanks! \o/ Do you also plan to fix the more general issue about WebIDL bindings mistreating undefined?
Chris Dumez
Comment 13 2015-09-18 10:43:23 PDT
(In reply to comment #12) > Thanks! \o/ > > Do you also plan to fix the more general issue about WebIDL bindings > mistreating undefined? Yes, I am fixing a lot of those via: https://bugs.webkit.org/show_bug.cgi?id=149263 https://bugs.webkit.org/show_bug.cgi?id=149331 If you know about more cases, please let me know.
Note You need to log in before you can comment on or make changes to this bug.