Chromium Code Reviews| 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 4147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4158 | 4158 |
| 4159 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( | 4159 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( |
| 4160 function_name, ast_value_factory(), scope, body, | 4160 function_name, ast_value_factory(), scope, body, |
| 4161 materialized_literal_count, expected_property_count, num_parameters, | 4161 materialized_literal_count, expected_property_count, num_parameters, |
| 4162 duplicate_parameters, function_type, FunctionLiteral::kIsFunction, | 4162 duplicate_parameters, function_type, FunctionLiteral::kIsFunction, |
| 4163 eager_compile_hint, kind, pos); | 4163 eager_compile_hint, kind, pos); |
| 4164 function_literal->set_function_token_position(function_token_pos); | 4164 function_literal->set_function_token_position(function_token_pos); |
| 4165 if (should_be_used_once_hint) | 4165 if (should_be_used_once_hint) |
| 4166 function_literal->set_should_be_used_once_hint(); | 4166 function_literal->set_should_be_used_once_hint(); |
| 4167 | 4167 |
| 4168 if (scope->has_rest_parameter()) { | |
| 4169 // TODO(caitp): enable optimization of functions with rest params | |
| 4170 function_literal->set_dont_optimize_reason(kRestParameter); | |
| 4171 } | |
| 4172 | |
| 4173 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); | 4168 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); |
| 4174 return function_literal; | 4169 return function_literal; |
| 4175 } | 4170 } |
| 4176 | 4171 |
| 4177 | 4172 |
| 4178 void Parser::SkipLazyFunctionBody(int* materialized_literal_count, | 4173 void Parser::SkipLazyFunctionBody(int* materialized_literal_count, |
| 4179 int* expected_property_count, bool* ok, | 4174 int* expected_property_count, bool* ok, |
| 4180 Scanner::BookmarkScope* bookmark) { | 4175 Scanner::BookmarkScope* bookmark) { |
| 4181 DCHECK_IMPLIES(bookmark, bookmark->HasBeenSet()); | 4176 DCHECK_IMPLIES(bookmark, bookmark->HasBeenSet()); |
| 4182 if (produce_cached_parse_data()) CHECK(log_); | 4177 if (produce_cached_parse_data()) CHECK(log_); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4319 descriptor.needs_init = true; | 4314 descriptor.needs_init = true; |
| 4320 descriptor.declaration_pos = parameter.pattern->position(); | 4315 descriptor.declaration_pos = parameter.pattern->position(); |
| 4321 descriptor.initialization_pos = parameter.pattern->position(); | 4316 descriptor.initialization_pos = parameter.pattern->position(); |
| 4322 descriptor.init_op = Token::INIT_LET; | 4317 descriptor.init_op = Token::INIT_LET; |
| 4323 DeclarationParsingResult::Declaration decl( | 4318 DeclarationParsingResult::Declaration decl( |
| 4324 parameter.pattern, parameter.pattern->position(), | 4319 parameter.pattern, parameter.pattern->position(), |
| 4325 factory()->NewVariableProxy(parameter.var)); | 4320 factory()->NewVariableProxy(parameter.var)); |
| 4326 PatternRewriter::DeclareAndInitializeVariables(init_block, &descriptor, | 4321 PatternRewriter::DeclareAndInitializeVariables(init_block, &descriptor, |
| 4327 &decl, nullptr, CHECK_OK); | 4322 &decl, nullptr, CHECK_OK); |
| 4328 } | 4323 } |
| 4324 if (formal_parameters.has_rest) { | |
| 4325 auto rest_parameter = formal_parameters.params.last(); | |
| 4326 int rest_index = formal_parameters.params.length() - 1; | |
| 4327 DCHECK_NULL(rest_parameter.pattern); | |
| 4328 if (init_block == nullptr) { | |
| 4329 init_block = factory()->NewBlock(NULL, 1, true, RelocInfo::kNoPosition); | |
| 4330 } | |
| 4331 | |
| 4332 // DESUGAR: | |
| 4333 // let <rest_params> = []; | |
|
Michael Starzinger
2015/07/15 11:32:11
Just throwing this out there, not saying we should
caitp (gmail)
2015/07/15 11:36:32
I don't think there's any problem doing it that wa
Michael Starzinger
2015/07/15 11:41:15
Awesome. Thanks! In that case I would be fine with
Toon Verwaest
2015/07/15 18:57:39
When you preallocate an array of a specific length
Michael Starzinger
2015/07/15 19:07:43
Yes, you are right. I should have been more explic
| |
| 4334 // for (int i = <rest_index>; i < <arguments.length>; ++i) { | |
| 4335 // %AddElement(<rest_params>, <rest_params.length>, arguments[i++]); | |
| 4336 // } | |
| 4337 VariableProxy* proxy = factory()->NewVariableProxy(rest_parameter.var); | |
| 4338 Declaration* declaration = factory()->NewVariableDeclaration( | |
| 4339 proxy, VAR, scope_, RelocInfo::kNoPosition); | |
|
rossberg
2015/07/15 12:10:16
Shouldn't this be LET?
caitp (gmail)
2015/07/15 13:53:35
There are 2 things that get in the way: missing po
rossberg
2015/07/15 14:54:31
I'm fine with that. You can find a related TODO in
| |
| 4340 Variable* var = this->Declare(declaration, DeclarationDescriptor::PARAMETER, | |
| 4341 false, CHECK_OK); | |
| 4342 proxy = factory()->NewVariableProxy(var); | |
| 4343 | |
| 4344 // TODO(@caitp): use an array literal to avoid escape | |
|
rossberg
2015/07/15 12:10:16
Can you do that in this CL? It would avoid adding
caitp (gmail)
2015/07/15 13:53:35
This is proving to be very difficult to accomplish
rossberg
2015/07/15 14:54:31
I see. Fine to leave for follow-up as well.
| |
| 4345 auto empty_values = new (zone()) ZoneList<Expression*>(0, zone()); | |
| 4346 Expression* empty_array = factory()->NewCallRuntime( | |
| 4347 ast_value_factory()->empty_array_string(), nullptr, empty_values, | |
| 4348 RelocInfo::kNoPosition); | |
| 4349 | |
| 4350 Assignment* init_array = factory()->NewAssignment( | |
| 4351 Token::INIT_VAR, proxy, empty_array, RelocInfo::kNoPosition); | |
| 4352 | |
| 4353 auto loop = factory()->NewForStatement(NULL, RelocInfo::kNoPosition); | |
| 4354 | |
| 4355 // argument_index = rest_index | |
| 4356 Variable* argument_index = | |
| 4357 scope_->NewTemporary(ast_value_factory()->dot_string()); | |
| 4358 auto init = factory()->NewExpressionStatement( | |
| 4359 factory()->NewAssignment( | |
| 4360 Token::INIT_VAR, factory()->NewVariableProxy(argument_index), | |
| 4361 factory()->NewSmiLiteral(rest_index, RelocInfo::kNoPosition), | |
| 4362 RelocInfo::kNoPosition), | |
| 4363 RelocInfo::kNoPosition); | |
| 4364 | |
| 4365 auto arguments_length = Runtime::FunctionForId(Runtime::kArgumentsLength); | |
| 4366 auto empty_arguments = new (zone()) ZoneList<Expression*>(0, zone()); | |
| 4367 | |
| 4368 // argument_index < %_ArgumentsLength() | |
| 4369 auto cond = factory()->NewCompareOperation( | |
| 4370 Token::LT, factory()->NewVariableProxy(argument_index), | |
| 4371 factory()->NewCallRuntime(ast_value_factory()->empty_string(), | |
| 4372 arguments_length, empty_arguments, | |
| 4373 RelocInfo::kNoPosition), | |
| 4374 RelocInfo::kNoPosition); | |
| 4375 | |
| 4376 // ++argument_index | |
| 4377 auto next = factory()->NewExpressionStatement( | |
| 4378 factory()->NewCountOperation( | |
| 4379 Token::INC, true, factory()->NewVariableProxy(argument_index), | |
| 4380 RelocInfo::kNoPosition), | |
| 4381 RelocInfo::kNoPosition); | |
| 4382 | |
| 4383 auto arguments = Runtime::FunctionForId(Runtime::kArguments); | |
| 4384 // %_Arguments(<argument_index>) | |
| 4385 auto arguments_args = new (zone()) ZoneList<Expression*>(1, zone()); | |
| 4386 arguments_args->Add(factory()->NewVariableProxy(argument_index), zone()); | |
| 4387 | |
| 4388 // %AddElement( | |
| 4389 // <restParam>, <restParam.length>, %_Arguments(<argument_index>)); | |
| 4390 auto add_element = Runtime::FunctionForId(Runtime::kAddElement); | |
| 4391 auto add_element_args = new (zone()) ZoneList<Expression*>(3, zone()); | |
| 4392 add_element_args->Add(factory()->NewVariableProxy(var), zone()); | |
| 4393 add_element_args->Add( | |
| 4394 factory()->NewProperty( | |
| 4395 factory()->NewVariableProxy(var), | |
| 4396 factory()->NewStringLiteral(ast_value_factory()->length_string(), | |
| 4397 RelocInfo::kNoPosition), | |
| 4398 RelocInfo::kNoPosition), | |
| 4399 zone()); | |
| 4400 add_element_args->Add(factory()->NewCallRuntime( | |
| 4401 ast_value_factory()->empty_string(), arguments, | |
| 4402 arguments_args, RelocInfo::kNoPosition), | |
| 4403 zone()); | |
| 4404 | |
| 4405 auto body = factory()->NewExpressionStatement( | |
| 4406 factory()->NewCallRuntime(ast_value_factory()->empty_string(), | |
| 4407 add_element, add_element_args, | |
| 4408 RelocInfo::kNoPosition), | |
| 4409 RelocInfo::kNoPosition); | |
| 4410 | |
| 4411 loop->Initialize(init, cond, next, body); | |
| 4412 init_block->AddStatement( | |
| 4413 factory()->NewExpressionStatement(init_array, RelocInfo::kNoPosition), | |
| 4414 zone()); | |
| 4415 init_block->AddStatement(loop, zone()); | |
| 4416 } | |
| 4329 return init_block; | 4417 return init_block; |
| 4330 } | 4418 } |
| 4331 | 4419 |
| 4332 | 4420 |
| 4333 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( | 4421 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( |
| 4334 const AstRawString* function_name, int pos, | 4422 const AstRawString* function_name, int pos, |
| 4335 const ParserFormalParameterParsingState& formal_parameters, Variable* fvar, | 4423 const ParserFormalParameterParsingState& formal_parameters, Variable* fvar, |
| 4336 Token::Value fvar_init_op, FunctionKind kind, bool* ok) { | 4424 Token::Value fvar_init_op, FunctionKind kind, bool* ok) { |
| 4337 // Everything inside an eagerly parsed function will be parsed eagerly | 4425 // Everything inside an eagerly parsed function will be parsed eagerly |
| 4338 // (see comment above). | 4426 // (see comment above). |
| (...skipping 1610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5949 Expression* Parser::SpreadCallNew(Expression* function, | 6037 Expression* Parser::SpreadCallNew(Expression* function, |
| 5950 ZoneList<v8::internal::Expression*>* args, | 6038 ZoneList<v8::internal::Expression*>* args, |
| 5951 int pos) { | 6039 int pos) { |
| 5952 args->InsertAt(0, function, zone()); | 6040 args->InsertAt(0, function, zone()); |
| 5953 | 6041 |
| 5954 return factory()->NewCallRuntime( | 6042 return factory()->NewCallRuntime( |
| 5955 ast_value_factory()->reflect_construct_string(), NULL, args, pos); | 6043 ast_value_factory()->reflect_construct_string(), NULL, args, pos); |
| 5956 } | 6044 } |
| 5957 } // namespace internal | 6045 } // namespace internal |
| 5958 } // namespace v8 | 6046 } // namespace v8 |
| OLD | NEW |