[whatwg] Specification unclear about how HTMLElement.prototype.onscroll's getter/setter should behave for "body" elements
Boris Zbarsky
bzbarsky at MIT.EDU
Mon Dec 3 05:58:14 PST 2012
Consider this testcase:
var desc = Object.getOwnPropertyDescriptor(HTMLElement.prototype,
"onscroll");
desc.set.call(document.body, function() { alert(this); });
Is the listener added on the body, or the window?
The relevant parts of the spec are:
1) "onscroll" is present on both HTMLElement.prototype and
HTMLBodyElement.prototype. This testcase explicitly invokes the setter
for the former.
2) The spec text at
http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#handler-onscroll
(scroll up; there is no way to link to the actual text) says:
The following are the event handlers (and their corresponding event
handler event types) that must be supported by all HTML elements
other than body and frameset, as both content attributes and IDL
attributes, and on Document objects, as IDL attributes
It's not clear to me what this means since the properties are on
HTMLElement.prototype so they can be applied to all HTML elements. What
does this text mean in terms of the testcase above?
Basically, I can see three possible behaviors here. Either the
HTMLElement.prototype.onscroll setter behaves the same way on all
elements (and hence the above adds the event handler on the body) or it
behaves specially for the body element, forwarding to the window (and
then we don't need HTMLBodyElement.prototype.onscroll), or it throws for
the body element. Which one is intended?
-Boris
More information about the whatwg
mailing list