removeEventListener with only one passed parameter...

Hey folks,

I was reviewing a site-compatibility issue with IE on the phone, and ran across what I think to be a Chrome implementation bug, but I wanted to post my findings in case I messed up the interpretation—it has to do with undefined handling in WebIDL I think.

The API is removeEventListener defined in DOM4 [1] as:

void removeEventListener(DOMString type, EventListener? callback, optional boolean capture = false);

The site-compatibility problem occurs because the site is [unknowingly?] calling this API with only one param:

ob.removeEventListener(‘click’);

and no exception is thrown. In IE and Firefox, this throws because 2 params are expected to this function. In Chrome, the call silently fails (no exception). Note that IE and Firefox do not throw when passing undefined explicitly: ob.removeEventListener(‘click’, undefined).

Per WebIDL AFAICT, this method would be invoked with the following values: (‘click’, <missing>, false), since the optional 3rd arg with a default gets substituted when no value is passed (and would also be substituted if undefined as a value were specifically passed). I’m pretty sure the nullable 2nd arg is not considered “optional” per the “optionality” determination in WebIDL. If it is, then undefined would type-convert to null, and Chrome’s behavior of not-throwing is right, but I can’t quite see how that would work.

Would love your clarification. Is this a Chrome bug or a spec bug?

[1] http://w3c.github.io/dom/#eventtarget

Received on Monday, 9 June 2014 20:08:10 UTC