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 #ifndef V8_PARSING_PARSER_BASE_H | 5 #ifndef V8_PARSING_PARSER_BASE_H |
6 #define V8_PARSING_PARSER_BASE_H | 6 #define V8_PARSING_PARSER_BASE_H |
7 | 7 |
8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/ast/scopes.h" | 9 #include "src/ast/scopes.h" |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
(...skipping 1329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1340 impl()->IsEvalOrArguments(impl()->AsIdentifier(expression))) { | 1340 impl()->IsEvalOrArguments(impl()->AsIdentifier(expression))) { |
1341 return false; | 1341 return false; |
1342 } | 1342 } |
1343 return true; | 1343 return true; |
1344 } | 1344 } |
1345 | 1345 |
1346 bool IsValidPattern(ExpressionT expression) { | 1346 bool IsValidPattern(ExpressionT expression) { |
1347 return expression->IsObjectLiteral() || expression->IsArrayLiteral(); | 1347 return expression->IsObjectLiteral() || expression->IsArrayLiteral(); |
1348 } | 1348 } |
1349 | 1349 |
1350 // Due to hoisting, the value of a 'var'-declared variable may actually change | |
1351 // even if the code contains only the "initial" assignment, namely when that | |
1352 // assignment occurs inside a loop. For example: | |
1353 // | |
1354 // let i = 10; | |
1355 // do { var x = i } while (i--): | |
1356 // | |
1357 // As a simple and very conservative approximation of this, we explicitly mark | |
1358 // as maybe-assigned any non-lexical variable whose initializing "declaration" | |
1359 // does not syntactically occur in the function scope. (In the example above, | |
1360 // it occurs in a block scope.) | |
1361 // | |
1362 // Note that non-lexical variables include temporaries, which may also get | |
1363 // assigned inside a loop due to the various rewritings that the parser | |
1364 // performs. | |
1365 // | |
1366 static void MarkLoopVariableAsAssigned(Scope* scope, Variable* var); | |
1367 | |
1368 // Keep track of eval() calls since they disable all local variable | 1350 // Keep track of eval() calls since they disable all local variable |
1369 // optimizations. This checks if expression is an eval call, and if yes, | 1351 // optimizations. This checks if expression is an eval call, and if yes, |
1370 // forwards the information to scope. | 1352 // forwards the information to scope. |
1371 Call::PossiblyEval CheckPossibleEvalCall(ExpressionT expression, | 1353 Call::PossiblyEval CheckPossibleEvalCall(ExpressionT expression, |
1372 Scope* scope) { | 1354 Scope* scope) { |
1373 if (impl()->IsIdentifier(expression) && | 1355 if (impl()->IsIdentifier(expression) && |
1374 impl()->IsEval(impl()->AsIdentifier(expression))) { | 1356 impl()->IsEval(impl()->AsIdentifier(expression))) { |
1375 scope->RecordEvalCall(); | 1357 scope->RecordEvalCall(); |
1376 if (is_sloppy(scope->language_mode())) { | 1358 if (is_sloppy(scope->language_mode())) { |
1377 // For sloppy scopes we also have to record the call at function level, | 1359 // For sloppy scopes we also have to record the call at function level, |
(...skipping 4331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5709 block->statements()->Add(loop, zone()); | 5691 block->statements()->Add(loop, zone()); |
5710 block->set_scope(for_scope); | 5692 block->set_scope(for_scope); |
5711 loop->Initialize(init, cond, next, body); | 5693 loop->Initialize(init, cond, next, body); |
5712 return block; | 5694 return block; |
5713 } | 5695 } |
5714 | 5696 |
5715 loop->Initialize(init, cond, next, body); | 5697 loop->Initialize(init, cond, next, body); |
5716 return loop; | 5698 return loop; |
5717 } | 5699 } |
5718 | 5700 |
5719 template <typename Impl> | 5701 #undef CHECK_OK |
5720 void ParserBase<Impl>::MarkLoopVariableAsAssigned(Scope* scope, Variable* var) { | 5702 #undef CHECK_OK_CUSTOM |
5721 if (!IsLexicalVariableMode(var->mode()) && !scope->is_function_scope()) { | |
5722 var->set_maybe_assigned(); | |
5723 } | |
5724 } | |
5725 | 5703 |
5726 template <typename Impl> | 5704 template <typename Impl> |
5727 void ParserBase<Impl>::ObjectLiteralChecker::CheckDuplicateProto( | 5705 void ParserBase<Impl>::ObjectLiteralChecker::CheckDuplicateProto( |
5728 Token::Value property) { | 5706 Token::Value property) { |
5729 if (property == Token::SMI || property == Token::NUMBER) return; | 5707 if (property == Token::SMI || property == Token::NUMBER) return; |
5730 | 5708 |
5731 if (IsProto()) { | 5709 if (IsProto()) { |
5732 if (has_seen_proto_) { | 5710 if (has_seen_proto_) { |
5733 this->parser()->classifier()->RecordExpressionError( | 5711 this->parser()->classifier()->RecordExpressionError( |
5734 this->scanner()->location(), MessageTemplate::kDuplicateProto); | 5712 this->scanner()->location(), MessageTemplate::kDuplicateProto); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5766 if (has_seen_constructor_) { | 5744 if (has_seen_constructor_) { |
5767 this->parser()->ReportMessage(MessageTemplate::kDuplicateConstructor); | 5745 this->parser()->ReportMessage(MessageTemplate::kDuplicateConstructor); |
5768 *ok = false; | 5746 *ok = false; |
5769 return; | 5747 return; |
5770 } | 5748 } |
5771 has_seen_constructor_ = true; | 5749 has_seen_constructor_ = true; |
5772 return; | 5750 return; |
5773 } | 5751 } |
5774 } | 5752 } |
5775 | 5753 |
5776 #undef CHECK_OK | |
5777 #undef CHECK_OK_CUSTOM | |
5778 #undef CHECK_OK_VOID | 5754 #undef CHECK_OK_VOID |
5779 | 5755 |
5780 } // namespace internal | 5756 } // namespace internal |
5781 } // namespace v8 | 5757 } // namespace v8 |
5782 | 5758 |
5783 #endif // V8_PARSING_PARSER_BASE_H | 5759 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |