[whatwg] Specification unclear about how HTMLElement.prototype.onscroll's getter/setter should behave for "body" elements

Ian Hickson ian at hixie.ch
Mon Dec 3 11:05:35 PST 2012


On Mon, 3 Dec 2012, Boris Zbarsky wrote:
>
> 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?

What do browsers do?

This should probably be defined in WebIDL. It relatess also to:

   https://www.w3.org/Bugs/Public/show_bug.cgi?id=17201

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'


More information about the whatwg mailing list