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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/ast.h" | 8 #include "src/ast.h" |
9 #include "src/base/platform/platform.h" | 9 #include "src/base/platform/platform.h" |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 1671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1682 // Note that we always add an unresolved proxy even if it's not | 1682 // Note that we always add an unresolved proxy even if it's not |
1683 // used, simply because we don't know in this method (w/o extra | 1683 // used, simply because we don't know in this method (w/o extra |
1684 // parameters) if the proxy is needed or not. The proxy will be | 1684 // parameters) if the proxy is needed or not. The proxy will be |
1685 // bound during variable resolution time unless it was pre-bound | 1685 // bound during variable resolution time unless it was pre-bound |
1686 // below. | 1686 // below. |
1687 // | 1687 // |
1688 // WARNING: This will lead to multiple declaration nodes for the | 1688 // WARNING: This will lead to multiple declaration nodes for the |
1689 // same variable if it is declared several times. This is not a | 1689 // same variable if it is declared several times. This is not a |
1690 // semantic issue as long as we keep the source order, but it may be | 1690 // semantic issue as long as we keep the source order, but it may be |
1691 // a performance issue since it may lead to repeated | 1691 // a performance issue since it may lead to repeated |
1692 // RuntimeHidden_DeclareContextSlot calls. | 1692 // RuntimeHidden_DeclareLookupSlot calls. |
1693 declaration_scope->AddDeclaration(declaration); | 1693 declaration_scope->AddDeclaration(declaration); |
1694 | 1694 |
1695 if (mode == CONST_LEGACY && declaration_scope->is_global_scope()) { | 1695 if (mode == CONST_LEGACY && declaration_scope->is_global_scope()) { |
1696 // For global const variables we bind the proxy to a variable. | 1696 // For global const variables we bind the proxy to a variable. |
1697 ASSERT(resolve); // should be set by all callers | 1697 ASSERT(resolve); // should be set by all callers |
1698 Variable::Kind kind = Variable::NORMAL; | 1698 Variable::Kind kind = Variable::NORMAL; |
1699 var = new(zone()) Variable( | 1699 var = new(zone()) Variable( |
1700 declaration_scope, name, mode, true, kind, | 1700 declaration_scope, name, mode, true, kind, |
1701 kNeedsInitialization, proxy->interface()); | 1701 kNeedsInitialization, proxy->interface()); |
1702 } else if (declaration_scope->is_eval_scope() && | 1702 } else if (declaration_scope->is_eval_scope() && |
1703 declaration_scope->strict_mode() == SLOPPY) { | 1703 declaration_scope->strict_mode() == SLOPPY) { |
1704 // For variable declarations in a sloppy eval scope the proxy is bound | 1704 // For variable declarations in a sloppy eval scope the proxy is bound |
1705 // to a lookup variable to force a dynamic declaration using the | 1705 // to a lookup variable to force a dynamic declaration using the |
1706 // DeclareContextSlot runtime function. | 1706 // DeclareLookupSlot runtime function. |
1707 Variable::Kind kind = Variable::NORMAL; | 1707 Variable::Kind kind = Variable::NORMAL; |
1708 var = new(zone()) Variable( | 1708 var = new(zone()) Variable( |
1709 declaration_scope, name, mode, true, kind, | 1709 declaration_scope, name, mode, true, kind, |
1710 declaration->initialization(), proxy->interface()); | 1710 declaration->initialization(), proxy->interface()); |
1711 var->AllocateTo(Variable::LOOKUP, -1); | 1711 var->AllocateTo(Variable::LOOKUP, -1); |
1712 resolve = true; | 1712 resolve = true; |
1713 } | 1713 } |
1714 | 1714 |
1715 // If requested and we have a local variable, bind the proxy to the variable | 1715 // If requested and we have a local variable, bind the proxy to the variable |
1716 // at parse-time. This is used for functions (and consts) declared inside | 1716 // at parse-time. This is used for functions (and consts) declared inside |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2179 StrictMode strict_mode = initialization_scope->strict_mode(); | 2179 StrictMode strict_mode = initialization_scope->strict_mode(); |
2180 arguments->Add(factory()->NewNumberLiteral(strict_mode, pos), zone()); | 2180 arguments->Add(factory()->NewNumberLiteral(strict_mode, pos), zone()); |
2181 | 2181 |
2182 // Be careful not to assign a value to the global variable if | 2182 // Be careful not to assign a value to the global variable if |
2183 // we're in a with. The initialization value should not | 2183 // we're in a with. The initialization value should not |
2184 // necessarily be stored in the global object in that case, | 2184 // necessarily be stored in the global object in that case, |
2185 // which is why we need to generate a separate assignment node. | 2185 // which is why we need to generate a separate assignment node. |
2186 if (value != NULL && !inside_with()) { | 2186 if (value != NULL && !inside_with()) { |
2187 arguments->Add(value, zone()); | 2187 arguments->Add(value, zone()); |
2188 value = NULL; // zap the value to avoid the unnecessary assignment | 2188 value = NULL; // zap the value to avoid the unnecessary assignment |
| 2189 // Construct the call to Runtime_InitializeVarGlobal |
| 2190 // and add it to the initialization statement block. |
| 2191 initialize = factory()->NewCallRuntime( |
| 2192 ast_value_factory_->initialize_var_global_string(), |
| 2193 Runtime::FunctionForId(Runtime::kInitializeVarGlobal), arguments, |
| 2194 pos); |
| 2195 } else { |
| 2196 initialize = NULL; |
2189 } | 2197 } |
2190 | |
2191 // Construct the call to Runtime_InitializeVarGlobal | |
2192 // and add it to the initialization statement block. | |
2193 // Note that the function does different things depending on | |
2194 // the number of arguments (2 or 3). | |
2195 initialize = factory()->NewCallRuntime( | |
2196 ast_value_factory_->initialize_var_global_string(), | |
2197 Runtime::FunctionForId(Runtime::kInitializeVarGlobal), | |
2198 arguments, pos); | |
2199 } | 2198 } |
2200 | 2199 |
2201 block->AddStatement( | 2200 if (initialize != NULL) { |
2202 factory()->NewExpressionStatement(initialize, RelocInfo::kNoPosition), | 2201 block->AddStatement(factory()->NewExpressionStatement( |
2203 zone()); | 2202 initialize, RelocInfo::kNoPosition), |
| 2203 zone()); |
| 2204 } |
2204 } else if (needs_init) { | 2205 } else if (needs_init) { |
2205 // Constant initializations always assign to the declared constant which | 2206 // Constant initializations always assign to the declared constant which |
2206 // is always at the function scope level. This is only relevant for | 2207 // is always at the function scope level. This is only relevant for |
2207 // dynamically looked-up variables and constants (the start context for | 2208 // dynamically looked-up variables and constants (the start context for |
2208 // constant lookups is always the function context, while it is the top | 2209 // constant lookups is always the function context, while it is the top |
2209 // context for var declared variables). Sigh... | 2210 // context for var declared variables). Sigh... |
2210 // For 'let' and 'const' declared variables in harmony mode the | 2211 // For 'let' and 'const' declared variables in harmony mode the |
2211 // initialization also always assigns to the declared variable. | 2212 // initialization also always assigns to the declared variable. |
2212 ASSERT(proxy != NULL); | 2213 ASSERT(proxy != NULL); |
2213 ASSERT(proxy->var() != NULL); | 2214 ASSERT(proxy->var() != NULL); |
(...skipping 2577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4791 info()->SetAstValueFactory(ast_value_factory_); | 4792 info()->SetAstValueFactory(ast_value_factory_); |
4792 } | 4793 } |
4793 ast_value_factory_ = NULL; | 4794 ast_value_factory_ = NULL; |
4794 | 4795 |
4795 InternalizeUseCounts(); | 4796 InternalizeUseCounts(); |
4796 | 4797 |
4797 return (result != NULL); | 4798 return (result != NULL); |
4798 } | 4799 } |
4799 | 4800 |
4800 } } // namespace v8::internal | 4801 } } // namespace v8::internal |
OLD | NEW |