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

Side by Side Diff: src/parser.cc

Issue 1409093005: Re-re-land "[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 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 if (ok && is_strict(language_mode())) { 1065 if (ok && is_strict(language_mode())) {
1066 CheckStrictOctalLiteral(beg_pos, scanner()->location().end_pos, &ok); 1066 CheckStrictOctalLiteral(beg_pos, scanner()->location().end_pos, &ok);
1067 } 1067 }
1068 if (ok && is_sloppy(language_mode()) && allow_harmony_sloppy_function()) { 1068 if (ok && is_sloppy(language_mode()) && allow_harmony_sloppy_function()) {
1069 // TODO(littledan): Function bindings on the global object that modify 1069 // TODO(littledan): Function bindings on the global object that modify
1070 // pre-existing bindings should be made writable, enumerable and 1070 // pre-existing bindings should be made writable, enumerable and
1071 // nonconfigurable if possible, whereas this code will leave attributes 1071 // nonconfigurable if possible, whereas this code will leave attributes
1072 // unchanged if the property already exists. 1072 // unchanged if the property already exists.
1073 InsertSloppyBlockFunctionVarBindings(scope, &ok); 1073 InsertSloppyBlockFunctionVarBindings(scope, &ok);
1074 } 1074 }
1075 if (ok && (is_strict(language_mode()) || allow_harmony_sloppy())) { 1075 if (ok && (is_strict(language_mode()) || allow_harmony_sloppy() ||
1076 allow_harmony_destructuring())) {
1076 CheckConflictingVarDeclarations(scope_, &ok); 1077 CheckConflictingVarDeclarations(scope_, &ok);
1077 } 1078 }
1078 1079
1079 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) { 1080 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) {
1080 if (body->length() != 1 || 1081 if (body->length() != 1 ||
1081 !body->at(0)->IsExpressionStatement() || 1082 !body->at(0)->IsExpressionStatement() ||
1082 !body->at(0)->AsExpressionStatement()-> 1083 !body->at(0)->AsExpressionStatement()->
1083 expression()->IsFunctionLiteral()) { 1084 expression()->IsFunctionLiteral()) {
1084 ReportMessage(MessageTemplate::kSingleFunctionLiteral); 1085 ReportMessage(MessageTemplate::kSingleFunctionLiteral);
1085 ok = false; 1086 ok = false;
(...skipping 2063 matching lines...) Expand 10 before | Expand all | Expand 10 after
3149 Token::Value tok = peek(); 3150 Token::Value tok = peek();
3150 if (tok != Token::CATCH && tok != Token::FINALLY) { 3151 if (tok != Token::CATCH && tok != Token::FINALLY) {
3151 ReportMessage(MessageTemplate::kNoCatchOrFinally); 3152 ReportMessage(MessageTemplate::kNoCatchOrFinally);
3152 *ok = false; 3153 *ok = false;
3153 return NULL; 3154 return NULL;
3154 } 3155 }
3155 3156
3156 Scope* catch_scope = NULL; 3157 Scope* catch_scope = NULL;
3157 Variable* catch_variable = NULL; 3158 Variable* catch_variable = NULL;
3158 Block* catch_block = NULL; 3159 Block* catch_block = NULL;
3159 const AstRawString* name = NULL;
3160 if (tok == Token::CATCH) { 3160 if (tok == Token::CATCH) {
3161 Consume(Token::CATCH); 3161 Consume(Token::CATCH);
3162 3162
3163 Expect(Token::LPAREN, CHECK_OK); 3163 Expect(Token::LPAREN, CHECK_OK);
3164 catch_scope = NewScope(scope_, CATCH_SCOPE); 3164 catch_scope = NewScope(scope_, CATCH_SCOPE);
3165 catch_scope->set_start_position(scanner()->location().beg_pos); 3165 catch_scope->set_start_position(scanner()->location().beg_pos);
3166 name = ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK); 3166
3167 ExpressionClassifier pattern_classifier;
3168 Expression* pattern = ParsePrimaryExpression(&pattern_classifier, CHECK_OK);
3169 ValidateBindingPattern(&pattern_classifier, CHECK_OK);
3170
3171 const AstRawString* name = ast_value_factory()->dot_catch_string();
3172 bool is_simple = pattern->IsVariableProxy();
3173 if (is_simple) {
3174 auto proxy = pattern->AsVariableProxy();
3175 scope_->RemoveUnresolved(proxy);
3176 name = proxy->raw_name();
3177 }
3178
3179 catch_variable = catch_scope->DeclareLocal(name, VAR, kCreatedInitialized,
3180 Variable::NORMAL);
3167 3181
3168 Expect(Token::RPAREN, CHECK_OK); 3182 Expect(Token::RPAREN, CHECK_OK);
3169 3183
3170 catch_variable = catch_scope->DeclareLocal(name, VAR, kCreatedInitialized, 3184 {
3171 Variable::NORMAL); 3185 BlockState block_state(&scope_, catch_scope);
3172 BlockState block_state(&scope_, catch_scope); 3186
3173 catch_block = ParseBlock(NULL, CHECK_OK); 3187 // TODO(adamk): Make a version of ParseScopedBlock that takes a scope and
3188 // a block.
3189 catch_block =
3190 factory()->NewBlock(nullptr, 16, false, RelocInfo::kNoPosition);
3191 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE);
3192
3193 block_scope->set_start_position(scanner()->location().beg_pos);
3194 {
3195 BlockState block_state(&scope_, block_scope);
3196 Target target(&this->target_stack_, catch_block);
3197
3198 if (!is_simple) {
3199 DeclarationDescriptor descriptor;
3200 descriptor.declaration_kind = DeclarationDescriptor::NORMAL;
3201 descriptor.parser = this;
3202 descriptor.declaration_scope = scope_;
3203 descriptor.scope = scope_;
3204 descriptor.hoist_scope = nullptr;
3205 descriptor.mode = LET;
3206 descriptor.is_const = false;
3207 descriptor.needs_init = true;
3208 descriptor.declaration_pos = pattern->position();
3209 descriptor.initialization_pos = pattern->position();
3210 descriptor.init_op = Token::INIT_LET;
3211
3212 DeclarationParsingResult::Declaration decl(
3213 pattern, pattern->position(),
3214 factory()->NewVariableProxy(catch_variable));
3215
3216 PatternRewriter::DeclareAndInitializeVariables(
3217 catch_block, &descriptor, &decl, nullptr, CHECK_OK);
3218 }
3219
3220 Expect(Token::LBRACE, CHECK_OK);
3221 while (peek() != Token::RBRACE) {
3222 Statement* stat = ParseStatementListItem(CHECK_OK);
3223 if (stat && !stat->IsEmpty()) {
3224 catch_block->statements()->Add(stat, zone());
3225 }
3226 }
3227 Consume(Token::RBRACE);
3228 }
3229 block_scope->set_end_position(scanner()->location().end_pos);
3230 block_scope = block_scope->FinalizeBlockScope();
3231 catch_block->set_scope(block_scope);
3232 }
3174 3233
3175 catch_scope->set_end_position(scanner()->location().end_pos); 3234 catch_scope->set_end_position(scanner()->location().end_pos);
3176 tok = peek(); 3235 tok = peek();
3177 } 3236 }
3178 3237
3179 Block* finally_block = NULL; 3238 Block* finally_block = NULL;
3180 DCHECK(tok == Token::FINALLY || catch_block != NULL); 3239 DCHECK(tok == Token::FINALLY || catch_block != NULL);
3181 if (tok == Token::FINALLY) { 3240 if (tok == Token::FINALLY) {
3182 Consume(Token::FINALLY); 3241 Consume(Token::FINALLY);
3183 finally_block = ParseBlock(NULL, CHECK_OK); 3242 finally_block = ParseBlock(NULL, CHECK_OK);
(...skipping 1179 matching lines...) Expand 10 before | Expand all | Expand 10 after
4363 ValidateFormalParameters(&formals_classifier, language_mode, 4422 ValidateFormalParameters(&formals_classifier, language_mode,
4364 allow_duplicate_parameters, CHECK_OK); 4423 allow_duplicate_parameters, CHECK_OK);
4365 4424
4366 if (is_strict(language_mode)) { 4425 if (is_strict(language_mode)) {
4367 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(), 4426 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(),
4368 CHECK_OK); 4427 CHECK_OK);
4369 } 4428 }
4370 if (is_sloppy(language_mode) && allow_harmony_sloppy_function()) { 4429 if (is_sloppy(language_mode) && allow_harmony_sloppy_function()) {
4371 InsertSloppyBlockFunctionVarBindings(scope, CHECK_OK); 4430 InsertSloppyBlockFunctionVarBindings(scope, CHECK_OK);
4372 } 4431 }
4373 if (is_strict(language_mode) || allow_harmony_sloppy()) { 4432 if (is_strict(language_mode) || allow_harmony_sloppy() ||
4433 allow_harmony_destructuring()) {
4374 CheckConflictingVarDeclarations(scope, CHECK_OK); 4434 CheckConflictingVarDeclarations(scope, CHECK_OK);
4375 } 4435 }
4376 } 4436 }
4377 4437
4378 bool has_duplicate_parameters = 4438 bool has_duplicate_parameters =
4379 !formals_classifier.is_valid_formal_parameter_list_without_duplicates(); 4439 !formals_classifier.is_valid_formal_parameter_list_without_duplicates();
4380 FunctionLiteral::ParameterFlag duplicate_parameters = 4440 FunctionLiteral::ParameterFlag duplicate_parameters =
4381 has_duplicate_parameters ? FunctionLiteral::kHasDuplicateParameters 4441 has_duplicate_parameters ? FunctionLiteral::kHasDuplicateParameters
4382 : FunctionLiteral::kNoDuplicateParameters; 4442 : FunctionLiteral::kNoDuplicateParameters;
4383 4443
(...skipping 1982 matching lines...) Expand 10 before | Expand all | Expand 10 after
6366 6426
6367 Expression* Parser::SpreadCallNew(Expression* function, 6427 Expression* Parser::SpreadCallNew(Expression* function,
6368 ZoneList<v8::internal::Expression*>* args, 6428 ZoneList<v8::internal::Expression*>* args,
6369 int pos) { 6429 int pos) {
6370 args->InsertAt(0, function, zone()); 6430 args->InsertAt(0, function, zone());
6371 6431
6372 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); 6432 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos);
6373 } 6433 }
6374 } // namespace internal 6434 } // namespace internal
6375 } // namespace v8 6435 } // 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