-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DOMTokenList#toggle: don't treat everything non-undefined as true #64
Comments
I found this to be a very weird part of the spec as well. I agree with you on the best solution being:
|
@mzgol The spec IDL says:
which means that passing undefined is the same as passing no second argument at all (your observed Firefox and IE behavior). That's precisely for the proxying reason you describe. The part that you link to at https://dom.spec.whatwg.org/#dom-domtokenlist-toggle will have |
Oh, and to be clear what IDL does for an
|
Ah goodness, Web IDL. Thanks @bzbarsky. Of course, now that Firefox is the only browser following the spec we might have a problem... especially as Edge seems to have purposefully regressed to match Chrome/Safari :( |
Edge is basically reverse-engineering whatever Chrome does, bugs and all. Can't say I blame them... That said, the fact that Chrome mishandles the way |
@bzbarsky Thanks for clarifying, I'm not that familiar with Web IDL.
Actually, I should've included IE in this matrix as it just doesn't implement the second parameter to the BTW, I found the Chrome report about that: https://crbug.com/489665. I've reported it to WebKit: https://bugs.webkit.org/show_bug.cgi?id=148582 and Edge: https://connect.microsoft.com/IE/feedbackdetail/view/1725606/ as well. |
I guess we can close the issue since the spec is OK and non-Firefox browsers should update their behavior? Or do we want to first check if this is mobile-web-compatible or something? (BTW, after today I can recognize each of Chrome, Firefox, Safari, Edge & IE 11 just by checking results of various |
@mzgol hah, yes, if you test a given feature enough, you can use it to detect all browsers, and often different versions of browsers too! I think I'm closing this and if a browser finds out this is not compatible they can file a new focused issue. Thank you all for your efforts. |
According to the 3rd & 4th step at https://dom.spec.whatwg.org/#dom-domtokenlist-toggle,
DOMTokenList#toggle
treats every non-false
value of the second argument astrue
. In particular:So, according to the spec, these should be
div.classList.contains('a')
results after the first & secondtoggle
invocation:This is because
force
is passed and is notfalse
so the first sub-step of the 3rd step doesn't apply.Now, these are the results in popular browsers:
Chrome 44, Safari 8, Edge:
Firefox 40, IE 11 (edit: IE just ignores the second parameter to toggle in all cases):
Now, if you change
undefined
tonull
in both those cases, all browsers return:This indicates all browsers cast the
force
value to a boolean and only some of them make an exception forundefined
, treating it as an argument not passed.IMO the Firefox & IE 11 behavior is the most sensible one. This allows to proxy the
toggle
method without checking the number of arguments passed:In any case, the currently specced behavior is not matching reality and is surprising (I'd certainly not expect
undefined
to be treated astrue
).The text was updated successfully, but these errors were encountered: