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

Re: This binding and ES5 builtins

From: Brendan Eich <brendan@mozilla.org>
Date: Thu, 7 Jul 2011 11:15:25 -0700
Cc: "Mark S. Miller" <erights@google.com>, public-script-coord@w3.org, "es5-discuss@mozilla.org discussion" <es5-discuss@mozilla.org>
Message-Id: <08981231-C24F-4FC8-9ED9-B16A57CEDD84@mozilla.org>
To: Luke Hoban <lukeh@microsoft.com>
On Jul 7, 2011, at 11:05 AM, Brendan Eich wrote:

> On Jul 7, 2011, at 10:33 AM, Luke Hoban wrote:
>>  Also, the note that “if a host supplied function is somehow converting this/undefined to the caller's global object it is doing something magical”, is concerning.  As far as I understand, with multiple globals, the web-compatible behaviour is to pass the caller-side global.
> 
> No! Ah, I see Oliver replied.
> 
> The situation with caller-side |this| computation in non-strict global code is not to pass null or undefined and then replace that with the dynamic scope's global object. Rather, property lookup computes a Reference for the unqualified global property name used as the callee expression, and that Reference base is the exactly the global object in which the global property was found.
> 
> This is lexical not dynamic scope, in the caller evaluation context. It predates ES5 and it cannot be modeled with callee-based |this| rectification. It's why we did not "fix" https://bugzilla.mozilla.org/show_bug.cgi?id=634590 is Firefox 4.

And if the host callable object is invoked by a funny expression, e.g.

(1, hostCallable)();

and it's a built-in, then ES3 + reality would indeed pass null for |this| in the CallExpression semantics, and (here's where ES3 dropped the ball) the real-world implementations would fall back *not* on the dynamic scope's global object, but on hostCallable's global.

This relied on even built-ins and host callables having a link to their global, parallel to [[Scope]] for user-defined functions.

You can contrive a test case where the dynamic scope's global is not the same, by borrowing hostCallable from another window or frame.

This is still unspecified in ECMA-262 because we haven't specified multiple globals.

/be
Received on Thursday, 7 July 2011 18:16:06 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 8 May 2013 19:30:04 UTC