OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/ast/ast.h" | 5 #include "src/ast/ast.h" |
6 #include "src/messages.h" | 6 #include "src/messages.h" |
7 #include "src/parsing/parameter-initializer-rewriter.h" | 7 #include "src/parsing/parameter-initializer-rewriter.h" |
8 #include "src/parsing/parser.h" | 8 #include "src/parsing/parser.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 46 matching lines...) Loading... |
57 Variable* var = parser->Declare(declaration, descriptor_->declaration_kind, | 57 Variable* var = parser->Declare(declaration, descriptor_->declaration_kind, |
58 descriptor_->mode != VAR, ok_, | 58 descriptor_->mode != VAR, ok_, |
59 descriptor_->hoist_scope); | 59 descriptor_->hoist_scope); |
60 if (!*ok_) return; | 60 if (!*ok_) return; |
61 DCHECK_NOT_NULL(var); | 61 DCHECK_NOT_NULL(var); |
62 DCHECK(!proxy->is_resolved() || proxy->var() == var); | 62 DCHECK(!proxy->is_resolved() || proxy->var() == var); |
63 var->set_initializer_position(initializer_position_); | 63 var->set_initializer_position(initializer_position_); |
64 | 64 |
65 DCHECK(initializer_position_ != RelocInfo::kNoPosition); | 65 DCHECK(initializer_position_ != RelocInfo::kNoPosition); |
66 | 66 |
67 if (descriptor_->declaration_scope->num_var_or_const() > | 67 Scope* declaration_scope = IsLexicalVariableMode(descriptor_->mode) |
68 kMaxNumFunctionLocals) { | 68 ? descriptor_->scope |
| 69 : descriptor_->scope->DeclarationScope(); |
| 70 if (declaration_scope->num_var_or_const() > kMaxNumFunctionLocals) { |
69 parser->ReportMessage(MessageTemplate::kTooManyVariables); | 71 parser->ReportMessage(MessageTemplate::kTooManyVariables); |
70 *ok_ = false; | 72 *ok_ = false; |
71 return; | 73 return; |
72 } | 74 } |
73 if (names_) { | 75 if (names_) { |
74 names_->Add(name, zone()); | 76 names_->Add(name, zone()); |
75 } | 77 } |
76 | 78 |
77 // Initialize variables if needed. A | 79 // Initialize variables if needed. A |
78 // declaration of the form: | 80 // declaration of the form: |
(...skipping 14 matching lines...) Loading... |
93 // | 95 // |
94 // const c = x; | 96 // const c = x; |
95 // | 97 // |
96 // is *not* syntactic sugar for: | 98 // is *not* syntactic sugar for: |
97 // | 99 // |
98 // const c; c = x; | 100 // const c; c = x; |
99 // | 101 // |
100 // The "variable" c initialized to x is the same as the declared | 102 // The "variable" c initialized to x is the same as the declared |
101 // one - there is no re-lookup (see the last parameter of the | 103 // one - there is no re-lookup (see the last parameter of the |
102 // Declare() call above). | 104 // Declare() call above). |
103 Scope* initialization_scope = descriptor_->is_const | 105 Scope* initialization_scope = IsImmutableVariableMode(descriptor_->mode) |
104 ? descriptor_->declaration_scope | 106 ? declaration_scope |
105 : descriptor_->scope; | 107 : descriptor_->scope; |
106 | 108 |
107 | 109 |
108 // Global variable declarations must be compiled in a specific | 110 // Global variable declarations must be compiled in a specific |
109 // way. When the script containing the global variable declaration | 111 // way. When the script containing the global variable declaration |
110 // is entered, the global variable must be declared, so that if it | 112 // is entered, the global variable must be declared, so that if it |
111 // doesn't exist (on the global object itself, see ES5 errata) it | 113 // doesn't exist (on the global object itself, see ES5 errata) it |
112 // gets created with an initial undefined value. This is handled | 114 // gets created with an initial undefined value. This is handled |
113 // by the declarations part of the function representing the | 115 // by the declarations part of the function representing the |
114 // top-level global code; see Runtime::DeclareGlobalVariable. If | 116 // top-level global code; see Runtime::DeclareGlobalVariable. If |
(...skipping 13 matching lines...) Loading... |
128 // Compute the arguments for the runtime | 130 // Compute the arguments for the runtime |
129 // call.test-parsing/InitializedDeclarationsInStrictForOfError | 131 // call.test-parsing/InitializedDeclarationsInStrictForOfError |
130 ZoneList<Expression*>* arguments = | 132 ZoneList<Expression*>* arguments = |
131 new (zone()) ZoneList<Expression*>(3, zone()); | 133 new (zone()) ZoneList<Expression*>(3, zone()); |
132 // We have at least 1 parameter. | 134 // We have at least 1 parameter. |
133 arguments->Add( | 135 arguments->Add( |
134 factory()->NewStringLiteral(name, descriptor_->declaration_pos), | 136 factory()->NewStringLiteral(name, descriptor_->declaration_pos), |
135 zone()); | 137 zone()); |
136 CallRuntime* initialize; | 138 CallRuntime* initialize; |
137 | 139 |
138 if (descriptor_->is_const) { | 140 if (IsImmutableVariableMode(descriptor_->mode)) { |
139 arguments->Add(value, zone()); | 141 arguments->Add(value, zone()); |
140 value = NULL; // zap the value to avoid the unnecessary assignment | 142 value = NULL; // zap the value to avoid the unnecessary assignment |
141 | 143 |
142 // Construct the call to Runtime_InitializeConstGlobal | 144 // Construct the call to Runtime_InitializeConstGlobal |
143 // and add it to the initialization statement block. | 145 // and add it to the initialization statement block. |
144 // Note that the function does different things depending on | 146 // Note that the function does different things depending on |
145 // the number of arguments (1 or 2). | 147 // the number of arguments (1 or 2). |
146 initialize = | 148 initialize = |
147 factory()->NewCallRuntime(Runtime::kInitializeConstGlobal, arguments, | 149 factory()->NewCallRuntime(Runtime::kInitializeConstGlobal, arguments, |
148 descriptor_->initialization_pos); | 150 descriptor_->initialization_pos); |
(...skipping 277 matching lines...) Loading... |
426 NOT_A_PATTERN(TryFinallyStatement) | 428 NOT_A_PATTERN(TryFinallyStatement) |
427 NOT_A_PATTERN(UnaryOperation) | 429 NOT_A_PATTERN(UnaryOperation) |
428 NOT_A_PATTERN(VariableDeclaration) | 430 NOT_A_PATTERN(VariableDeclaration) |
429 NOT_A_PATTERN(WhileStatement) | 431 NOT_A_PATTERN(WhileStatement) |
430 NOT_A_PATTERN(WithStatement) | 432 NOT_A_PATTERN(WithStatement) |
431 NOT_A_PATTERN(Yield) | 433 NOT_A_PATTERN(Yield) |
432 | 434 |
433 #undef NOT_A_PATTERN | 435 #undef NOT_A_PATTERN |
434 } // namespace internal | 436 } // namespace internal |
435 } // namespace v8 | 437 } // namespace v8 |
OLD | NEW |