| Index: src/preparser.cc
|
| diff --git a/src/preparser.cc b/src/preparser.cc
|
| index 95339dac33ca08b6b87bdf4bfed467c294a93280..68b29fc5fea5c8a9e1b394b97a1f71111a7cf25b 100644
|
| --- a/src/preparser.cc
|
| +++ b/src/preparser.cc
|
| @@ -108,13 +108,19 @@ PreParser::PreParseResult PreParser::PreParseLazyFunction(
|
| &top_factory);
|
| scope_->SetLanguageMode(language_mode);
|
| Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE);
|
| + Scope* function_body = NewScope(function_scope, FUNCTION_BODY_SCOPE);
|
| + DCHECK_EQ(function_scope->function_body(), function_body);
|
| PreParserFactory function_factory(NULL);
|
| FunctionState function_state(&function_state_, &scope_, function_scope, kind,
|
| &function_factory);
|
| DCHECK_EQ(Token::LBRACE, scanner()->current_token());
|
| bool ok = true;
|
| int start_position = peek_position();
|
| - ParseLazyFunctionLiteralBody(&ok);
|
| + {
|
| + DCHECK(scope_->is_function_scope());
|
| + BlockState(&scope_, function_body);
|
| + ParseLazyFunctionLiteralBody(&ok);
|
| + }
|
| if (stack_overflow()) return kPreParseStackOverflow;
|
| if (!ok) {
|
| ReportUnexpectedToken(scanner()->current_token());
|
| @@ -996,6 +1002,8 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
|
| // Parse function body.
|
| bool outer_is_script_scope = scope_->is_script_scope();
|
| Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE);
|
| + Scope* function_body = NewScope(function_scope, FUNCTION_BODY_SCOPE);
|
| + DCHECK_EQ(function_scope->function_body(), function_body);
|
| PreParserFactory factory(NULL);
|
| FunctionState function_state(&function_state_, &scope_, function_scope, kind,
|
| &factory);
|
| @@ -1005,11 +1013,15 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
|
| Expect(Token::LPAREN, CHECK_OK);
|
| int start_position = scanner()->location().beg_pos;
|
| function_scope->set_start_position(start_position);
|
| + function_body->set_start_position(start_position);
|
| int num_parameters;
|
| + bool has_initializers = false;
|
| {
|
| DuplicateFinder duplicate_finder(scanner()->unicode_cache());
|
| - num_parameters = ParseFormalParameterList(&duplicate_finder, &error_locs,
|
| - &is_rest, CHECK_OK);
|
| + PreParserExpressionList initializers = NewExpressionList(0, zone());
|
| + num_parameters =
|
| + ParseFormalParameterList(&duplicate_finder, &error_locs, initializers,
|
| + &has_initializers, &is_rest, CHECK_OK);
|
| }
|
| Expect(Token::RPAREN, CHECK_OK);
|
| int formals_end_position = scanner()->location().end_pos;
|
| @@ -1024,12 +1036,24 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
|
| parenthesized_function_ = false;
|
|
|
| Expect(Token::LBRACE, CHECK_OK);
|
| - if (is_lazily_parsed) {
|
| - ParseLazyFunctionLiteralBody(CHECK_OK);
|
| - } else {
|
| - ParseStatementList(Token::RBRACE, CHECK_OK);
|
| + {
|
| + // Use the FUNCTION_BODY scope only if it's needed
|
| + // TODO(caitp): This is needed when ObjectBindingPatterns with
|
| + // computed property keys are used as well.
|
| + Scope* func_scope = has_initializers ? function_body : scope_;
|
| + if (func_scope != function_body) {
|
| + function_body->FinalizeBlockScope();
|
| + }
|
| + BlockState function_body_state(&scope_, func_scope);
|
| + if (is_lazily_parsed) {
|
| + ParseLazyFunctionLiteralBody(CHECK_OK);
|
| + } else {
|
| + ParseStatementList(Token::RBRACE, CHECK_OK);
|
| + }
|
| }
|
| Expect(Token::RBRACE, CHECK_OK);
|
| + function_scope->set_end_position(scanner()->location().end_pos);
|
| + function_body->set_end_position(scanner()->location().end_pos);
|
|
|
| // Validate name and parameter names. We can do this only after parsing the
|
| // function, since the function can declare itself strict.
|
|
|