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

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

Issue 1858943002: Remove runtime flags for sloppy mode block scoping features (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased Created 4 years, 8 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/parsing/parser.cc ('k') | src/parsing/preparser.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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 ast_value_factory_(ast_value_factory), 106 ast_value_factory_(ast_value_factory),
107 log_(log), 107 log_(log),
108 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. 108 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly.
109 stack_limit_(stack_limit), 109 stack_limit_(stack_limit),
110 zone_(zone), 110 zone_(zone),
111 scanner_(scanner), 111 scanner_(scanner),
112 stack_overflow_(false), 112 stack_overflow_(false),
113 allow_lazy_(false), 113 allow_lazy_(false),
114 allow_natives_(false), 114 allow_natives_(false),
115 allow_tailcalls_(false), 115 allow_tailcalls_(false),
116 allow_harmony_sloppy_(false),
117 allow_harmony_sloppy_function_(false),
118 allow_harmony_sloppy_let_(false),
119 allow_harmony_restrictive_declarations_(false), 116 allow_harmony_restrictive_declarations_(false),
120 allow_harmony_do_expressions_(false), 117 allow_harmony_do_expressions_(false),
121 allow_harmony_function_name_(false), 118 allow_harmony_function_name_(false),
122 allow_harmony_function_sent_(false) {} 119 allow_harmony_function_sent_(false) {}
123 120
124 #define ALLOW_ACCESSORS(name) \ 121 #define ALLOW_ACCESSORS(name) \
125 bool allow_##name() const { return allow_##name##_; } \ 122 bool allow_##name() const { return allow_##name##_; } \
126 void set_allow_##name(bool allow) { allow_##name##_ = allow; } 123 void set_allow_##name(bool allow) { allow_##name##_ = allow; }
127 124
128 #define SCANNER_ACCESSORS(name) \ 125 #define SCANNER_ACCESSORS(name) \
129 bool allow_##name() const { return scanner_->allow_##name(); } \ 126 bool allow_##name() const { return scanner_->allow_##name(); } \
130 void set_allow_##name(bool allow) { \ 127 void set_allow_##name(bool allow) { \
131 return scanner_->set_allow_##name(allow); \ 128 return scanner_->set_allow_##name(allow); \
132 } 129 }
133 130
134 ALLOW_ACCESSORS(lazy); 131 ALLOW_ACCESSORS(lazy);
135 ALLOW_ACCESSORS(natives); 132 ALLOW_ACCESSORS(natives);
136 ALLOW_ACCESSORS(tailcalls); 133 ALLOW_ACCESSORS(tailcalls);
137 ALLOW_ACCESSORS(harmony_sloppy);
138 ALLOW_ACCESSORS(harmony_sloppy_function);
139 ALLOW_ACCESSORS(harmony_sloppy_let);
140 ALLOW_ACCESSORS(harmony_restrictive_declarations); 134 ALLOW_ACCESSORS(harmony_restrictive_declarations);
141 ALLOW_ACCESSORS(harmony_do_expressions); 135 ALLOW_ACCESSORS(harmony_do_expressions);
142 ALLOW_ACCESSORS(harmony_function_name); 136 ALLOW_ACCESSORS(harmony_function_name);
143 ALLOW_ACCESSORS(harmony_function_sent); 137 ALLOW_ACCESSORS(harmony_function_sent);
144 SCANNER_ACCESSORS(harmony_exponentiation_operator); 138 SCANNER_ACCESSORS(harmony_exponentiation_operator);
145 139
146 #undef SCANNER_ACCESSORS 140 #undef SCANNER_ACCESSORS
147 #undef ALLOW_ACCESSORS 141 #undef ALLOW_ACCESSORS
148 142
149 uintptr_t stack_limit() const { return stack_limit_; } 143 uintptr_t stack_limit() const { return stack_limit_; }
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 return Token::Precedence(token); 551 return Token::Precedence(token);
558 } 552 }
559 553
560 typename Traits::Type::Factory* factory() { 554 typename Traits::Type::Factory* factory() {
561 return function_state_->factory(); 555 return function_state_->factory();
562 } 556 }
563 557
564 LanguageMode language_mode() { return scope_->language_mode(); } 558 LanguageMode language_mode() { return scope_->language_mode(); }
565 bool is_generator() const { return function_state_->is_generator(); } 559 bool is_generator() const { return function_state_->is_generator(); }
566 560
567 bool allow_const() {
568 return is_strict(language_mode()) || allow_harmony_sloppy();
569 }
570
571 bool allow_let() {
572 return is_strict(language_mode()) || allow_harmony_sloppy_let();
573 }
574
575 // Report syntax errors. 561 // Report syntax errors.
576 void ReportMessage(MessageTemplate::Template message, const char* arg = NULL, 562 void ReportMessage(MessageTemplate::Template message, const char* arg = NULL,
577 ParseErrorType error_type = kSyntaxError) { 563 ParseErrorType error_type = kSyntaxError) {
578 Scanner::Location source_location = scanner()->location(); 564 Scanner::Location source_location = scanner()->location();
579 Traits::ReportMessageAt(source_location, message, arg, error_type); 565 Traits::ReportMessageAt(source_location, message, arg, error_type);
580 } 566 }
581 567
582 void ReportMessageAt(Scanner::Location location, 568 void ReportMessageAt(Scanner::Location location,
583 MessageTemplate::Template message, 569 MessageTemplate::Template message,
584 ParseErrorType error_type = kSyntaxError) { 570 ParseErrorType error_type = kSyntaxError) {
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 905
920 private: 906 private:
921 Zone* zone_; 907 Zone* zone_;
922 908
923 Scanner* scanner_; 909 Scanner* scanner_;
924 bool stack_overflow_; 910 bool stack_overflow_;
925 911
926 bool allow_lazy_; 912 bool allow_lazy_;
927 bool allow_natives_; 913 bool allow_natives_;
928 bool allow_tailcalls_; 914 bool allow_tailcalls_;
929 bool allow_harmony_sloppy_;
930 bool allow_harmony_sloppy_function_;
931 bool allow_harmony_sloppy_let_;
932 bool allow_harmony_restrictive_declarations_; 915 bool allow_harmony_restrictive_declarations_;
933 bool allow_harmony_do_expressions_; 916 bool allow_harmony_do_expressions_;
934 bool allow_harmony_function_name_; 917 bool allow_harmony_function_name_;
935 bool allow_harmony_function_sent_; 918 bool allow_harmony_function_sent_;
936 }; 919 };
937 920
938 template <class Traits> 921 template <class Traits>
939 ParserBase<Traits>::FunctionState::FunctionState( 922 ParserBase<Traits>::FunctionState::FunctionState(
940 FunctionState** function_state_stack, Scope** scope_stack, Scope* scope, 923 FunctionState** function_state_stack, Scope** scope_stack, Scope* scope,
941 FunctionKind kind, typename Traits::Type::Factory* factory) 924 FunctionKind kind, typename Traits::Type::Factory* factory)
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
1322 // seeing the call parentheses. 1305 // seeing the call parentheses.
1323 parenthesized_function_ = (peek() == Token::FUNCTION); 1306 parenthesized_function_ = (peek() == Token::FUNCTION);
1324 ExpressionT expr = this->ParseExpression(true, classifier, CHECK_OK); 1307 ExpressionT expr = this->ParseExpression(true, classifier, CHECK_OK);
1325 Expect(Token::RPAREN, CHECK_OK); 1308 Expect(Token::RPAREN, CHECK_OK);
1326 return expr; 1309 return expr;
1327 } 1310 }
1328 1311
1329 case Token::CLASS: { 1312 case Token::CLASS: {
1330 BindingPatternUnexpectedToken(classifier); 1313 BindingPatternUnexpectedToken(classifier);
1331 Consume(Token::CLASS); 1314 Consume(Token::CLASS);
1332 if (!allow_harmony_sloppy() && is_sloppy(language_mode())) {
1333 ReportMessage(MessageTemplate::kSloppyLexical);
1334 *ok = false;
1335 return this->EmptyExpression();
1336 }
1337 int class_token_position = position(); 1315 int class_token_position = position();
1338 IdentifierT name = this->EmptyIdentifier(); 1316 IdentifierT name = this->EmptyIdentifier();
1339 bool is_strict_reserved_name = false; 1317 bool is_strict_reserved_name = false;
1340 Scanner::Location class_name_location = Scanner::Location::invalid(); 1318 Scanner::Location class_name_location = Scanner::Location::invalid();
1341 if (peek_any_identifier()) { 1319 if (peek_any_identifier()) {
1342 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name, 1320 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name,
1343 CHECK_OK); 1321 CHECK_OK);
1344 class_name_location = scanner()->location(); 1322 class_name_location = scanner()->location();
1345 } 1323 }
1346 return this->ParseClassLiteral(name, class_name_location, 1324 return this->ParseClassLiteral(name, class_name_location,
(...skipping 1433 matching lines...) Expand 10 before | Expand all | Expand 10 after
2780 MessageTemplate::kBadSetterRestParameter); 2758 MessageTemplate::kBadSetterRestParameter);
2781 *ok = false; 2759 *ok = false;
2782 } 2760 }
2783 } 2761 }
2784 } 2762 }
2785 2763
2786 2764
2787 template <class Traits> 2765 template <class Traits>
2788 bool ParserBase<Traits>::IsNextLetKeyword() { 2766 bool ParserBase<Traits>::IsNextLetKeyword() {
2789 DCHECK(peek() == Token::LET); 2767 DCHECK(peek() == Token::LET);
2790 if (!allow_let()) {
2791 return false;
2792 }
2793 Token::Value next_next = PeekAhead(); 2768 Token::Value next_next = PeekAhead();
2794 switch (next_next) { 2769 switch (next_next) {
2795 case Token::LBRACE: 2770 case Token::LBRACE:
2796 case Token::LBRACK: 2771 case Token::LBRACK:
2797 case Token::IDENTIFIER: 2772 case Token::IDENTIFIER:
2798 case Token::STATIC: 2773 case Token::STATIC:
2799 case Token::LET: // Yes, you can do let let = ... in sloppy mode 2774 case Token::LET: // Yes, you can do let let = ... in sloppy mode
2800 case Token::YIELD: 2775 case Token::YIELD:
2801 return true; 2776 return true;
2802 default: 2777 default:
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
2883 // itself be strict as well. 2858 // itself be strict as well.
2884 const bool allow_duplicate_parameters = false; 2859 const bool allow_duplicate_parameters = false;
2885 this->ValidateFormalParameters(&formals_classifier, language_mode(), 2860 this->ValidateFormalParameters(&formals_classifier, language_mode(),
2886 allow_duplicate_parameters, CHECK_OK); 2861 allow_duplicate_parameters, CHECK_OK);
2887 2862
2888 // Validate strict mode. 2863 // Validate strict mode.
2889 if (is_strict(language_mode())) { 2864 if (is_strict(language_mode())) {
2890 CheckStrictOctalLiteral(formal_parameters.scope->start_position(), 2865 CheckStrictOctalLiteral(formal_parameters.scope->start_position(),
2891 scanner()->location().end_pos, CHECK_OK); 2866 scanner()->location().end_pos, CHECK_OK);
2892 } 2867 }
2893 if (is_strict(language_mode()) || allow_harmony_sloppy()) { 2868 this->CheckConflictingVarDeclarations(formal_parameters.scope, CHECK_OK);
2894 this->CheckConflictingVarDeclarations(formal_parameters.scope, CHECK_OK);
2895 }
2896 2869
2897 Traits::RewriteDestructuringAssignments(); 2870 Traits::RewriteDestructuringAssignments();
2898 } 2871 }
2899 2872
2900 FunctionLiteralT function_literal = factory()->NewFunctionLiteral( 2873 FunctionLiteralT function_literal = factory()->NewFunctionLiteral(
2901 this->EmptyIdentifierString(), formal_parameters.scope, body, 2874 this->EmptyIdentifierString(), formal_parameters.scope, body,
2902 materialized_literal_count, expected_property_count, num_parameters, 2875 materialized_literal_count, expected_property_count, num_parameters,
2903 FunctionLiteral::kNoDuplicateParameters, 2876 FunctionLiteral::kNoDuplicateParameters,
2904 FunctionLiteral::kAnonymousExpression, 2877 FunctionLiteral::kAnonymousExpression,
2905 FunctionLiteral::kShouldLazyCompile, FunctionKind::kArrowFunction, 2878 FunctionLiteral::kShouldLazyCompile, FunctionKind::kArrowFunction,
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
3123 has_seen_constructor_ = true; 3096 has_seen_constructor_ = true;
3124 return; 3097 return;
3125 } 3098 }
3126 } 3099 }
3127 3100
3128 3101
3129 } // namespace internal 3102 } // namespace internal
3130 } // namespace v8 3103 } // namespace v8
3131 3104
3132 #endif // V8_PARSING_PARSER_BASE_H 3105 #endif // V8_PARSING_PARSER_BASE_H
OLDNEW
« no previous file with comments | « src/parsing/parser.cc ('k') | src/parsing/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698