Aliased eval is handled in a special way. According to the specification it would be fine to completely disallow the use of aliased eval:
Paragraph 15.1.2.1 of ECMA-262: "If value of the eval property is used in any way other than a direct call (that is, other than by the explicit use of its name as an Identifier which is the MemberExpression in a CallExpression), or if the eval property is assigned to, an EvalError exception may be thrown." In practice, webpages rely on using eval so we do not disallow it. Instead, an aliased call to eval will evaluate the code in the global scope. JSC and V8 have the same behavior in this case. -- Mads On Wed, Sep 9, 2009 at 5:49 AM, Flier Lu<[email protected]> wrote: > > ECMA-262 define the with statement, which could add object to the > front of the scope chain. > > For example, the following statements will return 3, because 'a' was > defined in the with statement > >>with({a:1})eval("a+2") > 3 > > In the current v8 implementation (v1.3.9), if we use a alias of eval > method, the with statement doesn't work > >> var eval1=eval; with({b:1})eval1("b+2") > undefined:1: ReferenceError: b is not defined > b+2 > > I'm not sure whether it is ok base on design or just a implement > issue? > > 12.10 The with Statement > Syntax > WithStatement : > with ( Expression ) Statement > Description > The with statement adds a computed object to the front of the scope > chain of the current execution > context, then executes a statement with this augmented scope chain, > then restores the scope chain. > > Semantics > The production WithStatement : with ( Expression ) Statement is > evaluated as follows: > 1. Evaluate Expression. > 2. Call GetValue(Result(1)). > 3. Call ToObject(Result(2)). > 4. Add Result(3) to the front of the scope chain. > 5. Evaluate Statement using the augmented scope chain from step 4. > 6. Let C be Result(5). If an exception was thrown in step 5, let C be > (throw, V, empty), where V is the > exception. (Execution now proceeds as if no exception were thrown.) > 7. Remove Result(3) from the front of the scope chain. > 8. Return C. > NOTE > No matter how control leaves the embedded 'Statement', whether > normally or by some form of abrupt > completion or exception, the scope chain is always restored to its > former state12.10 The with Statement > Syntax > WithStatement : > with ( Expression ) Statement > Description > The with statement adds a computed object to the front of the scope > chain of the current execution > context, then executes a statement with this augmented scope chain, > then restores the scope chain. > > > --~--~---------~--~----~------------~-------~--~----~ v8-users mailing list [email protected] http://groups.google.com/group/v8-users -~----------~----~----~----~------~----~------~--~---
