| Index: src/parsing/preparser.cc
|
| diff --git a/src/parsing/preparser.cc b/src/parsing/preparser.cc
|
| index 3a6bfbf3b1f84e7c086d56ac16eb214832307afb..7bca65026696cbf5e70b4b0573f642d18eda288c 100644
|
| --- a/src/parsing/preparser.cc
|
| +++ b/src/parsing/preparser.cc
|
| @@ -84,8 +84,9 @@ PreParserIdentifier PreParser::GetSymbol() const {
|
| }
|
|
|
| PreParser::PreParseResult PreParser::PreParseFunction(
|
| - DeclarationScope* function_scope, bool parsing_module, SingletonLogger* log,
|
| - bool is_inner_function, bool may_abort, int* use_counts) {
|
| + FunctionKind kind, DeclarationScope* function_scope, bool parsing_module,
|
| + SingletonLogger* log, bool is_inner_function, bool may_abort,
|
| + int* use_counts) {
|
| DCHECK_EQ(FUNCTION_SCOPE, function_scope->scope_type());
|
| parsing_module_ = parsing_module;
|
| log_ = log;
|
| @@ -98,24 +99,65 @@ PreParser::PreParseResult PreParser::PreParseFunction(
|
| // PreParser.
|
| DCHECK_NULL(scope_state_);
|
| FunctionState function_state(&function_state_, &scope_state_, function_scope);
|
| - DCHECK_EQ(Token::LBRACE, scanner()->current_token());
|
| - bool ok = true;
|
| - int start_position = peek_position();
|
| - LazyParsingResult result = ParseStatementListAndLogFunction(may_abort, &ok);
|
| + // This indirection is needed so that we can use the CHECK_OK macros.
|
| + bool ok_holder = true;
|
| + bool* ok = &ok_holder;
|
| +
|
| + PreParserFormalParameters formals(function_scope);
|
| + bool has_duplicate_parameters = false;
|
| + DuplicateFinder duplicate_finder(scanner()->unicode_cache());
|
| + std::unique_ptr<ExpressionClassifier> formals_classifier;
|
| +
|
| + // Parse non-arrow function parameters. For arrow functions, the parameters
|
| + // have already been parsed.
|
| + if ((kind & FunctionKind::kArrowFunction) == 0) {
|
| + formals_classifier.reset(new ExpressionClassifier(this, &duplicate_finder));
|
| + // We return kPreParseSuccess in failure cases too - errors are retrieved
|
| + // separately by Parser::SkipLazyFunctionBody.
|
| + Expect(Token::LPAREN, CHECK_OK_VALUE(kPreParseSuccess));
|
| + function_scope->set_start_position(scanner()->location().beg_pos);
|
| + ParseFormalParameterList(&formals, CHECK_OK_VALUE(kPreParseSuccess));
|
| + Expect(Token::RPAREN, CHECK_OK_VALUE(kPreParseSuccess));
|
| + int formals_end_position = scanner()->location().end_pos;
|
| +
|
| + CheckArityRestrictions(
|
| + formals.arity, kind, formals.has_rest, function_scope->start_position(),
|
| + formals_end_position, CHECK_OK_VALUE(kPreParseSuccess));
|
| + has_duplicate_parameters =
|
| + !classifier()->is_valid_formal_parameter_list_without_duplicates();
|
| + }
|
| +
|
| + Expect(Token::LBRACE, CHECK_OK_VALUE(kPreParseSuccess));
|
| + LazyParsingResult result = ParseStatementListAndLogFunction(
|
| + function_scope->start_position(), &formals, has_duplicate_parameters,
|
| + may_abort, ok);
|
| use_counts_ = nullptr;
|
| track_unresolved_variables_ = false;
|
| if (result == kLazyParsingAborted) {
|
| return kPreParseAbort;
|
| } else if (stack_overflow()) {
|
| return kPreParseStackOverflow;
|
| - } else if (!ok) {
|
| + } else if (!*ok) {
|
| DCHECK(log->has_error());
|
| } else {
|
| DCHECK_EQ(Token::RBRACE, scanner()->peek());
|
| +
|
| + if ((kind & FunctionKind::kArrowFunction) == 0) {
|
| + // Validate parameter names. We can do this only after parsing the
|
| + // function, since the function can declare itself strict.
|
| + const bool allow_duplicate_parameters =
|
| + is_sloppy(function_scope->language_mode()) && formals.is_simple &&
|
| + !IsConciseMethod(kind);
|
| + ValidateFormalParameters(function_scope->language_mode(),
|
| + allow_duplicate_parameters,
|
| + CHECK_OK_VALUE(kPreParseSuccess));
|
| + }
|
| +
|
| if (is_strict(function_scope->language_mode())) {
|
| int end_pos = scanner()->location().end_pos;
|
| - CheckStrictOctalLiteral(start_position, end_pos, &ok);
|
| - CheckDecimalLiteralWithLeadingZero(start_position, end_pos);
|
| + CheckStrictOctalLiteral(function_scope->start_position(), end_pos, ok);
|
| + CheckDecimalLiteralWithLeadingZero(function_scope->start_position(),
|
| + end_pos);
|
| }
|
| }
|
| return kPreParseSuccess;
|
| @@ -195,8 +237,8 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
|
| }
|
|
|
| PreParser::LazyParsingResult PreParser::ParseStatementListAndLogFunction(
|
| - bool may_abort, bool* ok) {
|
| - int body_start = position();
|
| + int start_position, PreParserFormalParameters* formals,
|
| + bool has_duplicate_parameters, bool may_abort, bool* ok) {
|
| PreParserStatementList body;
|
| LazyParsingResult result = ParseStatementList(
|
| body, Token::RBRACE, may_abort, CHECK_OK_VALUE(kLazyParsingComplete));
|
| @@ -207,7 +249,10 @@ PreParser::LazyParsingResult PreParser::ParseStatementListAndLogFunction(
|
| int body_end = scanner()->peek_location().end_pos;
|
| DeclarationScope* scope = this->scope()->AsDeclarationScope();
|
| DCHECK(scope->is_function_scope());
|
| - log_->LogFunction(body_start, body_end,
|
| + // Key position doesn't matter, since it's decided when writing the function
|
| + // position cache (see Parser::SkipLazyFunction).
|
| + log_->LogFunction(-1, start_position, body_end, formals->num_parameters(),
|
| + formals->function_length, has_duplicate_parameters,
|
| function_state_->materialized_literal_count(),
|
| function_state_->expected_property_count(), language_mode(),
|
| scope->uses_super_property(), scope->calls_eval());
|
|
|