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

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

Issue 1895123002: Prevent un-parsed LiteralFunction reaching the compiler. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix test. (eager_compile_hint used function_state_ of parent function.) 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT; 91 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT;
92 typedef typename Traits::Type::Literal LiteralT; 92 typedef typename Traits::Type::Literal LiteralT;
93 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT; 93 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT;
94 typedef typename Traits::Type::StatementList StatementListT; 94 typedef typename Traits::Type::StatementList StatementListT;
95 typedef typename Traits::Type::ExpressionClassifier ExpressionClassifier; 95 typedef typename Traits::Type::ExpressionClassifier ExpressionClassifier;
96 96
97 ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit, 97 ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit,
98 v8::Extension* extension, AstValueFactory* ast_value_factory, 98 v8::Extension* extension, AstValueFactory* ast_value_factory,
99 ParserRecorder* log, typename Traits::Type::Parser this_object) 99 ParserRecorder* log, typename Traits::Type::Parser this_object)
100 : Traits(this_object), 100 : Traits(this_object),
101 parenthesized_function_(false),
102 scope_(NULL), 101 scope_(NULL),
103 function_state_(NULL), 102 function_state_(NULL),
104 extension_(extension), 103 extension_(extension),
105 fni_(NULL), 104 fni_(NULL),
106 ast_value_factory_(ast_value_factory), 105 ast_value_factory_(ast_value_factory),
107 log_(log), 106 log_(log),
108 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. 107 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly.
109 stack_limit_(stack_limit), 108 stack_limit_(stack_limit),
110 zone_(zone), 109 zone_(zone),
111 scanner_(scanner), 110 scanner_(scanner),
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 return collect_expressions_in_tail_position_; 258 return collect_expressions_in_tail_position_;
260 } 259 }
261 void set_collect_expressions_in_tail_position(bool collect) { 260 void set_collect_expressions_in_tail_position(bool collect) {
262 collect_expressions_in_tail_position_ = collect; 261 collect_expressions_in_tail_position_ = collect;
263 } 262 }
264 263
265 ZoneList<ExpressionT>* non_patterns_to_rewrite() { 264 ZoneList<ExpressionT>* non_patterns_to_rewrite() {
266 return &non_patterns_to_rewrite_; 265 return &non_patterns_to_rewrite_;
267 } 266 }
268 267
268 void next_function_is_parenthesized(bool parenthesized) {
269 next_function_is_parenthesized_ = parenthesized;
270 }
271
272 bool this_function_is_parenthesized() const {
273 return this_function_is_parenthesized_;
274 }
275
269 private: 276 private:
270 void AddDestructuringAssignment(DestructuringAssignment pair) { 277 void AddDestructuringAssignment(DestructuringAssignment pair) {
271 destructuring_assignments_to_rewrite_.Add(pair); 278 destructuring_assignments_to_rewrite_.Add(pair);
272 } 279 }
273 280
274 V8_INLINE Scope* scope() { return *scope_stack_; } 281 V8_INLINE Scope* scope() { return *scope_stack_; }
275 282
276 void AddNonPatternForRewriting(ExpressionT expr) { 283 void AddNonPatternForRewriting(ExpressionT expr) {
277 non_patterns_to_rewrite_.Add(expr, (*scope_stack_)->zone()); 284 non_patterns_to_rewrite_.Add(expr, (*scope_stack_)->zone());
278 } 285 }
(...skipping 26 matching lines...) Expand all
305 Scope** scope_stack_; 312 Scope** scope_stack_;
306 Scope* outer_scope_; 313 Scope* outer_scope_;
307 314
308 List<DestructuringAssignment> destructuring_assignments_to_rewrite_; 315 List<DestructuringAssignment> destructuring_assignments_to_rewrite_;
309 List<ExpressionT> expressions_in_tail_position_; 316 List<ExpressionT> expressions_in_tail_position_;
310 bool collect_expressions_in_tail_position_; 317 bool collect_expressions_in_tail_position_;
311 ZoneList<ExpressionT> non_patterns_to_rewrite_; 318 ZoneList<ExpressionT> non_patterns_to_rewrite_;
312 319
313 typename Traits::Type::Factory* factory_; 320 typename Traits::Type::Factory* factory_;
314 321
322 // If true, the next (and immediately following) function literal is
323 // preceded by a parenthesis.
324 bool next_function_is_parenthesized_;
325
326 // The value of the parents' next_function_is_parenthesized_, as it applies
327 // to this function. Filled in by constructor.
328 bool this_function_is_parenthesized_;
329
315 friend class ParserTraits; 330 friend class ParserTraits;
316 friend class PreParserTraits; 331 friend class PreParserTraits;
317 friend class Checkpoint; 332 friend class Checkpoint;
318 }; 333 };
319 334
320 // Annoyingly, arrow functions first parse as comma expressions, then when we 335 // Annoyingly, arrow functions first parse as comma expressions, then when we
321 // see the => we have to go back and reinterpret the arguments as being formal 336 // see the => we have to go back and reinterpret the arguments as being formal
322 // parameters. To do so we need to reset some of the parser state back to 337 // parameters. To do so we need to reset some of the parser state back to
323 // what it was before the arguments were first seen. 338 // what it was before the arguments were first seen.
324 class Checkpoint BASE_EMBEDDED { 339 class Checkpoint BASE_EMBEDDED {
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 bool IsConstructor() { 896 bool IsConstructor() {
882 return this->scanner()->LiteralMatches("constructor", 11); 897 return this->scanner()->LiteralMatches("constructor", 11);
883 } 898 }
884 bool IsPrototype() { 899 bool IsPrototype() {
885 return this->scanner()->LiteralMatches("prototype", 9); 900 return this->scanner()->LiteralMatches("prototype", 9);
886 } 901 }
887 902
888 bool has_seen_constructor_; 903 bool has_seen_constructor_;
889 }; 904 };
890 905
891 // If true, the next (and immediately following) function literal is
892 // preceded by a parenthesis.
893 // Heuristically that means that the function will be called immediately,
894 // so never lazily compile it.
895 bool parenthesized_function_;
896
897 Scope* scope_; // Scope stack. 906 Scope* scope_; // Scope stack.
898 FunctionState* function_state_; // Function state stack. 907 FunctionState* function_state_; // Function state stack.
899 v8::Extension* extension_; 908 v8::Extension* extension_;
900 FuncNameInferrer* fni_; 909 FuncNameInferrer* fni_;
901 AstValueFactory* ast_value_factory_; // Not owned. 910 AstValueFactory* ast_value_factory_; // Not owned.
902 ParserRecorder* log_; 911 ParserRecorder* log_;
903 Mode mode_; 912 Mode mode_;
904 uintptr_t stack_limit_; 913 uintptr_t stack_limit_;
905 914
906 private: 915 private:
(...skipping 21 matching lines...) Expand all
928 return_location_(Scanner::Location::invalid()), 937 return_location_(Scanner::Location::invalid()),
929 super_location_(Scanner::Location::invalid()), 938 super_location_(Scanner::Location::invalid()),
930 kind_(kind), 939 kind_(kind),
931 generator_object_variable_(NULL), 940 generator_object_variable_(NULL),
932 function_state_stack_(function_state_stack), 941 function_state_stack_(function_state_stack),
933 outer_function_state_(*function_state_stack), 942 outer_function_state_(*function_state_stack),
934 scope_stack_(scope_stack), 943 scope_stack_(scope_stack),
935 outer_scope_(*scope_stack), 944 outer_scope_(*scope_stack),
936 collect_expressions_in_tail_position_(true), 945 collect_expressions_in_tail_position_(true),
937 non_patterns_to_rewrite_(0, scope->zone()), 946 non_patterns_to_rewrite_(0, scope->zone()),
938 factory_(factory) { 947 factory_(factory),
948 next_function_is_parenthesized_(false),
949 this_function_is_parenthesized_(false) {
939 *scope_stack_ = scope; 950 *scope_stack_ = scope;
940 *function_state_stack = this; 951 *function_state_stack = this;
952 if (outer_function_state_) {
953 this_function_is_parenthesized_ =
954 outer_function_state_->next_function_is_parenthesized_;
955 outer_function_state_->next_function_is_parenthesized_ = false;
956 }
941 } 957 }
942 958
943 959
944 template <class Traits> 960 template <class Traits>
945 ParserBase<Traits>::FunctionState::~FunctionState() { 961 ParserBase<Traits>::FunctionState::~FunctionState() {
946 *scope_stack_ = outer_scope_; 962 *scope_stack_ = outer_scope_;
947 *function_state_stack_ = outer_function_state_; 963 *function_state_stack_ = outer_function_state_;
948 } 964 }
949 965
950 template <class Traits> 966 template <class Traits>
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
1296 ReportMessageAt(scanner()->peek_location(), 1312 ReportMessageAt(scanner()->peek_location(),
1297 MessageTemplate::kParamAfterRest); 1313 MessageTemplate::kParamAfterRest);
1298 *ok = false; 1314 *ok = false;
1299 return this->EmptyExpression(); 1315 return this->EmptyExpression();
1300 } 1316 }
1301 Expect(Token::RPAREN, CHECK_OK); 1317 Expect(Token::RPAREN, CHECK_OK);
1302 return factory()->NewSpread(expr, ellipsis_pos, expr_pos); 1318 return factory()->NewSpread(expr, ellipsis_pos, expr_pos);
1303 } 1319 }
1304 // Heuristically try to detect immediately called functions before 1320 // Heuristically try to detect immediately called functions before
1305 // seeing the call parentheses. 1321 // seeing the call parentheses.
1306 parenthesized_function_ = (peek() == Token::FUNCTION); 1322 function_state_->next_function_is_parenthesized(peek() ==
1323 Token::FUNCTION);
1307 ExpressionT expr = this->ParseExpression(true, classifier, CHECK_OK); 1324 ExpressionT expr = this->ParseExpression(true, classifier, CHECK_OK);
1308 Expect(Token::RPAREN, CHECK_OK); 1325 Expect(Token::RPAREN, CHECK_OK);
1309 return expr; 1326 return expr;
1310 } 1327 }
1311 1328
1312 case Token::CLASS: { 1329 case Token::CLASS: {
1313 BindingPatternUnexpectedToken(classifier); 1330 BindingPatternUnexpectedToken(classifier);
1314 Consume(Token::CLASS); 1331 Consume(Token::CLASS);
1315 int class_token_position = position(); 1332 int class_token_position = position();
1316 IdentifierT name = this->EmptyIdentifier(); 1333 IdentifierT name = this->EmptyIdentifier();
(...skipping 1513 matching lines...) Expand 10 before | Expand all | Expand 10 after
2830 body = this->ParseEagerFunctionBody( 2847 body = this->ParseEagerFunctionBody(
2831 this->EmptyIdentifier(), RelocInfo::kNoPosition, formal_parameters, 2848 this->EmptyIdentifier(), RelocInfo::kNoPosition, formal_parameters,
2832 kArrowFunction, FunctionLiteral::kAnonymousExpression, CHECK_OK); 2849 kArrowFunction, FunctionLiteral::kAnonymousExpression, CHECK_OK);
2833 materialized_literal_count = 2850 materialized_literal_count =
2834 function_state.materialized_literal_count(); 2851 function_state.materialized_literal_count();
2835 expected_property_count = function_state.expected_property_count(); 2852 expected_property_count = function_state.expected_property_count();
2836 } 2853 }
2837 } else { 2854 } else {
2838 // Single-expression body 2855 // Single-expression body
2839 int pos = position(); 2856 int pos = position();
2840 parenthesized_function_ = false;
2841 ExpressionClassifier classifier(this); 2857 ExpressionClassifier classifier(this);
2842 ExpressionT expression = 2858 ExpressionT expression =
2843 ParseAssignmentExpression(accept_IN, &classifier, CHECK_OK); 2859 ParseAssignmentExpression(accept_IN, &classifier, CHECK_OK);
2844 Traits::RewriteNonPattern(&classifier, CHECK_OK); 2860 Traits::RewriteNonPattern(&classifier, CHECK_OK);
2845 body = this->NewStatementList(1, zone()); 2861 body = this->NewStatementList(1, zone());
2846 this->AddParameterInitializationBlock(formal_parameters, body, CHECK_OK); 2862 this->AddParameterInitializationBlock(formal_parameters, body, CHECK_OK);
2847 body->Add(factory()->NewReturnStatement(expression, pos), zone()); 2863 body->Add(factory()->NewReturnStatement(expression, pos), zone());
2848 materialized_literal_count = function_state.materialized_literal_count(); 2864 materialized_literal_count = function_state.materialized_literal_count();
2849 expected_property_count = function_state.expected_property_count(); 2865 expected_property_count = function_state.expected_property_count();
2850 } 2866 }
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
3096 has_seen_constructor_ = true; 3112 has_seen_constructor_ = true;
3097 return; 3113 return;
3098 } 3114 }
3099 } 3115 }
3100 3116
3101 3117
3102 } // namespace internal 3118 } // namespace internal
3103 } // namespace v8 3119 } // namespace v8
3104 3120
3105 #endif // V8_PARSING_PARSER_BASE_H 3121 #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