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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parsing/parser.cc ('k') | src/parsing/preparser.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parsing/parser-base.h
diff --git a/src/parsing/parser-base.h b/src/parsing/parser-base.h
index 46689d54c02bcb645cc658ef7481349764a85c5a..27b9764434c5364ff18c9cf561acde122b80090d 100644
--- a/src/parsing/parser-base.h
+++ b/src/parsing/parser-base.h
@@ -98,7 +98,6 @@ class ParserBase : public Traits {
v8::Extension* extension, AstValueFactory* ast_value_factory,
ParserRecorder* log, typename Traits::Type::Parser this_object)
: Traits(this_object),
- parenthesized_function_(false),
scope_(NULL),
function_state_(NULL),
extension_(extension),
@@ -266,6 +265,14 @@ class ParserBase : public Traits {
return &non_patterns_to_rewrite_;
}
+ void next_function_is_parenthesized(bool parenthesized) {
+ next_function_is_parenthesized_ = parenthesized;
+ }
+
+ bool this_function_is_parenthesized() const {
+ return this_function_is_parenthesized_;
+ }
+
private:
void AddDestructuringAssignment(DestructuringAssignment pair) {
destructuring_assignments_to_rewrite_.Add(pair);
@@ -312,6 +319,14 @@ class ParserBase : public Traits {
typename Traits::Type::Factory* factory_;
+ // If true, the next (and immediately following) function literal is
+ // preceded by a parenthesis.
+ bool next_function_is_parenthesized_;
+
+ // The value of the parents' next_function_is_parenthesized_, as it applies
+ // to this function. Filled in by constructor.
+ bool this_function_is_parenthesized_;
+
friend class ParserTraits;
friend class PreParserTraits;
friend class Checkpoint;
@@ -888,12 +903,6 @@ class ParserBase : public Traits {
bool has_seen_constructor_;
};
- // If true, the next (and immediately following) function literal is
- // preceded by a parenthesis.
- // Heuristically that means that the function will be called immediately,
- // so never lazily compile it.
- bool parenthesized_function_;
-
Scope* scope_; // Scope stack.
FunctionState* function_state_; // Function state stack.
v8::Extension* extension_;
@@ -935,9 +944,16 @@ ParserBase<Traits>::FunctionState::FunctionState(
outer_scope_(*scope_stack),
collect_expressions_in_tail_position_(true),
non_patterns_to_rewrite_(0, scope->zone()),
- factory_(factory) {
+ factory_(factory),
+ next_function_is_parenthesized_(false),
+ this_function_is_parenthesized_(false) {
*scope_stack_ = scope;
*function_state_stack = this;
+ if (outer_function_state_) {
+ this_function_is_parenthesized_ =
+ outer_function_state_->next_function_is_parenthesized_;
+ outer_function_state_->next_function_is_parenthesized_ = false;
+ }
}
@@ -1303,7 +1319,8 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier,
}
// Heuristically try to detect immediately called functions before
// seeing the call parentheses.
- parenthesized_function_ = (peek() == Token::FUNCTION);
+ function_state_->next_function_is_parenthesized(peek() ==
+ Token::FUNCTION);
ExpressionT expr = this->ParseExpression(true, classifier, CHECK_OK);
Expect(Token::RPAREN, CHECK_OK);
return expr;
@@ -2837,7 +2854,6 @@ ParserBase<Traits>::ParseArrowFunctionLiteral(
} else {
// Single-expression body
int pos = position();
- parenthesized_function_ = false;
ExpressionClassifier classifier(this);
ExpressionT expression =
ParseAssignmentExpression(accept_IN, &classifier, CHECK_OK);
« 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