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

Side by Side Diff: src/preparser.h

Issue 1244423003: [es6] Fix function context check for super and new.target (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Comment; added test for super calls Created 5 years, 5 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 | « no previous file | src/scopes.h » ('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 3486 matching lines...) Expand 10 before | Expand all | Expand 10 after
3497 3497
3498 3498
3499 template <class Traits> 3499 template <class Traits>
3500 typename ParserBase<Traits>::ExpressionT 3500 typename ParserBase<Traits>::ExpressionT
3501 ParserBase<Traits>::ParseSuperExpression(bool is_new, 3501 ParserBase<Traits>::ParseSuperExpression(bool is_new,
3502 ExpressionClassifier* classifier, 3502 ExpressionClassifier* classifier,
3503 bool* ok) { 3503 bool* ok) {
3504 int pos = position(); 3504 int pos = position();
3505 Expect(Token::SUPER, CHECK_OK); 3505 Expect(Token::SUPER, CHECK_OK);
3506 3506
3507 Scope* scope = scope_->DeclarationScope(); 3507 Scope* scope = scope_->ReceiverScope();
3508 while (scope->is_eval_scope() || scope->is_arrow_scope()) {
3509 scope = scope->outer_scope();
3510 DCHECK_NOT_NULL(scope);
3511 scope = scope->DeclarationScope();
3512 }
3513
3514 FunctionKind kind = scope->function_kind(); 3508 FunctionKind kind = scope->function_kind();
3515 if (IsConciseMethod(kind) || IsAccessorFunction(kind) || 3509 if (IsConciseMethod(kind) || IsAccessorFunction(kind) ||
3516 i::IsConstructor(kind)) { 3510 i::IsConstructor(kind)) {
3517 if (peek() == Token::PERIOD || peek() == Token::LBRACK) { 3511 if (peek() == Token::PERIOD || peek() == Token::LBRACK) {
3518 scope->RecordSuperPropertyUsage(); 3512 scope->RecordSuperPropertyUsage();
3519 return this->SuperPropertyReference(scope_, factory(), pos); 3513 return this->SuperPropertyReference(scope_, factory(), pos);
3520 } 3514 }
3521 // new super() is never allowed. 3515 // new super() is never allowed.
3522 // super() is only allowed in derived constructor 3516 // super() is only allowed in derived constructor
3523 if (!is_new && peek() == Token::LPAREN && IsSubclassConstructor(kind)) { 3517 if (!is_new && peek() == Token::LPAREN && IsSubclassConstructor(kind)) {
(...skipping 17 matching lines...) Expand all
3541 } 3535 }
3542 3536
3543 3537
3544 template <class Traits> 3538 template <class Traits>
3545 typename ParserBase<Traits>::ExpressionT 3539 typename ParserBase<Traits>::ExpressionT
3546 ParserBase<Traits>::ParseNewTargetExpression(bool* ok) { 3540 ParserBase<Traits>::ParseNewTargetExpression(bool* ok) {
3547 int pos = position(); 3541 int pos = position();
3548 Consume(Token::PERIOD); 3542 Consume(Token::PERIOD);
3549 ExpectContextualKeyword(CStrVector("target"), CHECK_OK); 3543 ExpectContextualKeyword(CStrVector("target"), CHECK_OK);
3550 3544
3551 Scope* scope = scope_->DeclarationScope(); 3545 if (!scope_->ReceiverScope()->is_function_scope()) {
3552 while (scope->is_eval_scope() || scope->is_arrow_scope()) {
3553 scope = scope->outer_scope();
3554 DCHECK_NOT_NULL(scope);
3555 scope = scope->DeclarationScope();
3556 }
3557
3558 if (!scope->is_function_scope()) {
3559 ReportMessageAt(scanner()->location(), 3546 ReportMessageAt(scanner()->location(),
3560 MessageTemplate::kUnexpectedNewTarget); 3547 MessageTemplate::kUnexpectedNewTarget);
3561 *ok = false; 3548 *ok = false;
3562 return this->EmptyExpression(); 3549 return this->EmptyExpression();
3563 } 3550 }
3564 3551
3565 return this->NewTargetExpression(scope_, factory(), pos); 3552 return this->NewTargetExpression(scope_, factory(), pos);
3566 } 3553 }
3567 3554
3568 3555
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
4025 *ok = false; 4012 *ok = false;
4026 return; 4013 return;
4027 } 4014 }
4028 has_seen_constructor_ = true; 4015 has_seen_constructor_ = true;
4029 return; 4016 return;
4030 } 4017 }
4031 } 4018 }
4032 } } // v8::internal 4019 } } // v8::internal
4033 4020
4034 #endif // V8_PREPARSER_H 4021 #endif // V8_PREPARSER_H
OLDNEW
« no previous file with comments | « no previous file | src/scopes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698