On Jul 2, 2008, at 3:44 PM, Norris Boyd wrote:

> I should explain why limitation on calling eval by another name is in
> the spec. It turns out it is due to Rhino...

Wow :-)

> One of the biggest sources of efficiency in compiling JS to bytecode
> on the JVM is to avoid creating an activation object.

Right, 'cause then you can just use method local variable slots for  
them.

> (An activation
> object is an object representing the function level-scope; all
> variables of the function are represented as properties of the
> activation object.) Certain language features in JavaScript can't be
> implemented without an activation object, and eval is one of them.

Yep.

> But consider the following:
>
> js> function f() {
>>  g("var x = 5;");
>>  return x;
>> }
> js> var g = eval
>
> When compiling f(), Rhino *has no way to know that g could be eval*.
> So if we supported calling eval by a function of another name, Rhino
> would never be able to avoid creating the activation object for any
> function that calls another function. So Rhino handles calls to "eval"
> differently than calls to other function names. We were building Rhino
> at the time the ECMA spec was being finalized, and asked that this
> special wording be put into the spec specifically so implementations
> like Rhino could compile more efficiently.

Right place, right time, eh? I was beginning to wonder, actually, when  
John said only Rhino implements this optional restriction :-)

> So what do we do in this case? It seems like we could extend Rhino to
> handle eval.call specially, much like eval is handled specially. That
> seems like a reasonable approach; would it solve your problem?

Don't want to speak in John's name, but I think it would. eval.call  
and eval.apply would help him achieve what he wanted, and we could  
still keep the optimization. It's aliasing the eval that'd make the  
optimization impossible...

Attila.
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to