On May 1, 2010, at 3:25 PM, Brendan Eich wrote:

> On May 1, 2010, at 1:40 PM, Oliver Hunt wrote:
> 
>> On May 1, 2010, at 1:27 PM, Brendan Eich wrote:
>>>> A simple solution that would allow maintaining the
>>>> above mentioned 'invariant' in most cases and allow breaking it when
>>>> necessary would involve a flag passed into the 'get' handler
>>>> indicating that the property is about to be 'called'.  What would be
>>>> the negative ramifications of such a solution (asides from the fact
>>>> that it may get abused - like the 'get' accessor in es5 ;)?
>>> 
>>> This is a good idea. In all practical implementations, callee expressions 
>>> are specialized so the "get" can tell it is computing a callee. This is 
>>> done to bind |this| in the call expression of which the callee expression 
>>> is a left prefix.
>> 
>> [[Get]] in JavaScriptCore does not distinguish the get for a.b vs a.b(), i 
>> like to imagine that we count as being a practical implementation ;)
> 
> My mistake, I thought JSC did. How do you compute |this| for the call? I 
> mean, |this| binds to whatever |a| evaluated to, and it evaluates only once, 
> so *something* differs in how you compile a.b in an expression such as (x = 
> a.b) or (a.b + c.d) vs. how you compile a.b in a.b().

We copy |this| in advance.  For reference here is the bytecode representation 
for the function:
function f(){
    var a;
    a.b;
}
3 m_instructions; 1 parameter(s); 2 callee register(s)
[   0] enter
[   1] get_by_id         r1, r0, b(@id0)
[   9] ret               undefined(@k0)

(I'm assuming this is sufficiently obvious to not require any real explanation)

Here's 
function f() {
    var a;
    a.b();
}
5 m_instructions; 1 parameter(s); 11 callee register(s)

[   0] enter
[   1] mov               r2, r0
copy the variable a from r0 to r2
[   4] get_by_id         r1, r2, b(@id0)
resolve a.b -> r1
[  12] call              r1, r1, 1, 11
Call r1 -- this will be in r2, the instruction arguments are somewhat 
"interesting" so i won't go into details as to what they mean
[  17] ret               undefined(@k0)

As you can see there's no difference between how we do the property resolution 
for an ordinary lookup vs. a function call.

--Oliver

> 
> /be

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to