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

Side by Side Diff: src/parser.cc

Issue 1421193006: Revert of Revert "Revert of [es6] Implement destructuring binding in try/catch" (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 1 month 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/ast-value-factory.h ('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 #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 1055 matching lines...) Expand 10 before | Expand all | Expand 10 after
1066 if (ok && is_strict(language_mode())) { 1066 if (ok && is_strict(language_mode())) {
1067 CheckStrictOctalLiteral(beg_pos, scanner()->location().end_pos, &ok); 1067 CheckStrictOctalLiteral(beg_pos, scanner()->location().end_pos, &ok);
1068 } 1068 }
1069 if (ok && is_sloppy(language_mode()) && allow_harmony_sloppy_function()) { 1069 if (ok && is_sloppy(language_mode()) && allow_harmony_sloppy_function()) {
1070 // TODO(littledan): Function bindings on the global object that modify 1070 // TODO(littledan): Function bindings on the global object that modify
1071 // pre-existing bindings should be made writable, enumerable and 1071 // pre-existing bindings should be made writable, enumerable and
1072 // nonconfigurable if possible, whereas this code will leave attributes 1072 // nonconfigurable if possible, whereas this code will leave attributes
1073 // unchanged if the property already exists. 1073 // unchanged if the property already exists.
1074 InsertSloppyBlockFunctionVarBindings(scope, &ok); 1074 InsertSloppyBlockFunctionVarBindings(scope, &ok);
1075 } 1075 }
1076 if (ok && (is_strict(language_mode()) || allow_harmony_sloppy() || 1076 if (ok && (is_strict(language_mode()) || allow_harmony_sloppy())) {
1077 allow_harmony_destructuring())) {
1078 CheckConflictingVarDeclarations(scope_, &ok); 1077 CheckConflictingVarDeclarations(scope_, &ok);
1079 } 1078 }
1080 1079
1081 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) { 1080 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) {
1082 if (body->length() != 1 || 1081 if (body->length() != 1 ||
1083 !body->at(0)->IsExpressionStatement() || 1082 !body->at(0)->IsExpressionStatement() ||
1084 !body->at(0)->AsExpressionStatement()-> 1083 !body->at(0)->AsExpressionStatement()->
1085 expression()->IsFunctionLiteral()) { 1084 expression()->IsFunctionLiteral()) {
1086 ReportMessage(MessageTemplate::kSingleFunctionLiteral); 1085 ReportMessage(MessageTemplate::kSingleFunctionLiteral);
1087 ok = false; 1086 ok = false;
(...skipping 2063 matching lines...) Expand 10 before | Expand all | Expand 10 after
3151 Token::Value tok = peek(); 3150 Token::Value tok = peek();
3152 if (tok != Token::CATCH && tok != Token::FINALLY) { 3151 if (tok != Token::CATCH && tok != Token::FINALLY) {
3153 ReportMessage(MessageTemplate::kNoCatchOrFinally); 3152 ReportMessage(MessageTemplate::kNoCatchOrFinally);
3154 *ok = false; 3153 *ok = false;
3155 return NULL; 3154 return NULL;
3156 } 3155 }
3157 3156
3158 Scope* catch_scope = NULL; 3157 Scope* catch_scope = NULL;
3159 Variable* catch_variable = NULL; 3158 Variable* catch_variable = NULL;
3160 Block* catch_block = NULL; 3159 Block* catch_block = NULL;
3160 const AstRawString* name = NULL;
3161 if (tok == Token::CATCH) { 3161 if (tok == Token::CATCH) {
3162 Consume(Token::CATCH); 3162 Consume(Token::CATCH);
3163 3163
3164 Expect(Token::LPAREN, CHECK_OK); 3164 Expect(Token::LPAREN, CHECK_OK);
3165 catch_scope = NewScope(scope_, CATCH_SCOPE); 3165 catch_scope = NewScope(scope_, CATCH_SCOPE);
3166 catch_scope->set_start_position(scanner()->location().beg_pos); 3166 catch_scope->set_start_position(scanner()->location().beg_pos);
3167 name = ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK);
3167 3168
3168 ExpressionClassifier pattern_classifier; 3169 Expect(Token::RPAREN, CHECK_OK);
3169 Expression* pattern = ParsePrimaryExpression(&pattern_classifier, CHECK_OK);
3170 ValidateBindingPattern(&pattern_classifier, CHECK_OK);
3171
3172 const AstRawString* name = ast_value_factory()->dot_catch_string();
3173 bool is_simple = pattern->IsVariableProxy();
3174 if (is_simple) {
3175 auto proxy = pattern->AsVariableProxy();
3176 scope_->RemoveUnresolved(proxy);
3177 name = proxy->raw_name();
3178 }
3179 3170
3180 catch_variable = catch_scope->DeclareLocal(name, VAR, kCreatedInitialized, 3171 catch_variable = catch_scope->DeclareLocal(name, VAR, kCreatedInitialized,
3181 Variable::NORMAL); 3172 Variable::NORMAL);
3182 3173 BlockState block_state(&scope_, catch_scope);
3183 Expect(Token::RPAREN, CHECK_OK); 3174 catch_block = ParseBlock(NULL, CHECK_OK);
3184
3185 {
3186 BlockState block_state(&scope_, catch_scope);
3187
3188 // TODO(adamk): Make a version of ParseScopedBlock that takes a scope and
3189 // a block.
3190 catch_block =
3191 factory()->NewBlock(nullptr, 16, false, RelocInfo::kNoPosition);
3192 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE);
3193
3194 block_scope->set_start_position(scanner()->location().beg_pos);
3195 {
3196 BlockState block_state(&scope_, block_scope);
3197 Target target(&this->target_stack_, catch_block);
3198
3199 if (!is_simple) {
3200 DeclarationDescriptor descriptor;
3201 descriptor.declaration_kind = DeclarationDescriptor::NORMAL;
3202 descriptor.parser = this;
3203 descriptor.declaration_scope = scope_;
3204 descriptor.scope = scope_;
3205 descriptor.hoist_scope = nullptr;
3206 descriptor.mode = LET;
3207 descriptor.is_const = false;
3208 descriptor.needs_init = true;
3209 descriptor.declaration_pos = pattern->position();
3210 descriptor.initialization_pos = pattern->position();
3211 descriptor.init_op = Token::INIT_LET;
3212
3213 DeclarationParsingResult::Declaration decl(
3214 pattern, pattern->position(),
3215 factory()->NewVariableProxy(catch_variable));
3216
3217 PatternRewriter::DeclareAndInitializeVariables(
3218 catch_block, &descriptor, &decl, nullptr, CHECK_OK);
3219 }
3220
3221 Expect(Token::LBRACE, CHECK_OK);
3222 while (peek() != Token::RBRACE) {
3223 Statement* stat = ParseStatementListItem(CHECK_OK);
3224 if (stat && !stat->IsEmpty()) {
3225 catch_block->statements()->Add(stat, zone());
3226 }
3227 }
3228 Consume(Token::RBRACE);
3229 }
3230 block_scope->set_end_position(scanner()->location().end_pos);
3231 block_scope = block_scope->FinalizeBlockScope();
3232 catch_block->set_scope(block_scope);
3233 }
3234 3175
3235 catch_scope->set_end_position(scanner()->location().end_pos); 3176 catch_scope->set_end_position(scanner()->location().end_pos);
3236 tok = peek(); 3177 tok = peek();
3237 } 3178 }
3238 3179
3239 Block* finally_block = NULL; 3180 Block* finally_block = NULL;
3240 DCHECK(tok == Token::FINALLY || catch_block != NULL); 3181 DCHECK(tok == Token::FINALLY || catch_block != NULL);
3241 if (tok == Token::FINALLY) { 3182 if (tok == Token::FINALLY) {
3242 Consume(Token::FINALLY); 3183 Consume(Token::FINALLY);
3243 finally_block = ParseBlock(NULL, CHECK_OK); 3184 finally_block = ParseBlock(NULL, CHECK_OK);
(...skipping 1181 matching lines...) Expand 10 before | Expand all | Expand 10 after
4425 ValidateFormalParameters(&formals_classifier, language_mode, 4366 ValidateFormalParameters(&formals_classifier, language_mode,
4426 allow_duplicate_parameters, CHECK_OK); 4367 allow_duplicate_parameters, CHECK_OK);
4427 4368
4428 if (is_strict(language_mode)) { 4369 if (is_strict(language_mode)) {
4429 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(), 4370 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(),
4430 CHECK_OK); 4371 CHECK_OK);
4431 } 4372 }
4432 if (is_sloppy(language_mode) && allow_harmony_sloppy_function()) { 4373 if (is_sloppy(language_mode) && allow_harmony_sloppy_function()) {
4433 InsertSloppyBlockFunctionVarBindings(scope, CHECK_OK); 4374 InsertSloppyBlockFunctionVarBindings(scope, CHECK_OK);
4434 } 4375 }
4435 if (is_strict(language_mode) || allow_harmony_sloppy() || 4376 if (is_strict(language_mode) || allow_harmony_sloppy()) {
4436 allow_harmony_destructuring()) {
4437 CheckConflictingVarDeclarations(scope, CHECK_OK); 4377 CheckConflictingVarDeclarations(scope, CHECK_OK);
4438 } 4378 }
4439 } 4379 }
4440 4380
4441 bool has_duplicate_parameters = 4381 bool has_duplicate_parameters =
4442 !formals_classifier.is_valid_formal_parameter_list_without_duplicates(); 4382 !formals_classifier.is_valid_formal_parameter_list_without_duplicates();
4443 FunctionLiteral::ParameterFlag duplicate_parameters = 4383 FunctionLiteral::ParameterFlag duplicate_parameters =
4444 has_duplicate_parameters ? FunctionLiteral::kHasDuplicateParameters 4384 has_duplicate_parameters ? FunctionLiteral::kHasDuplicateParameters
4445 : FunctionLiteral::kNoDuplicateParameters; 4385 : FunctionLiteral::kNoDuplicateParameters;
4446 4386
(...skipping 2003 matching lines...) Expand 10 before | Expand all | Expand 10 after
6450 6390
6451 Expression* Parser::SpreadCallNew(Expression* function, 6391 Expression* Parser::SpreadCallNew(Expression* function,
6452 ZoneList<v8::internal::Expression*>* args, 6392 ZoneList<v8::internal::Expression*>* args,
6453 int pos) { 6393 int pos) {
6454 args->InsertAt(0, function, zone()); 6394 args->InsertAt(0, function, zone());
6455 6395
6456 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); 6396 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos);
6457 } 6397 }
6458 } // namespace internal 6398 } // namespace internal
6459 } // namespace v8 6399 } // namespace v8
OLDNEW
« no previous file with comments | « src/ast-value-factory.h ('k') | src/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698