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