Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: src/parsing/parser-base.h

Issue 1700123003: [parser] unify metaproperty parsing and require unescaped property name (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: more oops Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/messages.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/scopes.h" 8 #include "src/ast/scopes.h"
9 #include "src/bailout-reason.h" 9 #include "src/bailout-reason.h"
10 #include "src/hashmap.h" 10 #include "src/hashmap.h"
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 return true; 447 return true;
448 } 448 }
449 return false; 449 return false;
450 } 450 }
451 451
452 bool PeekContextualKeyword(Vector<const char> keyword) { 452 bool PeekContextualKeyword(Vector<const char> keyword) {
453 return peek() == Token::IDENTIFIER && 453 return peek() == Token::IDENTIFIER &&
454 scanner()->is_next_contextual_keyword(keyword); 454 scanner()->is_next_contextual_keyword(keyword);
455 } 455 }
456 456
457 void ExpectMetaProperty(Vector<const char> property_name,
458 const char* full_name, int pos, bool* ok);
459
457 void ExpectContextualKeyword(Vector<const char> keyword, bool* ok) { 460 void ExpectContextualKeyword(Vector<const char> keyword, bool* ok) {
458 Expect(Token::IDENTIFIER, ok); 461 Expect(Token::IDENTIFIER, ok);
459 if (!*ok) return; 462 if (!*ok) return;
460 if (!scanner()->is_literal_contextual_keyword(keyword)) { 463 if (!scanner()->is_literal_contextual_keyword(keyword)) {
461 ReportUnexpectedToken(scanner()->current_token()); 464 ReportUnexpectedToken(scanner()->current_token());
462 *ok = false; 465 *ok = false;
463 } 466 }
464 } 467 }
465 468
466 bool CheckInOrOf(ForEachStatement::VisitMode* visit_mode, bool* ok) { 469 bool CheckInOrOf(ForEachStatement::VisitMode* visit_mode, bool* ok) {
(...skipping 2066 matching lines...) Expand 10 before | Expand all | Expand 10 after
2533 2536
2534 // Parse the initial primary or function expression. 2537 // Parse the initial primary or function expression.
2535 ExpressionT result = this->EmptyExpression(); 2538 ExpressionT result = this->EmptyExpression();
2536 if (peek() == Token::FUNCTION) { 2539 if (peek() == Token::FUNCTION) {
2537 BindingPatternUnexpectedToken(classifier); 2540 BindingPatternUnexpectedToken(classifier);
2538 ArrowFormalParametersUnexpectedToken(classifier); 2541 ArrowFormalParametersUnexpectedToken(classifier);
2539 2542
2540 Consume(Token::FUNCTION); 2543 Consume(Token::FUNCTION);
2541 int function_token_position = position(); 2544 int function_token_position = position();
2542 2545
2543 if (FLAG_harmony_function_sent && Check(Token::PERIOD)) { 2546 if (FLAG_harmony_function_sent && peek() == Token::PERIOD) {
2544 // function.sent 2547 // function.sent
2545
2546 int pos = position(); 2548 int pos = position();
2547 ExpectContextualKeyword(CStrVector("sent"), CHECK_OK); 2549 ExpectMetaProperty(CStrVector("sent"), "function.sent", pos, CHECK_OK);
2548 2550
2549 if (!is_generator()) { 2551 if (!is_generator()) {
2550 // TODO(neis): allow escaping into closures? 2552 // TODO(neis): allow escaping into closures?
2551 ReportMessageAt(scanner()->location(), 2553 ReportMessageAt(scanner()->location(),
2552 MessageTemplate::kUnexpectedFunctionSent); 2554 MessageTemplate::kUnexpectedFunctionSent);
2553 *ok = false; 2555 *ok = false;
2554 return this->EmptyExpression(); 2556 return this->EmptyExpression();
2555 } 2557 }
2556 2558
2557 return this->FunctionSentExpression(scope_, factory(), pos); 2559 return this->FunctionSentExpression(scope_, factory(), pos);
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
2762 function_state_->set_super_location(scanner()->location()); 2764 function_state_->set_super_location(scanner()->location());
2763 return this->SuperCallReference(scope_, factory(), pos); 2765 return this->SuperCallReference(scope_, factory(), pos);
2764 } 2766 }
2765 } 2767 }
2766 2768
2767 ReportMessageAt(scanner()->location(), MessageTemplate::kUnexpectedSuper); 2769 ReportMessageAt(scanner()->location(), MessageTemplate::kUnexpectedSuper);
2768 *ok = false; 2770 *ok = false;
2769 return this->EmptyExpression(); 2771 return this->EmptyExpression();
2770 } 2772 }
2771 2773
2774 template <class Traits>
2775 void ParserBase<Traits>::ExpectMetaProperty(Vector<const char> property_name,
2776 const char* full_name, int pos,
2777 bool* ok) {
2778 Consume(Token::PERIOD);
2779 ExpectContextualKeyword(property_name, ok);
2780 if (!*ok) return;
2781 if (scanner()->literal_contains_escapes()) {
2782 Traits::ReportMessageAt(
2783 Scanner::Location(pos, scanner()->location().end_pos),
2784 MessageTemplate::kInvalidEscapedMetaProperty, full_name);
2785 *ok = false;
2786 }
2787 }
2772 2788
2773 template <class Traits> 2789 template <class Traits>
2774 typename ParserBase<Traits>::ExpressionT 2790 typename ParserBase<Traits>::ExpressionT
2775 ParserBase<Traits>::ParseNewTargetExpression(bool* ok) { 2791 ParserBase<Traits>::ParseNewTargetExpression(bool* ok) {
2776 int pos = position(); 2792 int pos = position();
2777 Consume(Token::PERIOD); 2793 ExpectMetaProperty(CStrVector("target"), "new.target", pos, CHECK_OK);
2778 ExpectContextualKeyword(CStrVector("target"), CHECK_OK);
2779 2794
2780 if (!scope_->ReceiverScope()->is_function_scope()) { 2795 if (!scope_->ReceiverScope()->is_function_scope()) {
2781 ReportMessageAt(scanner()->location(), 2796 ReportMessageAt(scanner()->location(),
2782 MessageTemplate::kUnexpectedNewTarget); 2797 MessageTemplate::kUnexpectedNewTarget);
2783 *ok = false; 2798 *ok = false;
2784 return this->EmptyExpression(); 2799 return this->EmptyExpression();
2785 } 2800 }
2786 2801
2787 return this->NewTargetExpression(scope_, factory(), pos); 2802 return this->NewTargetExpression(scope_, factory(), pos);
2788 } 2803 }
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
3345 return; 3360 return;
3346 } 3361 }
3347 has_seen_constructor_ = true; 3362 has_seen_constructor_ = true;
3348 return; 3363 return;
3349 } 3364 }
3350 } 3365 }
3351 } // namespace internal 3366 } // namespace internal
3352 } // namespace v8 3367 } // namespace v8
3353 3368
3354 #endif // V8_PARSING_PARSER_BASE_H 3369 #endif // V8_PARSING_PARSER_BASE_H
OLDNEW
« no previous file with comments | « src/messages.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698