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

Side by Side Diff: src/preparser.h

Issue 1135243004: [es6] Support super.property in eval and arrow functions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Code review cleanup Created 5 years, 7 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/parser.cc ('k') | src/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_PREPARSER_H 5 #ifndef V8_PREPARSER_H
6 #define V8_PREPARSER_H 6 #define V8_PREPARSER_H
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/bailout-reason.h" 10 #include "src/bailout-reason.h"
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 } 332 }
333 ~ParsingModeScope() { 333 ~ParsingModeScope() {
334 parser_->mode_ = old_mode_; 334 parser_->mode_ = old_mode_;
335 } 335 }
336 336
337 private: 337 private:
338 ParserBase* parser_; 338 ParserBase* parser_;
339 Mode old_mode_; 339 Mode old_mode_;
340 }; 340 };
341 341
342 Scope* NewScope(Scope* parent, ScopeType scope_type, 342 Scope* NewScope(Scope* parent, ScopeType scope_type) {
343 FunctionKind kind = kNormalFunction) { 343 // Must always pass the function kind for FUNCTION_SCOPE and ARROW_SCOPE.
344 DCHECK(scope_type != FUNCTION_SCOPE);
345 DCHECK(scope_type != ARROW_SCOPE);
346 return NewScope(parent, scope_type, kNormalFunction);
347 }
348
349 Scope* NewScope(Scope* parent, ScopeType scope_type, FunctionKind kind) {
344 DCHECK(ast_value_factory()); 350 DCHECK(ast_value_factory());
345 DCHECK(scope_type != MODULE_SCOPE || allow_harmony_modules()); 351 DCHECK(scope_type != MODULE_SCOPE || allow_harmony_modules());
346 DCHECK((scope_type == FUNCTION_SCOPE && IsValidFunctionKind(kind)) || 352 DCHECK(scope_type != ARROW_SCOPE || IsArrowFunction(kind));
347 kind == kNormalFunction);
348 Scope* result = new (zone()) 353 Scope* result = new (zone())
349 Scope(zone(), parent, scope_type, ast_value_factory(), kind); 354 Scope(zone(), parent, scope_type, ast_value_factory(), kind);
350 result->Initialize(); 355 result->Initialize();
351 return result; 356 return result;
352 } 357 }
353 358
354 Scanner* scanner() const { return scanner_; } 359 Scanner* scanner() const { return scanner_; }
355 AstValueFactory* ast_value_factory() const { return ast_value_factory_; } 360 AstValueFactory* ast_value_factory() const { return ast_value_factory_; }
356 int position() { return scanner_->location().beg_pos; } 361 int position() { return scanner_->location().beg_pos; }
357 int peek_position() { return scanner_->peek_location().beg_pos; } 362 int peek_position() { return scanner_->peek_location().beg_pos; }
(...skipping 1346 matching lines...) Expand 10 before | Expand all | Expand 10 after
1704 return PreParserIdentifier::Default(); 1709 return PreParserIdentifier::Default();
1705 } 1710 }
1706 1711
1707 static PreParserExpression ThisExpression(Scope* scope, 1712 static PreParserExpression ThisExpression(Scope* scope,
1708 PreParserFactory* factory, 1713 PreParserFactory* factory,
1709 int pos) { 1714 int pos) {
1710 return PreParserExpression::This(); 1715 return PreParserExpression::This();
1711 } 1716 }
1712 1717
1713 static PreParserExpression SuperReference(Scope* scope, 1718 static PreParserExpression SuperReference(Scope* scope,
1714 PreParserFactory* factory) { 1719 PreParserFactory* factory,
1720 int pos) {
1715 return PreParserExpression::Default(); 1721 return PreParserExpression::Default();
1716 } 1722 }
1717 1723
1718 static PreParserExpression DefaultConstructor(bool call_super, Scope* scope, 1724 static PreParserExpression DefaultConstructor(bool call_super, Scope* scope,
1719 int pos, int end_pos) { 1725 int pos, int end_pos) {
1720 return PreParserExpression::Default(); 1726 return PreParserExpression::Default();
1721 } 1727 }
1722 1728
1723 static PreParserExpression ExpressionFromLiteral( 1729 static PreParserExpression ExpressionFromLiteral(
1724 Token::Value token, int pos, Scanner* scanner, 1730 Token::Value token, int pos, Scanner* scanner,
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
2386 if (!classifier->is_valid_binding_pattern()) { 2392 if (!classifier->is_valid_binding_pattern()) {
2387 ArrowFormalParametersUnexpectedToken(classifier); 2393 ArrowFormalParametersUnexpectedToken(classifier);
2388 } 2394 }
2389 BindingPatternUnexpectedToken(classifier); 2395 BindingPatternUnexpectedToken(classifier);
2390 Consume(Token::LPAREN); 2396 Consume(Token::LPAREN);
2391 if (allow_harmony_arrow_functions() && Check(Token::RPAREN)) { 2397 if (allow_harmony_arrow_functions() && Check(Token::RPAREN)) {
2392 // As a primary expression, the only thing that can follow "()" is "=>". 2398 // As a primary expression, the only thing that can follow "()" is "=>".
2393 classifier->RecordBindingPatternError(scanner()->location(), 2399 classifier->RecordBindingPatternError(scanner()->location(),
2394 MessageTemplate::kUnexpectedToken, 2400 MessageTemplate::kUnexpectedToken,
2395 Token::String(Token::RPAREN)); 2401 Token::String(Token::RPAREN));
2396 Scope* scope = this->NewScope(scope_, ARROW_SCOPE); 2402 Scope* scope =
2403 this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction);
2397 scope->set_start_position(beg_pos); 2404 scope->set_start_position(beg_pos);
2398 ExpressionClassifier args_classifier; 2405 ExpressionClassifier args_classifier;
2399 bool has_rest = false; 2406 bool has_rest = false;
2400 result = this->ParseArrowFunctionLiteral(scope, has_rest, 2407 result = this->ParseArrowFunctionLiteral(scope, has_rest,
2401 args_classifier, CHECK_OK); 2408 args_classifier, CHECK_OK);
2402 } else { 2409 } else {
2403 // Heuristically try to detect immediately called functions before 2410 // Heuristically try to detect immediately called functions before
2404 // seeing the call parentheses. 2411 // seeing the call parentheses.
2405 parenthesized_function_ = (peek() == Token::FUNCTION); 2412 parenthesized_function_ = (peek() == Token::FUNCTION);
2406 result = this->ParseExpression(true, classifier, CHECK_OK); 2413 result = this->ParseExpression(true, classifier, CHECK_OK);
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
2913 accept_IN, &arrow_formals_classifier, CHECK_OK); 2920 accept_IN, &arrow_formals_classifier, CHECK_OK);
2914 classifier->Accumulate(arrow_formals_classifier); 2921 classifier->Accumulate(arrow_formals_classifier);
2915 2922
2916 if (allow_harmony_arrow_functions() && peek() == Token::ARROW) { 2923 if (allow_harmony_arrow_functions() && peek() == Token::ARROW) {
2917 checkpoint.Restore(); 2924 checkpoint.Restore();
2918 BindingPatternUnexpectedToken(classifier); 2925 BindingPatternUnexpectedToken(classifier);
2919 ValidateArrowFormalParameters(&arrow_formals_classifier, expression, 2926 ValidateArrowFormalParameters(&arrow_formals_classifier, expression,
2920 CHECK_OK); 2927 CHECK_OK);
2921 Scanner::Location loc(lhs_location.beg_pos, scanner()->location().end_pos); 2928 Scanner::Location loc(lhs_location.beg_pos, scanner()->location().end_pos);
2922 bool has_rest = false; 2929 bool has_rest = false;
2923 Scope* scope = this->NewScope(scope_, ARROW_SCOPE); 2930 Scope* scope =
2931 this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction);
2924 scope->set_start_position(lhs_location.beg_pos); 2932 scope->set_start_position(lhs_location.beg_pos);
2925 Scanner::Location duplicate_loc = Scanner::Location::invalid(); 2933 Scanner::Location duplicate_loc = Scanner::Location::invalid();
2926 this->ParseArrowFunctionFormalParameters(scope, expression, loc, &has_rest, 2934 this->ParseArrowFunctionFormalParameters(scope, expression, loc, &has_rest,
2927 &duplicate_loc, CHECK_OK); 2935 &duplicate_loc, CHECK_OK);
2928 if (duplicate_loc.IsValid()) { 2936 if (duplicate_loc.IsValid()) {
2929 arrow_formals_classifier.RecordDuplicateFormalParameterError( 2937 arrow_formals_classifier.RecordDuplicateFormalParameterError(
2930 duplicate_loc); 2938 duplicate_loc);
2931 } 2939 }
2932 expression = this->ParseArrowFunctionLiteral( 2940 expression = this->ParseArrowFunctionLiteral(
2933 scope, has_rest, arrow_formals_classifier, CHECK_OK); 2941 scope, has_rest, arrow_formals_classifier, CHECK_OK);
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
3500 typename ParserBase<Traits>::ExpressionT 3508 typename ParserBase<Traits>::ExpressionT
3501 ParserBase<Traits>::ParseStrongSuperCallExpression( 3509 ParserBase<Traits>::ParseStrongSuperCallExpression(
3502 ExpressionClassifier* classifier, bool* ok) { 3510 ExpressionClassifier* classifier, bool* ok) {
3503 // SuperCallExpression :: (strong mode) 3511 // SuperCallExpression :: (strong mode)
3504 // 'super' '(' ExpressionList ')' 3512 // 'super' '(' ExpressionList ')'
3505 BindingPatternUnexpectedToken(classifier); 3513 BindingPatternUnexpectedToken(classifier);
3506 3514
3507 Consume(Token::SUPER); 3515 Consume(Token::SUPER);
3508 int pos = position(); 3516 int pos = position();
3509 Scanner::Location super_loc = scanner()->location(); 3517 Scanner::Location super_loc = scanner()->location();
3510 ExpressionT expr = this->SuperReference(scope_, factory()); 3518 ExpressionT expr = this->SuperReference(scope_, factory(), pos);
3511 3519
3512 if (peek() != Token::LPAREN) { 3520 if (peek() != Token::LPAREN) {
3513 ReportMessage(MessageTemplate::kStrongConstructorSuper); 3521 ReportMessage(MessageTemplate::kStrongConstructorSuper);
3514 *ok = false; 3522 *ok = false;
3515 return this->EmptyExpression(); 3523 return this->EmptyExpression();
3516 } 3524 }
3517 3525
3518 Scanner::Location spread_pos; 3526 Scanner::Location spread_pos;
3519 typename Traits::Type::ExpressionList args = 3527 typename Traits::Type::ExpressionList args =
3520 ParseArguments(&spread_pos, classifier, CHECK_OK); 3528 ParseArguments(&spread_pos, classifier, CHECK_OK);
(...skipping 28 matching lines...) Expand all
3549 return factory()->NewCall(expr, args, pos); 3557 return factory()->NewCall(expr, args, pos);
3550 } 3558 }
3551 } 3559 }
3552 3560
3553 3561
3554 template <class Traits> 3562 template <class Traits>
3555 typename ParserBase<Traits>::ExpressionT 3563 typename ParserBase<Traits>::ExpressionT
3556 ParserBase<Traits>::ParseSuperExpression(bool is_new, 3564 ParserBase<Traits>::ParseSuperExpression(bool is_new,
3557 ExpressionClassifier* classifier, 3565 ExpressionClassifier* classifier,
3558 bool* ok) { 3566 bool* ok) {
3567 int pos = position();
3559 Expect(Token::SUPER, CHECK_OK); 3568 Expect(Token::SUPER, CHECK_OK);
3560 3569
3561 // TODO(wingo): Does this actually work with lazily compiled arrows? 3570 Scope* scope = scope_->DeclarationScope();
3562 FunctionState* function_state = function_state_; 3571
3563 while (IsArrowFunction(function_state->kind())) { 3572 while (scope->is_eval_scope() || scope->is_arrow_scope()) {
3564 function_state = function_state->outer(); 3573 scope = scope->outer_scope();
3574 DCHECK_NOT_NULL(scope);
3575 scope = scope->DeclarationScope();
3565 } 3576 }
3566 // TODO(arv): Handle eval scopes similarly.
3567 3577
3568 FunctionKind kind = function_state->kind(); 3578 FunctionKind kind = scope->function_kind();
3569 if (IsConciseMethod(kind) || IsAccessorFunction(kind) || 3579 if (IsConciseMethod(kind) || IsAccessorFunction(kind) ||
3570 i::IsConstructor(kind)) { 3580 i::IsConstructor(kind)) {
3571 if (peek() == Token::PERIOD || peek() == Token::LBRACK) { 3581 if (peek() == Token::PERIOD || peek() == Token::LBRACK) {
3572 scope_->RecordSuperPropertyUsage(); 3582 scope->RecordSuperPropertyUsage();
3573 return this->SuperReference(scope_, factory()); 3583 return this->SuperReference(scope_, factory(), pos);
3574 } 3584 }
3575 // new super() is never allowed. 3585 // new super() is never allowed.
3576 // super() is only allowed in derived constructor 3586 // super() is only allowed in derived constructor
3577 if (!is_new && peek() == Token::LPAREN && IsSubclassConstructor(kind)) { 3587 if (!is_new && peek() == Token::LPAREN && IsSubclassConstructor(kind)) {
3578 if (is_strong(language_mode())) { 3588 if (is_strong(language_mode())) {
3579 // Super calls in strong mode are parsed separately. 3589 // Super calls in strong mode are parsed separately.
3580 ReportMessageAt(scanner()->location(), 3590 ReportMessageAt(scanner()->location(),
3581 MessageTemplate::kStrongConstructorSuper); 3591 MessageTemplate::kStrongConstructorSuper);
3582 *ok = false; 3592 *ok = false;
3583 return this->EmptyExpression(); 3593 return this->EmptyExpression();
3584 } 3594 }
3585 function_state->set_super_location(scanner()->location()); 3595 // TODO(rossberg): This might not be the correct FunctionState for the
3586 return this->SuperReference(scope_, factory()); 3596 // method here.
3597 function_state_->set_super_location(scanner()->location());
3598 return this->SuperReference(scope_, factory(), pos);
3587 } 3599 }
3588 } 3600 }
3589 3601
3590 ReportMessageAt(scanner()->location(), MessageTemplate::kUnexpectedSuper); 3602 ReportMessageAt(scanner()->location(), MessageTemplate::kUnexpectedSuper);
3591 *ok = false; 3603 *ok = false;
3592 return this->EmptyExpression(); 3604 return this->EmptyExpression();
3593 } 3605 }
3594 3606
3595 3607
3596 template <class Traits> 3608 template <class Traits>
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
4027 *ok = false; 4039 *ok = false;
4028 return; 4040 return;
4029 } 4041 }
4030 has_seen_constructor_ = true; 4042 has_seen_constructor_ = true;
4031 return; 4043 return;
4032 } 4044 }
4033 } 4045 }
4034 } } // v8::internal 4046 } } // v8::internal
4035 4047
4036 #endif // V8_PREPARSER_H 4048 #endif // V8_PREPARSER_H
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | src/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698