OLD | NEW |
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 1305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1316 ast_value_factory()->use_strict_string() && | 1316 ast_value_factory()->use_strict_string() && |
1317 token_loc.end_pos - token_loc.beg_pos == | 1317 token_loc.end_pos - token_loc.beg_pos == |
1318 ast_value_factory()->use_strict_string()->length() + 2; | 1318 ast_value_factory()->use_strict_string()->length() + 2; |
1319 bool use_strong_found = | 1319 bool use_strong_found = |
1320 allow_strong_mode() && | 1320 allow_strong_mode() && |
1321 literal->raw_value()->AsString() == | 1321 literal->raw_value()->AsString() == |
1322 ast_value_factory()->use_strong_string() && | 1322 ast_value_factory()->use_strong_string() && |
1323 token_loc.end_pos - token_loc.beg_pos == | 1323 token_loc.end_pos - token_loc.beg_pos == |
1324 ast_value_factory()->use_strong_string()->length() + 2; | 1324 ast_value_factory()->use_strong_string()->length() + 2; |
1325 if (use_strict_found || use_strong_found) { | 1325 if (use_strict_found || use_strong_found) { |
| 1326 if (!scope_->HasSimpleParameters()) { |
| 1327 // A block declaration scope as a child scope of a function scope |
| 1328 // indicates that a function has a non-simple parameter list. |
| 1329 // TC39 deemed "use strict" directives to be an error in this case, |
| 1330 // on 29/7/2015. https://goo.gl/ueA7Ln |
| 1331 // |
| 1332 // In V8, this also applies to "use strong " directives. |
| 1333 const AstRawString* string = literal->raw_value()->AsString(); |
| 1334 ParserTraits::ReportMessageAt( |
| 1335 token_loc, MessageTemplate::kIllegalLanguageModeDirective, |
| 1336 string); |
| 1337 *ok = false; |
| 1338 return nullptr; |
| 1339 } |
| 1340 |
1326 // Strong mode implies strict mode. If there are several "use strict" | 1341 // Strong mode implies strict mode. If there are several "use strict" |
1327 // / "use strong" directives, do the strict mode changes only once. | 1342 // / "use strong" directives, do the strict mode changes only once. |
1328 if (is_sloppy(scope_->language_mode())) { | 1343 if (is_sloppy(scope_->language_mode())) { |
1329 scope_->SetLanguageMode(static_cast<LanguageMode>( | 1344 scope_->SetLanguageMode(static_cast<LanguageMode>( |
1330 scope_->language_mode() | STRICT)); | 1345 scope_->language_mode() | STRICT)); |
1331 } | 1346 } |
1332 | 1347 |
1333 if (use_strong_found) { | 1348 if (use_strong_found) { |
1334 scope_->SetLanguageMode(static_cast<LanguageMode>( | 1349 scope_->SetLanguageMode(static_cast<LanguageMode>( |
1335 scope_->language_mode() | STRONG)); | 1350 scope_->language_mode() | STRONG)); |
(...skipping 2911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4247 } | 4262 } |
4248 if (logger.calls_eval()) { | 4263 if (logger.calls_eval()) { |
4249 scope_->RecordEvalCall(); | 4264 scope_->RecordEvalCall(); |
4250 } | 4265 } |
4251 if (produce_cached_parse_data()) { | 4266 if (produce_cached_parse_data()) { |
4252 DCHECK(log_); | 4267 DCHECK(log_); |
4253 // Position right after terminal '}'. | 4268 // Position right after terminal '}'. |
4254 int body_end = scanner()->location().end_pos; | 4269 int body_end = scanner()->location().end_pos; |
4255 log_->LogFunction(function_block_pos, body_end, *materialized_literal_count, | 4270 log_->LogFunction(function_block_pos, body_end, *materialized_literal_count, |
4256 *expected_property_count, scope_->language_mode(), | 4271 *expected_property_count, scope_->language_mode(), |
4257 scope_->uses_super_property(), scope_->calls_eval()); | 4272 scope_->uses_super_property(), scope_->calls_eval(), |
| 4273 scope_->has_simple_parameters()); |
4258 } | 4274 } |
4259 } | 4275 } |
4260 | 4276 |
4261 | 4277 |
4262 void Parser::AddAssertIsConstruct(ZoneList<Statement*>* body, int pos) { | 4278 void Parser::AddAssertIsConstruct(ZoneList<Statement*>* body, int pos) { |
4263 ZoneList<Expression*>* arguments = | 4279 ZoneList<Expression*>* arguments = |
4264 new (zone()) ZoneList<Expression*>(0, zone()); | 4280 new (zone()) ZoneList<Expression*>(0, zone()); |
4265 CallRuntime* construct_check = factory()->NewCallRuntime( | 4281 CallRuntime* construct_check = factory()->NewCallRuntime( |
4266 ast_value_factory()->is_construct_call_string(), | 4282 ast_value_factory()->is_construct_call_string(), |
4267 Runtime::FunctionForId(Runtime::kInlineIsConstructCall), arguments, pos); | 4283 Runtime::FunctionForId(Runtime::kInlineIsConstructCall), arguments, pos); |
(...skipping 30 matching lines...) Expand all Loading... |
4298 condition, factory()->NewExpressionStatement(throw_type_error, | 4314 condition, factory()->NewExpressionStatement(throw_type_error, |
4299 RelocInfo::kNoPosition), | 4315 RelocInfo::kNoPosition), |
4300 factory()->NewEmptyStatement(RelocInfo::kNoPosition), | 4316 factory()->NewEmptyStatement(RelocInfo::kNoPosition), |
4301 RelocInfo::kNoPosition); | 4317 RelocInfo::kNoPosition); |
4302 return if_statement; | 4318 return if_statement; |
4303 } | 4319 } |
4304 | 4320 |
4305 | 4321 |
4306 Block* Parser::BuildParameterInitializationBlock( | 4322 Block* Parser::BuildParameterInitializationBlock( |
4307 const ParserFormalParameters& parameters, bool* ok) { | 4323 const ParserFormalParameters& parameters, bool* ok) { |
4308 DCHECK(!parameters.is_simple); | 4324 if (parameters.is_simple) return nullptr; |
4309 DCHECK(scope_->is_function_scope()); | 4325 DCHECK(scope_->is_function_scope()); |
4310 Block* init_block = | 4326 Block* init_block = |
4311 factory()->NewBlock(NULL, 1, true, RelocInfo::kNoPosition); | 4327 factory()->NewBlock(NULL, 1, true, RelocInfo::kNoPosition); |
4312 for (int i = 0; i < parameters.params.length(); ++i) { | 4328 for (int i = 0; i < parameters.params.length(); ++i) { |
4313 auto parameter = parameters.params[i]; | 4329 auto parameter = parameters.params[i]; |
4314 // TODO(caitp,rossberg): Remove special handling for rest once desugared. | 4330 // TODO(caitp,rossberg): Remove special handling for rest once desugared. |
4315 if (parameter.is_rest) break; | 4331 if (parameter.is_rest) break; |
4316 DeclarationDescriptor descriptor; | 4332 DeclarationDescriptor descriptor; |
4317 descriptor.declaration_kind = DeclarationDescriptor::PARAMETER; | 4333 descriptor.declaration_kind = DeclarationDescriptor::PARAMETER; |
4318 descriptor.parser = this; | 4334 descriptor.parser = this; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4357 | 4373 |
4358 // For concise constructors, check that they are constructed, | 4374 // For concise constructors, check that they are constructed, |
4359 // not called. | 4375 // not called. |
4360 if (i::IsConstructor(kind)) { | 4376 if (i::IsConstructor(kind)) { |
4361 AddAssertIsConstruct(result, pos); | 4377 AddAssertIsConstruct(result, pos); |
4362 } | 4378 } |
4363 | 4379 |
4364 ZoneList<Statement*>* body = result; | 4380 ZoneList<Statement*>* body = result; |
4365 Scope* inner_scope = nullptr; | 4381 Scope* inner_scope = nullptr; |
4366 Block* inner_block = nullptr; | 4382 Block* inner_block = nullptr; |
4367 if (!parameters.is_simple) { | 4383 Block* init_block = BuildParameterInitializationBlock(parameters, CHECK_OK); |
| 4384 if (init_block != nullptr) { |
| 4385 body->Add(init_block, zone()); |
| 4386 // Wrap the actual function body into an inner scope. |
| 4387 inner_block = factory()->NewBlock(NULL, 8, true, RelocInfo::kNoPosition); |
| 4388 body->Add(inner_block, zone()); |
| 4389 body = inner_block->statements(); |
4368 inner_scope = NewScope(scope_, BLOCK_SCOPE); | 4390 inner_scope = NewScope(scope_, BLOCK_SCOPE); |
4369 inner_scope->set_is_declaration_scope(); | 4391 inner_scope->set_is_declaration_scope(); |
4370 inner_scope->set_start_position(scanner()->location().beg_pos); | 4392 inner_scope->set_start_position(scanner()->location().beg_pos); |
4371 inner_block = factory()->NewBlock(NULL, 8, true, RelocInfo::kNoPosition); | |
4372 inner_block->set_scope(inner_scope); | 4393 inner_block->set_scope(inner_scope); |
4373 body = inner_block->statements(); | |
4374 } | 4394 } |
4375 | 4395 |
4376 { | 4396 { |
4377 BlockState block_state(&scope_, inner_scope ? inner_scope : scope_); | 4397 BlockState block_state(&scope_, inner_scope ? inner_scope : scope_); |
4378 | 4398 |
4379 // For generators, allocate and yield an iterator on function entry. | 4399 // For generators, allocate and yield an iterator on function entry. |
4380 if (IsGeneratorFunction(kind)) { | 4400 if (IsGeneratorFunction(kind)) { |
4381 ZoneList<Expression*>* arguments = | 4401 ZoneList<Expression*>* arguments = |
4382 new(zone()) ZoneList<Expression*>(0, zone()); | 4402 new(zone()) ZoneList<Expression*>(0, zone()); |
4383 CallRuntime* allocation = factory()->NewCallRuntime( | 4403 CallRuntime* allocation = factory()->NewCallRuntime( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4415 this->ThisExpression(scope_, factory(), RelocInfo::kNoPosition), | 4435 this->ThisExpression(scope_, factory(), RelocInfo::kNoPosition), |
4416 RelocInfo::kNoPosition), | 4436 RelocInfo::kNoPosition), |
4417 zone()); | 4437 zone()); |
4418 } | 4438 } |
4419 } | 4439 } |
4420 | 4440 |
4421 Expect(Token::RBRACE, CHECK_OK); | 4441 Expect(Token::RBRACE, CHECK_OK); |
4422 scope_->set_end_position(scanner()->location().end_pos); | 4442 scope_->set_end_position(scanner()->location().end_pos); |
4423 | 4443 |
4424 if (!parameters.is_simple) { | 4444 if (!parameters.is_simple) { |
4425 DCHECK_NOT_NULL(inner_scope); | 4445 DCHECK_NOT_NULL(inner_block); |
4426 DCHECK_EQ(body, inner_block->statements()); | |
4427 scope_->SetLanguageMode(inner_scope->language_mode()); | |
4428 Block* init_block = BuildParameterInitializationBlock(parameters, CHECK_OK); | |
4429 DCHECK_NOT_NULL(init_block); | |
4430 | |
4431 inner_scope->set_end_position(scanner()->location().end_pos); | 4446 inner_scope->set_end_position(scanner()->location().end_pos); |
4432 inner_scope = inner_scope->FinalizeBlockScope(); | 4447 inner_scope = inner_scope->FinalizeBlockScope(); |
4433 if (inner_scope != nullptr) { | 4448 if (inner_scope != nullptr) { |
4434 CheckConflictingVarDeclarations(inner_scope, CHECK_OK); | 4449 CheckConflictingVarDeclarations(inner_scope, CHECK_OK); |
4435 } | 4450 } |
4436 | |
4437 result->Add(init_block, zone()); | |
4438 result->Add(inner_block, zone()); | |
4439 } | 4451 } |
4440 | 4452 |
4441 if (function_type == FunctionLiteral::NAMED_EXPRESSION) { | 4453 if (function_type == FunctionLiteral::NAMED_EXPRESSION) { |
4442 // Now that we know the language mode, we can create the const assignment | 4454 // Now that we know the language mode, we can create the const assignment |
4443 // in the previously reserved spot. | 4455 // in the previously reserved spot. |
4444 // NOTE: We create a proxy and resolve it here so that in the | 4456 // NOTE: We create a proxy and resolve it here so that in the |
4445 // future we can change the AST to only refer to VariableProxies | 4457 // future we can change the AST to only refer to VariableProxies |
4446 // instead of Variables and Proxies as is the case now. | 4458 // instead of Variables and Proxies as is the case now. |
4447 Token::Value fvar_init_op = Token::INIT_CONST_LEGACY; | 4459 Token::Value fvar_init_op = Token::INIT_CONST_LEGACY; |
4448 bool use_strict_const = is_strict(scope_->language_mode()) || | 4460 bool use_strict_const = is_strict(scope_->language_mode()) || |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4493 SET_ALLOW(harmony_sloppy_let); | 4505 SET_ALLOW(harmony_sloppy_let); |
4494 SET_ALLOW(harmony_rest_parameters); | 4506 SET_ALLOW(harmony_rest_parameters); |
4495 SET_ALLOW(harmony_spreadcalls); | 4507 SET_ALLOW(harmony_spreadcalls); |
4496 SET_ALLOW(harmony_destructuring); | 4508 SET_ALLOW(harmony_destructuring); |
4497 SET_ALLOW(harmony_spread_arrays); | 4509 SET_ALLOW(harmony_spread_arrays); |
4498 SET_ALLOW(harmony_new_target); | 4510 SET_ALLOW(harmony_new_target); |
4499 SET_ALLOW(strong_mode); | 4511 SET_ALLOW(strong_mode); |
4500 #undef SET_ALLOW | 4512 #undef SET_ALLOW |
4501 } | 4513 } |
4502 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( | 4514 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( |
4503 language_mode(), function_state_->kind(), logger, bookmark); | 4515 language_mode(), function_state_->kind(), scope_->has_simple_parameters(), |
| 4516 logger, bookmark); |
4504 if (pre_parse_timer_ != NULL) { | 4517 if (pre_parse_timer_ != NULL) { |
4505 pre_parse_timer_->Stop(); | 4518 pre_parse_timer_->Stop(); |
4506 } | 4519 } |
4507 return result; | 4520 return result; |
4508 } | 4521 } |
4509 | 4522 |
4510 | 4523 |
4511 ClassLiteral* Parser::ParseClassLiteral(const AstRawString* name, | 4524 ClassLiteral* Parser::ParseClassLiteral(const AstRawString* name, |
4512 Scanner::Location class_name_location, | 4525 Scanner::Location class_name_location, |
4513 bool name_is_strict_reserved, int pos, | 4526 bool name_is_strict_reserved, int pos, |
(...skipping 1496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6010 Expression* Parser::SpreadCallNew(Expression* function, | 6023 Expression* Parser::SpreadCallNew(Expression* function, |
6011 ZoneList<v8::internal::Expression*>* args, | 6024 ZoneList<v8::internal::Expression*>* args, |
6012 int pos) { | 6025 int pos) { |
6013 args->InsertAt(0, function, zone()); | 6026 args->InsertAt(0, function, zone()); |
6014 | 6027 |
6015 return factory()->NewCallRuntime( | 6028 return factory()->NewCallRuntime( |
6016 ast_value_factory()->reflect_construct_string(), NULL, args, pos); | 6029 ast_value_factory()->reflect_construct_string(), NULL, args, pos); |
6017 } | 6030 } |
6018 } // namespace internal | 6031 } // namespace internal |
6019 } // namespace v8 | 6032 } // namespace v8 |
OLD | NEW |