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 4155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4166 | 4166 |
4167 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( | 4167 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( |
4168 function_name, ast_value_factory(), scope, body, | 4168 function_name, ast_value_factory(), scope, body, |
4169 materialized_literal_count, expected_property_count, arity, | 4169 materialized_literal_count, expected_property_count, arity, |
4170 duplicate_parameters, function_type, FunctionLiteral::kIsFunction, | 4170 duplicate_parameters, function_type, FunctionLiteral::kIsFunction, |
4171 eager_compile_hint, kind, pos); | 4171 eager_compile_hint, kind, pos); |
4172 function_literal->set_function_token_position(function_token_pos); | 4172 function_literal->set_function_token_position(function_token_pos); |
4173 if (should_be_used_once_hint) | 4173 if (should_be_used_once_hint) |
4174 function_literal->set_should_be_used_once_hint(); | 4174 function_literal->set_should_be_used_once_hint(); |
4175 | 4175 |
4176 if (scope->has_rest_parameter()) { | |
4177 // TODO(caitp): enable optimization of functions with rest params | |
4178 function_literal->set_dont_optimize_reason(kRestParameter); | |
4179 } | |
4180 | |
4181 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); | 4176 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); |
4182 return function_literal; | 4177 return function_literal; |
4183 } | 4178 } |
4184 | 4179 |
4185 | 4180 |
4186 void Parser::SkipLazyFunctionBody(int* materialized_literal_count, | 4181 void Parser::SkipLazyFunctionBody(int* materialized_literal_count, |
4187 int* expected_property_count, bool* ok, | 4182 int* expected_property_count, bool* ok, |
4188 Scanner::BookmarkScope* bookmark) { | 4183 Scanner::BookmarkScope* bookmark) { |
4189 DCHECK_IMPLIES(bookmark, bookmark->HasBeenSet()); | 4184 DCHECK_IMPLIES(bookmark, bookmark->HasBeenSet()); |
4190 if (produce_cached_parse_data()) CHECK(log_); | 4185 if (produce_cached_parse_data()) CHECK(log_); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4308 | 4303 |
4309 | 4304 |
4310 Block* Parser::BuildParameterInitializationBlock( | 4305 Block* Parser::BuildParameterInitializationBlock( |
4311 const ParserFormalParameters& parameters, bool* ok) { | 4306 const ParserFormalParameters& parameters, bool* ok) { |
4312 DCHECK(!parameters.is_simple); | 4307 DCHECK(!parameters.is_simple); |
4313 DCHECK(scope_->is_function_scope()); | 4308 DCHECK(scope_->is_function_scope()); |
4314 Block* init_block = | 4309 Block* init_block = |
4315 factory()->NewBlock(NULL, 1, true, RelocInfo::kNoPosition); | 4310 factory()->NewBlock(NULL, 1, true, RelocInfo::kNoPosition); |
4316 for (int i = 0; i < parameters.params.length(); ++i) { | 4311 for (int i = 0; i < parameters.params.length(); ++i) { |
4317 auto parameter = parameters.params[i]; | 4312 auto parameter = parameters.params[i]; |
4318 // TODO(caitp,rossberg): Remove special handling for rest once desugared. | |
4319 if (parameter.is_rest) break; | |
4320 DeclarationDescriptor descriptor; | 4313 DeclarationDescriptor descriptor; |
4321 descriptor.declaration_kind = DeclarationDescriptor::PARAMETER; | 4314 descriptor.declaration_kind = DeclarationDescriptor::PARAMETER; |
4322 descriptor.parser = this; | 4315 descriptor.parser = this; |
4323 descriptor.declaration_scope = scope_; | 4316 descriptor.declaration_scope = scope_; |
4324 descriptor.scope = scope_; | 4317 descriptor.scope = scope_; |
4325 descriptor.mode = LET; | 4318 descriptor.mode = LET; |
4326 descriptor.is_const = false; | 4319 descriptor.is_const = false; |
4327 descriptor.needs_init = true; | 4320 descriptor.needs_init = true; |
4328 descriptor.declaration_pos = parameter.pattern->position(); | 4321 descriptor.declaration_pos = parameter.pattern->position(); |
4329 descriptor.initialization_pos = parameter.pattern->position(); | 4322 descriptor.initialization_pos = parameter.pattern->position(); |
4330 descriptor.init_op = Token::INIT_LET; | 4323 descriptor.init_op = Token::INIT_LET; |
4324 | |
4325 auto parameter_var = parameters.scope->parameter(i); | |
4326 auto parameter_proxy = factory()->NewVariableProxy(parameter_var); | |
adamk
2015/08/05 22:13:02
I'd move this down to where it's used to avoid acc
| |
4327 | |
4328 if (parameter.is_rest) { | |
4329 DCHECK(parameter.pattern->IsVariableProxy()); | |
4330 DCHECK_EQ(i, parameters.params.length() - 1); | |
4331 | |
4332 // tmp_var = []; | |
4333 // for (i = rest_index; i < %_ArgumentsLength(); ++i) { | |
adamk
2015/08/05 22:13:02
This desugaring needs updating to match what's goi
| |
4334 // %AddElement(tmp_var, tmp_var.length, %_Arguments(i)); | |
4335 // } | |
4336 // let <$rest_array> = tmp_var; | |
4337 auto empty_values = new (zone()) ZoneList<Expression*>(0, zone()); | |
4338 auto empty_array = factory()->NewArrayLiteral( | |
4339 empty_values, parameters.rest_array_literal_index, | |
4340 is_strong(language_mode()), RelocInfo::kNoPosition); | |
4341 | |
4342 auto init_array = | |
4343 factory()->NewAssignment(Token::INIT_VAR, parameter_proxy, | |
4344 empty_array, RelocInfo::kNoPosition); | |
4345 | |
4346 auto loop = factory()->NewForStatement(NULL, RelocInfo::kNoPosition); | |
4347 | |
4348 // argument_index = rest_index | |
4349 auto argument_index = | |
4350 parameters.scope->NewTemporary(ast_value_factory()->dot_string()); | |
4351 auto init = factory()->NewExpressionStatement( | |
4352 factory()->NewAssignment( | |
4353 Token::INIT_VAR, factory()->NewVariableProxy(argument_index), | |
4354 factory()->NewSmiLiteral(i, RelocInfo::kNoPosition), | |
4355 RelocInfo::kNoPosition), | |
4356 RelocInfo::kNoPosition); | |
4357 | |
4358 auto arguments_length = Runtime::FunctionForId(Runtime::kArgumentsLength); | |
adamk
2015/08/05 22:13:02
I think you want kInlineArgumentsLength here (if I
| |
4359 auto empty_arguments = new (zone()) ZoneList<Expression*>(0, zone()); | |
4360 | |
4361 // arguments_index < arguments.length | |
4362 auto cond = factory()->NewCompareOperation( | |
4363 Token::LT, factory()->NewVariableProxy(argument_index), | |
4364 factory()->NewCallRuntime(ast_value_factory()->empty_string(), | |
4365 arguments_length, empty_arguments, | |
4366 RelocInfo::kNoPosition), | |
4367 RelocInfo::kNoPosition); | |
4368 | |
4369 // ++argument_index | |
4370 auto next = factory()->NewExpressionStatement( | |
4371 factory()->NewCountOperation( | |
4372 Token::INC, true, factory()->NewVariableProxy(argument_index), | |
4373 RelocInfo::kNoPosition), | |
4374 RelocInfo::kNoPosition); | |
4375 | |
4376 // %_Arguments(arguments_index) / arguments[arguments_index] | |
4377 auto arguments = Runtime::FunctionForId(Runtime::kArguments); | |
adamk
2015/08/05 22:13:02
kInlineArguments
| |
4378 | |
4379 auto arguments_args = new (zone()) ZoneList<Expression*>(1, zone()); | |
4380 arguments_args->Add(factory()->NewVariableProxy(argument_index), zone()); | |
4381 | |
4382 // %AppendElement($rest, $_Arguments(arguments_index)) | |
adamk
2015/08/05 22:13:02
Should read:
%AppendElement($rest, %_Arguments(ar
| |
4383 auto append_element = Runtime::FunctionForId(Runtime::kAppendElement); | |
4384 auto append_element_args = new (zone()) ZoneList<Expression*>(2, zone()); | |
4385 | |
4386 append_element_args->Add(factory()->NewVariableProxy(parameter_var), | |
4387 zone()); | |
4388 append_element_args->Add( | |
4389 factory()->NewCallRuntime(ast_value_factory()->empty_string(), | |
4390 arguments, arguments_args, | |
4391 RelocInfo::kNoPosition), | |
4392 zone()); | |
4393 | |
4394 auto body = factory()->NewExpressionStatement( | |
4395 factory()->NewCallRuntime(ast_value_factory()->empty_string(), | |
4396 append_element, append_element_args, | |
4397 RelocInfo::kNoPosition), | |
4398 RelocInfo::kNoPosition); | |
4399 | |
4400 loop->Initialize(init, cond, next, body); | |
4401 | |
4402 init_block->AddStatement( | |
4403 factory()->NewExpressionStatement(init_array, RelocInfo::kNoPosition), | |
4404 zone()); | |
4405 | |
4406 init_block->AddStatement(loop, zone()); | |
4407 } | |
4408 | |
4331 DeclarationParsingResult::Declaration decl( | 4409 DeclarationParsingResult::Declaration decl( |
4332 parameter.pattern, parameter.pattern->position(), | 4410 parameter.pattern, parameter.pattern->position(), |
4333 factory()->NewVariableProxy(parameters.scope->parameter(i))); | 4411 factory()->NewVariableProxy(parameter_var)); |
4334 PatternRewriter::DeclareAndInitializeVariables(init_block, &descriptor, | 4412 PatternRewriter::DeclareAndInitializeVariables(init_block, &descriptor, |
4335 &decl, nullptr, CHECK_OK); | 4413 &decl, nullptr, CHECK_OK); |
4336 } | 4414 } |
4415 | |
4337 return init_block; | 4416 return init_block; |
4338 } | 4417 } |
4339 | 4418 |
4340 | 4419 |
4341 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( | 4420 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( |
4342 const AstRawString* function_name, int pos, | 4421 const AstRawString* function_name, int pos, |
4343 const ParserFormalParameters& parameters, FunctionKind kind, | 4422 const ParserFormalParameters& parameters, FunctionKind kind, |
4344 FunctionLiteral::FunctionType function_type, bool* ok) { | 4423 FunctionLiteral::FunctionType function_type, bool* ok) { |
4345 // Everything inside an eagerly parsed function will be parsed eagerly | 4424 // Everything inside an eagerly parsed function will be parsed eagerly |
4346 // (see comment above). | 4425 // (see comment above). |
(...skipping 1670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6017 Expression* Parser::SpreadCallNew(Expression* function, | 6096 Expression* Parser::SpreadCallNew(Expression* function, |
6018 ZoneList<v8::internal::Expression*>* args, | 6097 ZoneList<v8::internal::Expression*>* args, |
6019 int pos) { | 6098 int pos) { |
6020 args->InsertAt(0, function, zone()); | 6099 args->InsertAt(0, function, zone()); |
6021 | 6100 |
6022 return factory()->NewCallRuntime( | 6101 return factory()->NewCallRuntime( |
6023 ast_value_factory()->reflect_construct_string(), NULL, args, pos); | 6102 ast_value_factory()->reflect_construct_string(), NULL, args, pos); |
6024 } | 6103 } |
6025 } // namespace internal | 6104 } // namespace internal |
6026 } // namespace v8 | 6105 } // namespace v8 |
OLD | NEW |