Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Version 4.8.271.10 (cherry-pick)
Browse files Browse the repository at this point in the history
Merged 1a24847cb5e83f510e4202846230c8e586a99113

Fix FuncNameInferrer usage in ParseAssignmentExpression

[email protected], [email protected]
BUG=v8:4595
LOG=N

Review URL: https://codereview.chromium.org/1534533002 .

Cr-Commit-Position: refs/branch-heads/4.8@{#13}
Cr-Branched-From: 10449d4-refs/heads/4.8.271@{#1}
Cr-Branched-From: 2ebd5fc-refs/heads/master@{#31941}
  • Loading branch information
ajklein committed Dec 17, 2015
1 parent 9bd13de commit ef42af2
Show file tree
Hide file tree
Showing 6 changed files with 10,049 additions and 36 deletions.
2 changes: 1 addition & 1 deletion include/v8-version.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define V8_MAJOR_VERSION 4
#define V8_MINOR_VERSION 8
#define V8_BUILD_NUMBER 271
#define V8_PATCH_LEVEL 9
#define V8_PATCH_LEVEL 10

// Use 1 for candidates and 0 otherwise.
// (Boolean macro values are not supported by all preprocessors.)
Expand Down
38 changes: 25 additions & 13 deletions src/func-name-inferrer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,29 @@ class FuncNameInferrer : public ZoneObject {
public:
FuncNameInferrer(AstValueFactory* ast_value_factory, Zone* zone);

// To enter function name inference state, put a FuncNameInferrer::State
// on the stack.
class State {
public:
explicit State(FuncNameInferrer* fni) : fni_(fni) {
if (fni_ != nullptr) fni_->Enter();
}
~State() {
if (fni_ != nullptr) fni_->Leave();
}

private:
FuncNameInferrer* fni_;

DISALLOW_COPY_AND_ASSIGN(State);
};

// Returns whether we have entered name collection state.
bool IsOpen() const { return !entries_stack_.is_empty(); }

// Pushes an enclosing the name of enclosing function onto names stack.
void PushEnclosingName(const AstRawString* name);

// Enters name collection state.
void Enter() {
entries_stack_.Add(names_stack_.length(), zone());
}

// Pushes an encountered name onto names stack when in collection state.
void PushLiteralName(const AstRawString* name);

Expand All @@ -67,14 +79,6 @@ class FuncNameInferrer : public ZoneObject {
}
}

// Leaves names collection state.
void Leave() {
DCHECK(IsOpen());
names_stack_.Rewind(entries_stack_.RemoveLast());
if (entries_stack_.is_empty())
funcs_to_infer_.Clear();
}

private:
enum NameType {
kEnclosingConstructorName,
Expand All @@ -87,6 +91,14 @@ class FuncNameInferrer : public ZoneObject {
NameType type;
};

void Enter() { entries_stack_.Add(names_stack_.length(), zone()); }

void Leave() {
DCHECK(IsOpen());
names_stack_.Rewind(entries_stack_.RemoveLast());
if (entries_stack_.is_empty()) funcs_to_infer_.Clear();
}

Zone* zone() const { return zone_; }

// Constructs a full name in dotted notation from gathered names.
Expand Down
17 changes: 5 additions & 12 deletions src/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2242,10 +2242,8 @@ Statement* Parser::ParseFunctionDeclaration(
const AstRawString* name = ParseIdentifierOrStrictReservedWord(
&is_strict_reserved, CHECK_OK);

if (fni_ != NULL) {
fni_->Enter();
fni_->PushEnclosingName(name);
}
FuncNameInferrer::State fni_state(fni_);
if (fni_ != NULL) fni_->PushEnclosingName(name);
FunctionLiteral* fun = ParseFunctionLiteral(
name, scanner()->location(),
is_strict_reserved ? kFunctionNameIsStrictReserved
Expand All @@ -2254,7 +2252,6 @@ Statement* Parser::ParseFunctionDeclaration(
: FunctionKind::kNormalFunction,
pos, FunctionLiteral::DECLARATION, FunctionLiteral::NORMAL_ARITY,
language_mode(), CHECK_OK);
if (fni_ != NULL) fni_->Leave();

// Even if we're not at the top-level of the global or a function
// scope, we treat it as such and introduce the function with its
Expand Down Expand Up @@ -2531,7 +2528,7 @@ void Parser::ParseVariableDeclarations(VariableDeclarationContext var_context,
int bindings_start = peek_position();
bool is_for_iteration_variable;
do {
if (fni_ != NULL) fni_->Enter();
FuncNameInferrer::State fni_state(fni_);

// Parse name.
if (!first_declaration) Consume(Token::COMMA);
Expand Down Expand Up @@ -2621,7 +2618,6 @@ void Parser::ParseVariableDeclarations(VariableDeclarationContext var_context,
value = GetLiteralUndefined(position());
}

if (single_name && fni_ != NULL) fni_->Leave();
parsing_result->declarations.Add(DeclarationParsingResult::Declaration(
pattern, initializer_position, value));
first_declaration = false;
Expand Down Expand Up @@ -4933,7 +4929,7 @@ ClassLiteral* Parser::ParseClassLiteral(const AstRawString* name,
const bool has_extends = extends != nullptr;
while (peek() != Token::RBRACE) {
if (Check(Token::SEMICOLON)) continue;
if (fni_ != NULL) fni_->Enter();
FuncNameInferrer::State fni_state(fni_);
const bool in_class = true;
const bool is_static = false;
bool is_computed_name = false; // Classes do not care about computed
Expand All @@ -4951,10 +4947,7 @@ ClassLiteral* Parser::ParseClassLiteral(const AstRawString* name,
properties->Add(property, zone());
}

if (fni_ != NULL) {
fni_->Infer();
fni_->Leave();
}
if (fni_ != NULL) fni_->Infer();
}

Expect(Token::RBRACE, CHECK_OK);
Expand Down
17 changes: 7 additions & 10 deletions src/preparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -2787,7 +2787,7 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral(
Expect(Token::LBRACE, CHECK_OK);

while (peek() != Token::RBRACE) {
if (fni_ != nullptr) fni_->Enter();
FuncNameInferrer::State fni_state(fni_);

const bool in_class = false;
const bool is_static = false;
Expand Down Expand Up @@ -2818,10 +2818,7 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral(
Expect(Token::COMMA, CHECK_OK);
}

if (fni_ != nullptr) {
fni_->Infer();
fni_->Leave();
}
if (fni_ != nullptr) fni_->Infer();
}
Expect(Token::RBRACE, CHECK_OK);

Expand Down Expand Up @@ -2921,7 +2918,7 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN,
return this->ParseYieldExpression(classifier, ok);
}

if (fni_ != NULL) fni_->Enter();
FuncNameInferrer::State fni_state(fni_);
ParserBase<Traits>::Checkpoint checkpoint(this);
ExpressionClassifier arrow_formals_classifier(classifier->duplicate_finder());
bool parenthesized_formals = peek() == Token::LPAREN;
Expand Down Expand Up @@ -2960,6 +2957,9 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN,
}
expression = this->ParseArrowFunctionLiteral(
accept_IN, parameters, arrow_formals_classifier, CHECK_OK);

if (fni_ != nullptr) fni_->Infer();

return expression;
}

Expand All @@ -2970,7 +2970,6 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN,
ExpressionClassifier::FormalParametersProductions);

if (!Token::IsAssignmentOp(peek())) {
if (fni_ != NULL) fni_->Leave();
// Parsed conditional expression only (no assignment).
return expression;
}
Expand Down Expand Up @@ -3021,7 +3020,6 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN,
} else {
fni_->RemoveLastFunction();
}
fni_->Leave();
}

return factory()->NewAssignment(op, expression, right, pos);
Expand Down Expand Up @@ -3488,7 +3486,7 @@ ParserBase<Traits>::ParseStrongInitializationExpression(
// 'this' '.' IdentifierName '=' AssignmentExpression
// 'this' '[' Expression ']' '=' AssignmentExpression

if (fni_ != NULL) fni_->Enter();
FuncNameInferrer::State fni_state(fni_);

Consume(Token::THIS);
int pos = position();
Expand Down Expand Up @@ -3547,7 +3545,6 @@ ParserBase<Traits>::ParseStrongInitializationExpression(
} else {
fni_->RemoveLastFunction();
}
fni_->Leave();
}

if (function_state_->return_location().IsValid()) {
Expand Down
3 changes: 3 additions & 0 deletions test/mjsunit/mjsunit.status
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@
# Too slow in debug mode for GC stress mode.
'regress/regress-crbug-217858': [PASS, ['mode == debug', SKIP]],

# Too slow in debug mode and under turbofan.
'regress/regress-4595': [PASS, NO_VARIANTS, ['mode == debug', SKIP]],

##############################################################################
# Only RegExp stuff tested, no need for extensive optimizing compiler tests.
'regexp-global': [PASS, NO_VARIANTS],
Expand Down
Loading

0 comments on commit ef42af2

Please sign in to comment.