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

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:

<script>
   (function f() {alert(this);}).call(undefined);
</script>

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.

-Boris

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