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

Side by Side Diff: src/parser.cc

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

Powered by Google App Engine
This is Rietveld 408576698