Chromium Code Reviews| 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 "declaration" does not | |
|
marja
2017/02/06 21:08:43
Confused by this comment + the comment about prepa
| |
| 1359 // syntactically occur in the function scope. (In the example above, it | |
| 1360 // 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 | |
| 1350 // Keep track of eval() calls since they disable all local variable | 1368 // Keep track of eval() calls since they disable all local variable |
| 1351 // optimizations. This checks if expression is an eval call, and if yes, | 1369 // optimizations. This checks if expression is an eval call, and if yes, |
| 1352 // forwards the information to scope. | 1370 // forwards the information to scope. |
| 1353 Call::PossiblyEval CheckPossibleEvalCall(ExpressionT expression, | 1371 Call::PossiblyEval CheckPossibleEvalCall(ExpressionT expression, |
| 1354 Scope* scope) { | 1372 Scope* scope) { |
| 1355 if (impl()->IsIdentifier(expression) && | 1373 if (impl()->IsIdentifier(expression) && |
| 1356 impl()->IsEval(impl()->AsIdentifier(expression))) { | 1374 impl()->IsEval(impl()->AsIdentifier(expression))) { |
| 1357 scope->RecordEvalCall(); | 1375 scope->RecordEvalCall(); |
| 1358 if (is_sloppy(scope->language_mode())) { | 1376 if (is_sloppy(scope->language_mode())) { |
| 1359 // For sloppy scopes we also have to record the call at function level, | 1377 // For sloppy scopes we also have to record the call at function level, |
| (...skipping 4332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5692 block->statements()->Add(loop, zone()); | 5710 block->statements()->Add(loop, zone()); |
| 5693 block->set_scope(for_scope); | 5711 block->set_scope(for_scope); |
| 5694 loop->Initialize(init, cond, next, body); | 5712 loop->Initialize(init, cond, next, body); |
| 5695 return block; | 5713 return block; |
| 5696 } | 5714 } |
| 5697 | 5715 |
| 5698 loop->Initialize(init, cond, next, body); | 5716 loop->Initialize(init, cond, next, body); |
| 5699 return loop; | 5717 return loop; |
| 5700 } | 5718 } |
| 5701 | 5719 |
| 5702 #undef CHECK_OK | 5720 template <typename Impl> |
| 5703 #undef CHECK_OK_CUSTOM | 5721 void ParserBase<Impl>::MarkLoopVariableAsAssigned(Scope* scope, Variable* var) { |
| 5722 if (!IsLexicalVariableMode(var->mode()) && !scope->is_function_scope()) { | |
| 5723 var->set_maybe_assigned(); | |
| 5724 } | |
| 5725 } | |
| 5704 | 5726 |
| 5705 template <typename Impl> | 5727 template <typename Impl> |
| 5706 void ParserBase<Impl>::ObjectLiteralChecker::CheckDuplicateProto( | 5728 void ParserBase<Impl>::ObjectLiteralChecker::CheckDuplicateProto( |
| 5707 Token::Value property) { | 5729 Token::Value property) { |
| 5708 if (property == Token::SMI || property == Token::NUMBER) return; | 5730 if (property == Token::SMI || property == Token::NUMBER) return; |
| 5709 | 5731 |
| 5710 if (IsProto()) { | 5732 if (IsProto()) { |
| 5711 if (has_seen_proto_) { | 5733 if (has_seen_proto_) { |
| 5712 this->parser()->classifier()->RecordExpressionError( | 5734 this->parser()->classifier()->RecordExpressionError( |
| 5713 this->scanner()->location(), MessageTemplate::kDuplicateProto); | 5735 this->scanner()->location(), MessageTemplate::kDuplicateProto); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5745 if (has_seen_constructor_) { | 5767 if (has_seen_constructor_) { |
| 5746 this->parser()->ReportMessage(MessageTemplate::kDuplicateConstructor); | 5768 this->parser()->ReportMessage(MessageTemplate::kDuplicateConstructor); |
| 5747 *ok = false; | 5769 *ok = false; |
| 5748 return; | 5770 return; |
| 5749 } | 5771 } |
| 5750 has_seen_constructor_ = true; | 5772 has_seen_constructor_ = true; |
| 5751 return; | 5773 return; |
| 5752 } | 5774 } |
| 5753 } | 5775 } |
| 5754 | 5776 |
| 5777 #undef CHECK_OK | |
| 5778 #undef CHECK_OK_CUSTOM | |
| 5755 #undef CHECK_OK_VOID | 5779 #undef CHECK_OK_VOID |
| 5756 | 5780 |
| 5757 } // namespace internal | 5781 } // namespace internal |
| 5758 } // namespace v8 | 5782 } // namespace v8 |
| 5759 | 5783 |
| 5760 #endif // V8_PARSING_PARSER_BASE_H | 5784 #endif // V8_PARSING_PARSER_BASE_H |
| OLD | NEW |