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

Re: This binding and ES5 builtins

From: Oliver Hunt <oliver@apple.com>
Date: Thu, 07 Jul 2011 11:42:05 -0700
Cc: Luke Hoban <lukeh@microsoft.com>, "Mark S. Miller" <erights@google.com>, public-script-coord@w3.org, "es5-discuss@mozilla.org discussion" <es5-discuss@mozilla.org>
Message-id: <90A5FE8F-F0D6-4751-A553-0D1522A71474@apple.com>
To: Brendan Eich <brendan@mozilla.org>

On Jul 7, 2011, at 11:15 AM, Brendan Eich wrote:

> 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.

I believe in webkit tot we get this right for most cases now -- perhaps not Array.prototype.map, etc however for something like Array() we should get it "right"

> 
> 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.

Which is sad making.

> 
> /be
> 
> _______________________________________________
> es5-discuss mailing list
> es5-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es5-discuss
Received on Thursday, 7 July 2011 18:42:44 UTC

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