• keuchel@chromium.org's avatar
    Static resolution of outer variables in eval code. · 08c9629f
    keuchel@chromium.org authored
    So far free variables references in eval code are not statically
    resolved. For example in
        function foo() { var x = 1; eval("y = x"); }
    the variable x will get mode DYNAMIC and y will get mode DYNAMIC_GLOBAL,
    i.e. free variable references trigger dynamic lookups with a fast case
    handling for global variables.
    
    The CL introduces static resolution of free variables references in eval
    code. If possible variable references are resolved to bindings belonging to
    outer scopes of the eval call site.
    
    This is achieved by deserializing the outer scope chain using
    Scope::DeserializeScopeChain prior to parsing the eval code similar to lazy
    parsing of functions. The existing code for variable resolution is used,
    however resolution starts at the first outer unresolved scope instead of
    always starting at the root of the scope tree.
    
    This is a prerequisite for statically checking validity of assignments in
    the extended code as specified by the current ES.next draft which will be
    introduced by a subsequent CL. More specifically section 11.13 of revision 4
    of the ES.next draft reads:
    * It is a Syntax Error if the AssignmentExpression is contained in extended
      code and the LeftHandSideExpression is an Identifier that does not
      statically resolve to a declarative environment record binding or if the
      resolved binding is an immutable binding.
    
    TEST=existing tests in mjsunit
    
    Review URL: http://codereview.chromium.org/8508052
    
    git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9999 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
    08c9629f
scopes.h 21.9 KB