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

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: 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/message/function-sent-escaped.js » ('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 int ExpectMetaProperty(Vector<const char> keyword, const char* full,
adamk 2016/02/16 20:52:09 Some nits on argument names: this should be "prope
caitp (gmail) 2016/02/16 22:13:55 Done.
458 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 2548 int pos =
2546 int pos = position(); 2549 ExpectMetaProperty(CStrVector("sent"), "function.sent", CHECK_OK);
2547 ExpectContextualKeyword(CStrVector("sent"), 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 int ParserBase<Traits>::ExpectMetaProperty(Vector<const char> keyword,
adamk 2016/02/16 20:52:09 Returning a position isn't something we do elsewhe
caitp (gmail) 2016/02/16 22:13:55 Done.
2776 const char* full, bool* ok) {
2777 int pos = position();
2778 if (*ok) {
adamk 2016/02/16 20:52:09 I don't think should ever be false, so this if sta
caitp (gmail) 2016/02/16 22:13:55 Done.
2779 Consume(Token::PERIOD);
2780 ExpectContextualKeyword(keyword, ok);
2781 if (!*ok) return pos;
2782 if (scanner()->literal_contains_escapes()) {
2783 Traits::ReportMessageAt(
2784 Scanner::Location(pos, scanner()->location().end_pos),
2785 MessageTemplate::kInvalidEscapedMetaProperty, full, kSyntaxError);
adamk 2016/02/16 20:52:09 kSyntaxError is the default
caitp (gmail) 2016/02/16 22:13:55 Done.
2786 *ok = false;
2787 }
2788 }
2789 return pos;
2790 }
2772 2791
2773 template <class Traits> 2792 template <class Traits>
2774 typename ParserBase<Traits>::ExpressionT 2793 typename ParserBase<Traits>::ExpressionT
2775 ParserBase<Traits>::ParseNewTargetExpression(bool* ok) { 2794 ParserBase<Traits>::ParseNewTargetExpression(bool* ok) {
2776 int pos = position(); 2795 int pos = ExpectMetaProperty(CStrVector("target"), "new.target", CHECK_OK);
2777 Consume(Token::PERIOD);
2778 ExpectContextualKeyword(CStrVector("target"), CHECK_OK);
2779 2796
2780 if (!scope_->ReceiverScope()->is_function_scope()) { 2797 if (!scope_->ReceiverScope()->is_function_scope()) {
2781 ReportMessageAt(scanner()->location(), 2798 ReportMessageAt(scanner()->location(),
2782 MessageTemplate::kUnexpectedNewTarget); 2799 MessageTemplate::kUnexpectedNewTarget);
2783 *ok = false; 2800 *ok = false;
2784 return this->EmptyExpression(); 2801 return this->EmptyExpression();
2785 } 2802 }
2786 2803
2787 return this->NewTargetExpression(scope_, factory(), pos); 2804 return this->NewTargetExpression(scope_, factory(), pos);
2788 } 2805 }
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
3345 return; 3362 return;
3346 } 3363 }
3347 has_seen_constructor_ = true; 3364 has_seen_constructor_ = true;
3348 return; 3365 return;
3349 } 3366 }
3350 } 3367 }
3351 } // namespace internal 3368 } // namespace internal
3352 } // namespace v8 3369 } // namespace v8
3353 3370
3354 #endif // V8_PARSING_PARSER_BASE_H 3371 #endif // V8_PARSING_PARSER_BASE_H
OLDNEW
« no previous file with comments | « src/messages.h ('k') | test/message/function-sent-escaped.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698