| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
| 6 | 6 |
| 7 #include "src/api.h" | 7 #include "src/api.h" |
| 8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
| 9 #include "src/ast/ast-expression-rewriter.h" | 9 #include "src/ast/ast-expression-rewriter.h" |
| 10 #include "src/ast/ast-expression-visitor.h" | 10 #include "src/ast/ast-expression-visitor.h" |
| (...skipping 2007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2018 } | 2018 } |
| 2019 } else if (mode == VAR) { | 2019 } else if (mode == VAR) { |
| 2020 var->set_maybe_assigned(); | 2020 var->set_maybe_assigned(); |
| 2021 } | 2021 } |
| 2022 } else if (declaration_scope->is_eval_scope() && | 2022 } else if (declaration_scope->is_eval_scope() && |
| 2023 is_sloppy(declaration_scope->language_mode()) && | 2023 is_sloppy(declaration_scope->language_mode()) && |
| 2024 !IsLexicalVariableMode(mode)) { | 2024 !IsLexicalVariableMode(mode)) { |
| 2025 // In a var binding in a sloppy direct eval, pollute the enclosing scope | 2025 // In a var binding in a sloppy direct eval, pollute the enclosing scope |
| 2026 // with this new binding by doing the following: | 2026 // with this new binding by doing the following: |
| 2027 // The proxy is bound to a lookup variable to force a dynamic declaration | 2027 // The proxy is bound to a lookup variable to force a dynamic declaration |
| 2028 // using the DeclareLookupSlot runtime function. | 2028 // using the DeclareEvalVar or DeclareEvalFunction runtime functions. |
| 2029 Variable::Kind kind = Variable::NORMAL; | 2029 Variable::Kind kind = Variable::NORMAL; |
| 2030 // TODO(sigurds) figure out if kNotAssigned is OK here | 2030 // TODO(sigurds) figure out if kNotAssigned is OK here |
| 2031 var = new (zone()) Variable(declaration_scope, name, mode, kind, | 2031 var = new (zone()) Variable(declaration_scope, name, mode, kind, |
| 2032 declaration->initialization(), kNotAssigned); | 2032 declaration->initialization(), kNotAssigned); |
| 2033 var->AllocateTo(VariableLocation::LOOKUP, -1); | 2033 var->AllocateTo(VariableLocation::LOOKUP, -1); |
| 2034 var->SetFromEval(); | |
| 2035 resolve = true; | 2034 resolve = true; |
| 2036 } | 2035 } |
| 2037 | 2036 |
| 2038 | 2037 |
| 2039 // We add a declaration node for every declaration. The compiler | 2038 // We add a declaration node for every declaration. The compiler |
| 2040 // will only generate code if necessary. In particular, declarations | 2039 // will only generate code if necessary. In particular, declarations |
| 2041 // for inner local variables that do not represent functions won't | 2040 // for inner local variables that do not represent functions won't |
| 2042 // result in any generated code. | 2041 // result in any generated code. |
| 2043 // | 2042 // |
| 2044 // Note that we always add an unresolved proxy even if it's not | 2043 // Note that we always add an unresolved proxy even if it's not |
| 2045 // used, simply because we don't know in this method (w/o extra | 2044 // used, simply because we don't know in this method (w/o extra |
| 2046 // parameters) if the proxy is needed or not. The proxy will be | 2045 // parameters) if the proxy is needed or not. The proxy will be |
| 2047 // bound during variable resolution time unless it was pre-bound | 2046 // bound during variable resolution time unless it was pre-bound |
| 2048 // below. | 2047 // below. |
| 2049 // | 2048 // |
| 2050 // WARNING: This will lead to multiple declaration nodes for the | 2049 // WARNING: This will lead to multiple declaration nodes for the |
| 2051 // same variable if it is declared several times. This is not a | 2050 // same variable if it is declared several times. This is not a |
| 2052 // semantic issue as long as we keep the source order, but it may be | 2051 // semantic issue as long as we keep the source order, but it may be |
| 2053 // a performance issue since it may lead to repeated | 2052 // a performance issue since it may lead to repeated |
| 2054 // RuntimeHidden_DeclareLookupSlot calls. | 2053 // DeclareEvalVar or DeclareEvalFunction calls. |
| 2055 declaration_scope->AddDeclaration(declaration); | 2054 declaration_scope->AddDeclaration(declaration); |
| 2056 | 2055 |
| 2057 // If requested and we have a local variable, bind the proxy to the variable | 2056 // If requested and we have a local variable, bind the proxy to the variable |
| 2058 // at parse-time. This is used for functions (and consts) declared inside | 2057 // at parse-time. This is used for functions (and consts) declared inside |
| 2059 // statements: the corresponding function (or const) variable must be in the | 2058 // statements: the corresponding function (or const) variable must be in the |
| 2060 // function scope and not a statement-local scope, e.g. as provided with a | 2059 // function scope and not a statement-local scope, e.g. as provided with a |
| 2061 // 'with' statement: | 2060 // 'with' statement: |
| 2062 // | 2061 // |
| 2063 // with (obj) { | 2062 // with (obj) { |
| 2064 // function f() {} | 2063 // function f() {} |
| (...skipping 4908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6973 try_block, target); | 6972 try_block, target); |
| 6974 final_loop = target; | 6973 final_loop = target; |
| 6975 } | 6974 } |
| 6976 | 6975 |
| 6977 return final_loop; | 6976 return final_loop; |
| 6978 } | 6977 } |
| 6979 | 6978 |
| 6980 | 6979 |
| 6981 } // namespace internal | 6980 } // namespace internal |
| 6982 } // namespace v8 | 6981 } // namespace v8 |
| OLD | NEW |