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

Side by Side Diff: src/parser.cc

Issue 1360403002: Revert of [es6] Introduce spec compliant IsConstructor. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 3 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/objects-inl.h ('k') | src/preparser.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 #include "src/parser.h" 5 #include "src/parser.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/ast-literal-reindexer.h" 9 #include "src/ast-literal-reindexer.h"
10 #include "src/bailout-reason.h" 10 #include "src/bailout-reason.h"
(...skipping 1262 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 while (peek() != end_token) { 1273 while (peek() != end_token) {
1274 if (directive_prologue && peek() != Token::STRING) { 1274 if (directive_prologue && peek() != Token::STRING) {
1275 directive_prologue = false; 1275 directive_prologue = false;
1276 } 1276 }
1277 1277
1278 Scanner::Location token_loc = scanner()->peek_location(); 1278 Scanner::Location token_loc = scanner()->peek_location();
1279 Scanner::Location old_this_loc = function_state_->this_location(); 1279 Scanner::Location old_this_loc = function_state_->this_location();
1280 Scanner::Location old_super_loc = function_state_->super_location(); 1280 Scanner::Location old_super_loc = function_state_->super_location();
1281 Statement* stat = ParseStatementListItem(CHECK_OK); 1281 Statement* stat = ParseStatementListItem(CHECK_OK);
1282 1282
1283 if (is_strong(language_mode()) && scope_->is_function_scope() && 1283 if (is_strong(language_mode()) &&
1284 IsClassConstructor(function_state_->kind())) { 1284 scope_->is_function_scope() &&
1285 i::IsConstructor(function_state_->kind())) {
1285 Scanner::Location this_loc = function_state_->this_location(); 1286 Scanner::Location this_loc = function_state_->this_location();
1286 Scanner::Location super_loc = function_state_->super_location(); 1287 Scanner::Location super_loc = function_state_->super_location();
1287 if (this_loc.beg_pos != old_this_loc.beg_pos && 1288 if (this_loc.beg_pos != old_this_loc.beg_pos &&
1288 this_loc.beg_pos != token_loc.beg_pos) { 1289 this_loc.beg_pos != token_loc.beg_pos) {
1289 ReportMessageAt(this_loc, MessageTemplate::kStrongConstructorThis); 1290 ReportMessageAt(this_loc, MessageTemplate::kStrongConstructorThis);
1290 *ok = false; 1291 *ok = false;
1291 return nullptr; 1292 return nullptr;
1292 } 1293 }
1293 if (super_loc.beg_pos != old_super_loc.beg_pos && 1294 if (super_loc.beg_pos != old_super_loc.beg_pos &&
1294 super_loc.beg_pos != token_loc.beg_pos) { 1295 super_loc.beg_pos != token_loc.beg_pos) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1328 // Strong mode implies strict mode. If there are several "use strict" 1329 // Strong mode implies strict mode. If there are several "use strict"
1329 // / "use strong" directives, do the strict mode changes only once. 1330 // / "use strong" directives, do the strict mode changes only once.
1330 if (is_sloppy(scope_->language_mode())) { 1331 if (is_sloppy(scope_->language_mode())) {
1331 scope_->SetLanguageMode( 1332 scope_->SetLanguageMode(
1332 static_cast<LanguageMode>(scope_->language_mode() | STRICT)); 1333 static_cast<LanguageMode>(scope_->language_mode() | STRICT));
1333 } 1334 }
1334 1335
1335 if (use_strong_found) { 1336 if (use_strong_found) {
1336 scope_->SetLanguageMode( 1337 scope_->SetLanguageMode(
1337 static_cast<LanguageMode>(scope_->language_mode() | STRONG)); 1338 static_cast<LanguageMode>(scope_->language_mode() | STRONG));
1338 if (IsClassConstructor(function_state_->kind())) { 1339 if (i::IsConstructor(function_state_->kind())) {
1339 // "use strong" cannot occur in a class constructor body, to avoid 1340 // "use strong" cannot occur in a class constructor body, to avoid
1340 // unintuitive strong class object semantics. 1341 // unintuitive strong class object semantics.
1341 ParserTraits::ReportMessageAt( 1342 ParserTraits::ReportMessageAt(
1342 token_loc, MessageTemplate::kStrongConstructorDirective); 1343 token_loc, MessageTemplate::kStrongConstructorDirective);
1343 *ok = false; 1344 *ok = false;
1344 return nullptr; 1345 return nullptr;
1345 } 1346 }
1346 } 1347 }
1347 if (!scope_->HasSimpleParameters()) { 1348 if (!scope_->HasSimpleParameters()) {
1348 // TC39 deemed "use strict" directives to be an error when occurring 1349 // TC39 deemed "use strict" directives to be an error when occurring
(...skipping 1285 matching lines...) Expand 10 before | Expand all | Expand 10 after
2634 case Token::CLASS: 2635 case Token::CLASS:
2635 ReportUnexpectedToken(Next()); 2636 ReportUnexpectedToken(Next());
2636 *ok = false; 2637 *ok = false;
2637 return nullptr; 2638 return nullptr;
2638 2639
2639 case Token::THIS: 2640 case Token::THIS:
2640 if (!FLAG_strong_this) break; 2641 if (!FLAG_strong_this) break;
2641 // Fall through. 2642 // Fall through.
2642 case Token::SUPER: 2643 case Token::SUPER:
2643 if (is_strong(language_mode()) && 2644 if (is_strong(language_mode()) &&
2644 IsClassConstructor(function_state_->kind())) { 2645 i::IsConstructor(function_state_->kind())) {
2645 bool is_this = peek() == Token::THIS; 2646 bool is_this = peek() == Token::THIS;
2646 Expression* expr; 2647 Expression* expr;
2647 ExpressionClassifier classifier; 2648 ExpressionClassifier classifier;
2648 if (is_this) { 2649 if (is_this) {
2649 expr = ParseStrongInitializationExpression(&classifier, CHECK_OK); 2650 expr = ParseStrongInitializationExpression(&classifier, CHECK_OK);
2650 } else { 2651 } else {
2651 expr = ParseStrongSuperCallExpression(&classifier, CHECK_OK); 2652 expr = ParseStrongSuperCallExpression(&classifier, CHECK_OK);
2652 } 2653 }
2653 ValidateExpression(&classifier, CHECK_OK); 2654 ValidateExpression(&classifier, CHECK_OK);
2654 switch (peek()) { 2655 switch (peek()) {
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
2841 tok == Token::SEMICOLON || 2842 tok == Token::SEMICOLON ||
2842 tok == Token::RBRACE || 2843 tok == Token::RBRACE ||
2843 tok == Token::EOS) { 2844 tok == Token::EOS) {
2844 if (IsSubclassConstructor(function_state_->kind())) { 2845 if (IsSubclassConstructor(function_state_->kind())) {
2845 return_value = ThisExpression(scope_, factory(), loc.beg_pos); 2846 return_value = ThisExpression(scope_, factory(), loc.beg_pos);
2846 } else { 2847 } else {
2847 return_value = GetLiteralUndefined(position()); 2848 return_value = GetLiteralUndefined(position());
2848 } 2849 }
2849 } else { 2850 } else {
2850 if (is_strong(language_mode()) && 2851 if (is_strong(language_mode()) &&
2851 IsClassConstructor(function_state_->kind())) { 2852 i::IsConstructor(function_state_->kind())) {
2852 int pos = peek_position(); 2853 int pos = peek_position();
2853 ReportMessageAt(Scanner::Location(pos, pos + 1), 2854 ReportMessageAt(Scanner::Location(pos, pos + 1),
2854 MessageTemplate::kStrongConstructorReturnValue); 2855 MessageTemplate::kStrongConstructorReturnValue);
2855 *ok = false; 2856 *ok = false;
2856 return NULL; 2857 return NULL;
2857 } 2858 }
2858 2859
2859 int pos = peek_position(); 2860 int pos = peek_position();
2860 return_value = ParseExpression(true, CHECK_OK); 2861 return_value = ParseExpression(true, CHECK_OK);
2861 2862
(...skipping 1734 matching lines...) Expand 10 before | Expand all | Expand 10 after
4596 // declaration to the body of the function with the name of the 4597 // declaration to the body of the function with the name of the
4597 // function and let it refer to the function itself (closure). 4598 // function and let it refer to the function itself (closure).
4598 // Not having parsed the function body, the language mode may still change, 4599 // Not having parsed the function body, the language mode may still change,
4599 // so we reserve a spot and create the actual const assignment later. 4600 // so we reserve a spot and create the actual const assignment later.
4600 DCHECK_EQ(kFunctionNameAssignmentIndex, result->length()); 4601 DCHECK_EQ(kFunctionNameAssignmentIndex, result->length());
4601 result->Add(NULL, zone()); 4602 result->Add(NULL, zone());
4602 } 4603 }
4603 4604
4604 // For concise constructors, check that they are constructed, 4605 // For concise constructors, check that they are constructed,
4605 // not called. 4606 // not called.
4606 if (IsClassConstructor(kind)) { 4607 if (i::IsConstructor(kind)) {
4607 AddAssertIsConstruct(result, pos); 4608 AddAssertIsConstruct(result, pos);
4608 } 4609 }
4609 4610
4610 ZoneList<Statement*>* body = result; 4611 ZoneList<Statement*>* body = result;
4611 Scope* inner_scope = scope_; 4612 Scope* inner_scope = scope_;
4612 Block* inner_block = nullptr; 4613 Block* inner_block = nullptr;
4613 if (!parameters.is_simple) { 4614 if (!parameters.is_simple) {
4614 inner_scope = NewScope(scope_, BLOCK_SCOPE); 4615 inner_scope = NewScope(scope_, BLOCK_SCOPE);
4615 inner_scope->set_is_declaration_scope(); 4616 inner_scope->set_is_declaration_scope();
4616 inner_scope->set_start_position(scanner()->location().beg_pos); 4617 inner_scope->set_start_position(scanner()->location().beg_pos);
(...skipping 1672 matching lines...) Expand 10 before | Expand all | Expand 10 after
6289 6290
6290 Expression* Parser::SpreadCallNew(Expression* function, 6291 Expression* Parser::SpreadCallNew(Expression* function,
6291 ZoneList<v8::internal::Expression*>* args, 6292 ZoneList<v8::internal::Expression*>* args,
6292 int pos) { 6293 int pos) {
6293 args->InsertAt(0, function, zone()); 6294 args->InsertAt(0, function, zone());
6294 6295
6295 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); 6296 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos);
6296 } 6297 }
6297 } // namespace internal 6298 } // namespace internal
6298 } // namespace v8 6299 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects-inl.h ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698