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

Side by Side Diff: src/parser.cc

Issue 1234213004: [parser] use-strict directives in function body affect init block (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix arrow-function failures 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 | « src/parser.h ('k') | test/mjsunit/strong/destructuring.js » ('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/v8.h" 5 #include "src/v8.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 4289 matching lines...) Expand 10 before | Expand all | Expand 10 after
4300 RelocInfo::kNoPosition); 4300 RelocInfo::kNoPosition);
4301 IfStatement* if_statement = factory()->NewIfStatement( 4301 IfStatement* if_statement = factory()->NewIfStatement(
4302 condition, factory()->NewExpressionStatement(throw_type_error, 4302 condition, factory()->NewExpressionStatement(throw_type_error,
4303 RelocInfo::kNoPosition), 4303 RelocInfo::kNoPosition),
4304 factory()->NewEmptyStatement(RelocInfo::kNoPosition), 4304 factory()->NewEmptyStatement(RelocInfo::kNoPosition),
4305 RelocInfo::kNoPosition); 4305 RelocInfo::kNoPosition);
4306 return if_statement; 4306 return if_statement;
4307 } 4307 }
4308 4308
4309 4309
4310 bool Parser::IsSimpleParameterList(
4311 const ParserFormalParameterParsingState& formal_parameters) {
4312 for (auto parameter : formal_parameters.params) {
4313 if (parameter.pattern != nullptr) return false;
4314 }
4315 return true;
4316 }
4317
4318
4310 Block* Parser::BuildParameterInitializationBlock( 4319 Block* Parser::BuildParameterInitializationBlock(
4311 const ParserFormalParameterParsingState& formal_parameters, bool* ok) { 4320 const ParserFormalParameterParsingState& formal_parameters, bool* ok) {
4321 DCHECK(!IsSimpleParameterList(formal_parameters));
4312 DCHECK(scope_->is_function_scope()); 4322 DCHECK(scope_->is_function_scope());
4313 Block* init_block = nullptr; 4323 Block* init_block =
4324 factory()->NewBlock(NULL, 1, true, RelocInfo::kNoPosition);
4314 for (auto parameter : formal_parameters.params) { 4325 for (auto parameter : formal_parameters.params) {
4315 if (parameter.pattern == nullptr) continue; 4326 if (parameter.pattern == nullptr) continue;
4316 if (init_block == nullptr) {
4317 init_block = factory()->NewBlock(NULL, 1, true, RelocInfo::kNoPosition);
4318 }
4319
4320 DeclarationDescriptor descriptor; 4327 DeclarationDescriptor descriptor;
4321 descriptor.declaration_kind = DeclarationDescriptor::PARAMETER; 4328 descriptor.declaration_kind = DeclarationDescriptor::PARAMETER;
4322 descriptor.parser = this; 4329 descriptor.parser = this;
4323 descriptor.declaration_scope = scope_; 4330 descriptor.declaration_scope = scope_;
4324 descriptor.scope = scope_; 4331 descriptor.scope = scope_;
4325 descriptor.mode = LET; 4332 descriptor.mode = LET;
4326 descriptor.is_const = false; 4333 descriptor.is_const = false;
4327 descriptor.needs_init = true; 4334 descriptor.needs_init = true;
4328 descriptor.declaration_pos = parameter.pattern->position(); 4335 descriptor.declaration_pos = parameter.pattern->position();
4329 descriptor.initialization_pos = parameter.pattern->position(); 4336 descriptor.initialization_pos = parameter.pattern->position();
4330 descriptor.init_op = Token::INIT_LET; 4337 descriptor.init_op = Token::INIT_LET;
4331 DeclarationParsingResult::Declaration decl( 4338 DeclarationParsingResult::Declaration decl(
4332 parameter.pattern, parameter.pattern->position(), 4339 parameter.pattern, parameter.pattern->position(),
4333 factory()->NewVariableProxy(parameter.var)); 4340 factory()->NewVariableProxy(parameter.var));
4334 PatternRewriter::DeclareAndInitializeVariables(init_block, &descriptor, 4341 PatternRewriter::DeclareAndInitializeVariables(init_block, &descriptor,
4335 &decl, nullptr, CHECK_OK); 4342 &decl, nullptr, CHECK_OK);
4336 } 4343 }
4337 return init_block; 4344 return init_block;
4338 } 4345 }
4339 4346
4340 4347
4341 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( 4348 ZoneList<Statement*>* Parser::ParseEagerFunctionBody(
4342 const AstRawString* function_name, int pos, 4349 const AstRawString* function_name, int pos,
4343 const ParserFormalParameterParsingState& formal_parameters, Variable* fvar, 4350 const ParserFormalParameterParsingState& formal_parameters, Variable* fvar,
4344 Token::Value fvar_init_op, FunctionKind kind, bool* ok) { 4351 Token::Value fvar_init_op, FunctionKind kind, bool* ok) {
4352 bool is_simple_parameter_list = IsSimpleParameterList(formal_parameters);
4353
4345 // Everything inside an eagerly parsed function will be parsed eagerly 4354 // Everything inside an eagerly parsed function will be parsed eagerly
4346 // (see comment above). 4355 // (see comment above).
4347 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); 4356 ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
4348 ZoneList<Statement*>* result = new(zone()) ZoneList<Statement*>(8, zone()); 4357 ZoneList<Statement*>* result = new(zone()) ZoneList<Statement*>(8, zone());
4349 if (fvar != NULL) { 4358 if (fvar != NULL) {
4350 VariableProxy* fproxy = scope_->NewUnresolved(factory(), function_name); 4359 VariableProxy* fproxy = scope_->NewUnresolved(factory(), function_name);
4351 fproxy->BindTo(fvar); 4360 fproxy->BindTo(fvar);
4352 result->Add(factory()->NewExpressionStatement( 4361 result->Add(factory()->NewExpressionStatement(
4353 factory()->NewAssignment(fvar_init_op, 4362 factory()->NewAssignment(fvar_init_op,
4354 fproxy, 4363 fproxy,
4355 factory()->NewThisFunction(pos), 4364 factory()->NewThisFunction(pos),
4356 RelocInfo::kNoPosition), 4365 RelocInfo::kNoPosition),
4357 RelocInfo::kNoPosition), zone()); 4366 RelocInfo::kNoPosition), zone());
4358 } 4367 }
4359 4368
4360 4369
4361 // For concise constructors, check that they are constructed, 4370 // For concise constructors, check that they are constructed,
4362 // not called. 4371 // not called.
4363 if (i::IsConstructor(kind)) { 4372 if (i::IsConstructor(kind)) {
4364 AddAssertIsConstruct(result, pos); 4373 AddAssertIsConstruct(result, pos);
4365 } 4374 }
4366 4375
4367 ZoneList<Statement*>* body = result; 4376 ZoneList<Statement*>* body = result;
4368 Scope* inner_scope = nullptr; 4377 Scope* inner_scope = nullptr;
4369 Block* inner_block = nullptr; 4378 Block* inner_block = nullptr;
4370 Block* init_block = 4379 if (!is_simple_parameter_list) {
4371 BuildParameterInitializationBlock(formal_parameters, CHECK_OK);
4372 if (init_block != nullptr) {
4373 body->Add(init_block, zone());
4374 // Wrap the actual function body into an inner scope.
4375 inner_block = factory()->NewBlock(NULL, 8, true, RelocInfo::kNoPosition);
4376 body->Add(inner_block, zone());
4377 body = inner_block->statements();
4378 inner_scope = NewScope(scope_, BLOCK_SCOPE); 4380 inner_scope = NewScope(scope_, BLOCK_SCOPE);
4379 inner_scope->set_is_declaration_scope(); 4381 inner_scope->set_is_declaration_scope();
4380 inner_scope->set_start_position(scanner()->location().beg_pos); 4382 inner_scope->set_start_position(scanner()->location().beg_pos);
4383 inner_block = factory()->NewBlock(NULL, 8, true, RelocInfo::kNoPosition);
4384 inner_block->set_scope(inner_scope);
4385 body = inner_block->statements();
4381 } 4386 }
4382 4387
4383 { 4388 {
4384 BlockState block_state(&scope_, inner_scope ? inner_scope : scope_); 4389 BlockState block_state(&scope_, inner_scope ? inner_scope : scope_);
4385 4390
4386 // For generators, allocate and yield an iterator on function entry. 4391 // For generators, allocate and yield an iterator on function entry.
4387 if (IsGeneratorFunction(kind)) { 4392 if (IsGeneratorFunction(kind)) {
4388 ZoneList<Expression*>* arguments = 4393 ZoneList<Expression*>* arguments =
4389 new(zone()) ZoneList<Expression*>(0, zone()); 4394 new(zone()) ZoneList<Expression*>(0, zone());
4390 CallRuntime* allocation = factory()->NewCallRuntime( 4395 CallRuntime* allocation = factory()->NewCallRuntime(
(...skipping 29 matching lines...) Expand all
4420 body->Add( 4425 body->Add(
4421 factory()->NewReturnStatement( 4426 factory()->NewReturnStatement(
4422 this->ThisExpression(scope_, factory(), RelocInfo::kNoPosition), 4427 this->ThisExpression(scope_, factory(), RelocInfo::kNoPosition),
4423 RelocInfo::kNoPosition), 4428 RelocInfo::kNoPosition),
4424 zone()); 4429 zone());
4425 } 4430 }
4426 } 4431 }
4427 4432
4428 Expect(Token::RBRACE, CHECK_OK); 4433 Expect(Token::RBRACE, CHECK_OK);
4429 scope_->set_end_position(scanner()->location().end_pos); 4434 scope_->set_end_position(scanner()->location().end_pos);
4430 if (inner_scope != nullptr) { 4435
4431 DCHECK(inner_block != nullptr); 4436 if (!is_simple_parameter_list) {
4437 DCHECK_NOT_NULL(inner_scope);
4438 DCHECK_EQ(body, inner_block->statements());
4439 scope_->SetLanguageMode(inner_scope->language_mode());
4440 Block* init_block =
4441 BuildParameterInitializationBlock(formal_parameters, CHECK_OK);
4442 DCHECK_NOT_NULL(init_block);
4443
4432 inner_scope->set_end_position(scanner()->location().end_pos); 4444 inner_scope->set_end_position(scanner()->location().end_pos);
4433 inner_scope = inner_scope->FinalizeBlockScope(); 4445 inner_scope = inner_scope->FinalizeBlockScope();
4434 inner_block->set_scope(inner_scope); 4446
4447 result->Add(init_block, zone());
4448 result->Add(inner_block, zone());
4435 } 4449 }
4436 4450
4437 return result; 4451 return result;
4438 } 4452 }
4439 4453
4440 4454
4441 PreParser::PreParseResult Parser::ParseLazyFunctionBodyWithPreParser( 4455 PreParser::PreParseResult Parser::ParseLazyFunctionBodyWithPreParser(
4442 SingletonLogger* logger, Scanner::BookmarkScope* bookmark) { 4456 SingletonLogger* logger, Scanner::BookmarkScope* bookmark) {
4443 // This function may be called on a background thread too; record only the 4457 // This function may be called on a background thread too; record only the
4444 // main thread preparse times. 4458 // main thread preparse times.
(...skipping 1532 matching lines...) Expand 10 before | Expand all | Expand 10 after
5977 Expression* Parser::SpreadCallNew(Expression* function, 5991 Expression* Parser::SpreadCallNew(Expression* function,
5978 ZoneList<v8::internal::Expression*>* args, 5992 ZoneList<v8::internal::Expression*>* args,
5979 int pos) { 5993 int pos) {
5980 args->InsertAt(0, function, zone()); 5994 args->InsertAt(0, function, zone());
5981 5995
5982 return factory()->NewCallRuntime( 5996 return factory()->NewCallRuntime(
5983 ast_value_factory()->reflect_construct_string(), NULL, args, pos); 5997 ast_value_factory()->reflect_construct_string(), NULL, args, pos);
5984 } 5998 }
5985 } // namespace internal 5999 } // namespace internal
5986 } // namespace v8 6000 } // namespace v8
OLDNEW
« no previous file with comments | « src/parser.h ('k') | test/mjsunit/strong/destructuring.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698