W3C home > Mailing lists > Public > public-script-coord@w3.org > July to September 2013

Re: [WebIDL] Which realm should be used for coercing null/undefined this values to "the" global object?

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Mon, 23 Sep 2013 20:07:28 -0400
Message-ID: <5240D7C0.3090206@mit.edu>
To: David Bruant <bruant.d@gmail.com>
CC: "public-script-coord@w3.org" <public-script-coord@w3.org>
On 9/23/13 5:43 PM, David Bruant wrote:
> Maybe IE9 has a form of self-hosted addEventListener, somthing like:
>      EventTarget.prototype.addEventListener = function(type, listener){
>          // use |this| as an object
>      }
> IE9 has no support for strict mode, so the code would be non-strict and
> "this" has the global object as value by default when the function is
> called as a function (as opposed to as a method).

It has the global object as default value no matter how it's called, in 
non-strict code.  Simple testcase:

   (function f() {alert(this);}).call(undefined);

try it in your favorite browser.

> That could explain why
> "addEventListener()" works, but "addEventListener.call(undefined)" doesn't.

I don't see how.

> The sane behavior would be for
> "something.addEventListener.call(undefined, ..." to throw a TypeError
> (on the basis that undefined is not a platform object). But I imagine IE
> moved away from that behavior for web compat?

Unless I'm missing something, that case is not really distinguishable, 
from inside the function, from bareword addEventListener() being invoked.

This last works in all UAs I have access too, and is needed for web compat.

>> Conceptually, using the global of the realm of the function involved
>> (i.e. the Chrome/Firefox/IE10 behavior) makes sense to me.
> Assuming throwing a TypeError isn't an option, if by "the function"
> you're referring to addEventListener

I am, yes.  The thing called with thisArg == undefined.

Received on Tuesday, 24 September 2013 00:08:00 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:14:18 UTC