Bug 18547 - Add [ImplicitThis] to EventTarget?
Add [ImplicitThis] to EventTarget?
Status: NEW
Product: WebAppsWG
Classification: Unclassified
Component: WebIDL
unspecified
All Windows 3.1
: P2 normal
: ---
Assigned To: Cameron McCormack
public-webapps-bugzilla
[v1]
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-08-13 12:13 UTC by Ms2ger
Modified: 2013-06-17 01:20 UTC (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ms2ger 2012-08-13 12:13:49 UTC
window.addEventListener.call(null, "a", function (e) { w(e) })

seems to work, while it isn't allowed per WebIDL.

I'm not actually sure what [ImplicitThis] is good for, and why we don't always turn null/undefined into the window; maybe Cameron can explain.
Comment 1 Cameron McCormack 2012-08-14 07:59:20 UTC
In ES3, Function.prototype.call would treat a first argument value of undefined or null as the global object instead, which would make the call you wrote work.  ES5 removed this:

  http://people.mozilla.org/~jorendorff/es5.html#sec-15.3.4.4

[LenientThis] is for if you need to work around that.  But I'd like to know if it's really needed before adding it to addEventListener.  Or if we could even remove [LenientThis] from the spec.  It used to be used somewhere in HTML but I can't see it in use now.
Comment 3 Anne 2012-09-21 10:07:42 UTC
Anyone thought about this some more? Are the problems raised with HTML fixed?
Comment 4 Boris Zbarsky 2012-11-26 16:26:15 UTC
This isn't about [LenientThis]; [LenientThis] doesn't do what's needed here.

Gecko's WebIDL bindings effectively implement the ES3 behavior, for what it's worth: they always compute "this" to an object, just like non-strict-mode functions do in ES5...
Comment 5 Boris Zbarsky 2012-12-03 14:08:50 UTC
Is there a black-box-detectable difference between putting [ImplicitThis] on all interfaces implemented by the global object (which may not be a Window) and simply having [ImplicitThis] on all interfaces?
Comment 6 Cameron McCormack 2012-12-07 00:59:04 UTC
(In reply to comment #5)
> Is there a black-box-detectable difference between putting [ImplicitThis] on
> all interfaces implemented by the global object (which may not be a Window)
> and simply having [ImplicitThis] on all interfaces?

No, there would be no difference, because when calling a function from some [ImplicitThis]-annotated not-implemented-by-Window interface, you will get a TypeError thrown from step 1 of http://dev.w3.org/2006/webapi/WebIDL/#es-operations, and if it wasn't [ImplicitThis]-annotated then you would get a TypeError because http://es5.github.com/#x10.4.3 would turn the null into the global object, and this wouldn't be the right kind of object to call the function on.

One of the problems mentioned in the IRC log was that without [ImplicitThis],

  interface WindowProxy {
    readonly attribute WindowProxy window;
  };

you can't actually evaluate `window` in strict mode.  And anyway [ImplicitThis] is currently only defined to work on operations, not attributes.

So we obviously need it for that attribute.  And comment 0 says we need it for window.addEventListener.call().  Do we need it for a specific set of functions, or just for everything on window?  I'm wondering if doing it for everything on window defeats (some of) the purpose of strict mode.
Comment 7 Boris Zbarsky 2012-12-07 01:23:17 UTC
>  interface WindowProxy {
>    readonly attribute WindowProxy window;
>  };

That seems nonsensical.  Shouldn't that attribute be on Window?  There is no actual WindowProxy interface....  (Or no actual Window interface; pick your poison.)

But yes, the getter for that attribute needs to have something like [ImplicitThis].

My gut reaction is that every single thing on Window should have it so we don't break the web, but it's worth checking with the ES folks for what they want here.
Comment 8 Cameron McCormack 2012-12-07 01:30:03 UTC
(In reply to comment #7)
> >  interface WindowProxy {
> >    readonly attribute WindowProxy window;
> >  };
> 
> That seems nonsensical.  Shouldn't that attribute be on Window?  There is no
> actual WindowProxy interface....  (Or no actual Window interface; pick your
> poison.)

Er, yep.

> But yes, the getter for that attribute needs to have something like
> [ImplicitThis].
> 
> My gut reaction is that every single thing on Window should have it so we
> don't break the web, but it's worth checking with the ES folks for what they
> want here.

Allen, can you tell us about the intentions of strict mode's "not converting null/undefined to the global object" and whether that was intended to apply to everything on the window object, or more for user defined functions?