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/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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 new (zone()) ZoneList<Expression*>(2, zone()); | 364 new (zone()) ZoneList<Expression*>(2, zone()); |
365 VariableProxy* new_target_proxy = scope_->NewUnresolved( | 365 VariableProxy* new_target_proxy = scope_->NewUnresolved( |
366 factory(), ast_value_factory()->new_target_string(), Variable::NORMAL, | 366 factory(), ast_value_factory()->new_target_string(), Variable::NORMAL, |
367 pos); | 367 pos); |
368 args->Add(new_target_proxy, zone()); | 368 args->Add(new_target_proxy, zone()); |
369 VariableProxy* this_function_proxy = scope_->NewUnresolved( | 369 VariableProxy* this_function_proxy = scope_->NewUnresolved( |
370 factory(), ast_value_factory()->this_function_string(), | 370 factory(), ast_value_factory()->this_function_string(), |
371 Variable::NORMAL, pos); | 371 Variable::NORMAL, pos); |
372 args->Add(this_function_proxy, zone()); | 372 args->Add(this_function_proxy, zone()); |
373 CallRuntime* call = factory()->NewCallRuntime( | 373 CallRuntime* call = factory()->NewCallRuntime( |
374 ast_value_factory()->empty_string(), | 374 Runtime::kInlineDefaultConstructorCallSuper, args, pos); |
375 Runtime::FunctionForId(Runtime::kInlineDefaultConstructorCallSuper), | |
376 args, pos); | |
377 body->Add(factory()->NewReturnStatement(call, pos), zone()); | 375 body->Add(factory()->NewReturnStatement(call, pos), zone()); |
378 } | 376 } |
379 | 377 |
380 materialized_literal_count = function_state.materialized_literal_count(); | 378 materialized_literal_count = function_state.materialized_literal_count(); |
381 expected_property_count = function_state.expected_property_count(); | 379 expected_property_count = function_state.expected_property_count(); |
382 } | 380 } |
383 | 381 |
384 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( | 382 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( |
385 name, ast_value_factory(), function_scope, body, | 383 name, ast_value_factory(), function_scope, body, |
386 materialized_literal_count, expected_property_count, parameter_count, | 384 materialized_literal_count, expected_property_count, parameter_count, |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 } | 662 } |
665 | 663 |
666 | 664 |
667 Expression* ParserTraits::NewThrowError(Runtime::FunctionId id, | 665 Expression* ParserTraits::NewThrowError(Runtime::FunctionId id, |
668 MessageTemplate::Template message, | 666 MessageTemplate::Template message, |
669 const AstRawString* arg, int pos) { | 667 const AstRawString* arg, int pos) { |
670 Zone* zone = parser_->zone(); | 668 Zone* zone = parser_->zone(); |
671 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(2, zone); | 669 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(2, zone); |
672 args->Add(parser_->factory()->NewSmiLiteral(message, pos), zone); | 670 args->Add(parser_->factory()->NewSmiLiteral(message, pos), zone); |
673 args->Add(parser_->factory()->NewStringLiteral(arg, pos), zone); | 671 args->Add(parser_->factory()->NewStringLiteral(arg, pos), zone); |
674 CallRuntime* call_constructor = parser_->factory()->NewCallRuntime( | 672 CallRuntime* call_constructor = |
675 parser_->ast_value_factory()->empty_string(), Runtime::FunctionForId(id), | 673 parser_->factory()->NewCallRuntime(id, args, pos); |
676 args, pos); | |
677 return parser_->factory()->NewThrow(call_constructor, pos); | 674 return parser_->factory()->NewThrow(call_constructor, pos); |
678 } | 675 } |
679 | 676 |
680 | 677 |
681 void ParserTraits::ReportMessageAt(Scanner::Location source_location, | 678 void ParserTraits::ReportMessageAt(Scanner::Location source_location, |
682 MessageTemplate::Template message, | 679 MessageTemplate::Template message, |
683 const char* arg, ParseErrorType error_type) { | 680 const char* arg, ParseErrorType error_type) { |
684 if (parser_->stack_overflow()) { | 681 if (parser_->stack_overflow()) { |
685 // Suppress the error message (syntax error or such) in the presence of a | 682 // Suppress the error message (syntax error or such) in the presence of a |
686 // stack overflow. The isolate allows only one pending exception at at time | 683 // stack overflow. The isolate allows only one pending exception at at time |
(...skipping 2161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2848 | 2845 |
2849 Expression* throw_expression = | 2846 Expression* throw_expression = |
2850 NewThrowTypeError(MessageTemplate::kDerivedConstructorReturn, | 2847 NewThrowTypeError(MessageTemplate::kDerivedConstructorReturn, |
2851 ast_value_factory()->empty_string(), pos); | 2848 ast_value_factory()->empty_string(), pos); |
2852 | 2849 |
2853 // %_IsSpecObject(temp) | 2850 // %_IsSpecObject(temp) |
2854 ZoneList<Expression*>* is_spec_object_args = | 2851 ZoneList<Expression*>* is_spec_object_args = |
2855 new (zone()) ZoneList<Expression*>(1, zone()); | 2852 new (zone()) ZoneList<Expression*>(1, zone()); |
2856 is_spec_object_args->Add(factory()->NewVariableProxy(temp), zone()); | 2853 is_spec_object_args->Add(factory()->NewVariableProxy(temp), zone()); |
2857 Expression* is_spec_object_call = factory()->NewCallRuntime( | 2854 Expression* is_spec_object_call = factory()->NewCallRuntime( |
2858 ast_value_factory()->is_spec_object_string(), | 2855 Runtime::kInlineIsSpecObject, is_spec_object_args, pos); |
2859 Runtime::FunctionForId(Runtime::kInlineIsSpecObject), | |
2860 is_spec_object_args, pos); | |
2861 | 2856 |
2862 // %_IsSpecObject(temp) ? temp : throw_expression | 2857 // %_IsSpecObject(temp) ? temp : throw_expression |
2863 Expression* is_object_conditional = factory()->NewConditional( | 2858 Expression* is_object_conditional = factory()->NewConditional( |
2864 is_spec_object_call, factory()->NewVariableProxy(temp), | 2859 is_spec_object_call, factory()->NewVariableProxy(temp), |
2865 throw_expression, pos); | 2860 throw_expression, pos); |
2866 | 2861 |
2867 // temp === undefined | 2862 // temp === undefined |
2868 Expression* is_undefined = factory()->NewCompareOperation( | 2863 Expression* is_undefined = factory()->NewCompareOperation( |
2869 Token::EQ_STRICT, assign, | 2864 Token::EQ_STRICT, assign, |
2870 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition), pos); | 2865 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition), pos); |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3160 factory()->NewCall(next_property, next_arguments, pos); | 3155 factory()->NewCall(next_property, next_arguments, pos); |
3161 Expression* result_proxy = factory()->NewVariableProxy(result); | 3156 Expression* result_proxy = factory()->NewVariableProxy(result); |
3162 Expression* left = | 3157 Expression* left = |
3163 factory()->NewAssignment(Token::ASSIGN, result_proxy, next_call, pos); | 3158 factory()->NewAssignment(Token::ASSIGN, result_proxy, next_call, pos); |
3164 | 3159 |
3165 // %_IsSpecObject(...) | 3160 // %_IsSpecObject(...) |
3166 ZoneList<Expression*>* is_spec_object_args = | 3161 ZoneList<Expression*>* is_spec_object_args = |
3167 new (zone()) ZoneList<Expression*>(1, zone()); | 3162 new (zone()) ZoneList<Expression*>(1, zone()); |
3168 is_spec_object_args->Add(left, zone()); | 3163 is_spec_object_args->Add(left, zone()); |
3169 Expression* is_spec_object_call = factory()->NewCallRuntime( | 3164 Expression* is_spec_object_call = factory()->NewCallRuntime( |
3170 ast_value_factory()->is_spec_object_string(), | 3165 Runtime::kInlineIsSpecObject, is_spec_object_args, pos); |
3171 Runtime::FunctionForId(Runtime::kInlineIsSpecObject), is_spec_object_args, | |
3172 pos); | |
3173 | 3166 |
3174 // %ThrowIteratorResultNotAnObject(result) | 3167 // %ThrowIteratorResultNotAnObject(result) |
3175 Expression* result_proxy_again = factory()->NewVariableProxy(result); | 3168 Expression* result_proxy_again = factory()->NewVariableProxy(result); |
3176 ZoneList<Expression*>* throw_arguments = | 3169 ZoneList<Expression*>* throw_arguments = |
3177 new (zone()) ZoneList<Expression*>(1, zone()); | 3170 new (zone()) ZoneList<Expression*>(1, zone()); |
3178 throw_arguments->Add(result_proxy_again, zone()); | 3171 throw_arguments->Add(result_proxy_again, zone()); |
3179 Expression* throw_call = factory()->NewCallRuntime( | 3172 Expression* throw_call = factory()->NewCallRuntime( |
3180 ast_value_factory()->throw_iterator_result_not_an_object_string(), | 3173 Runtime::kThrowIteratorResultNotAnObject, throw_arguments, pos); |
3181 Runtime::FunctionForId(Runtime::kThrowIteratorResultNotAnObject), | |
3182 throw_arguments, pos); | |
3183 | 3174 |
3184 return factory()->NewBinaryOperation( | 3175 return factory()->NewBinaryOperation( |
3185 Token::AND, | 3176 Token::AND, |
3186 factory()->NewUnaryOperation(Token::NOT, is_spec_object_call, pos), | 3177 factory()->NewUnaryOperation(Token::NOT, is_spec_object_call, pos), |
3187 throw_call, pos); | 3178 throw_call, pos); |
3188 } | 3179 } |
3189 | 3180 |
3190 | 3181 |
3191 void Parser::InitializeForEachStatement(ForEachStatement* stmt, | 3182 void Parser::InitializeForEachStatement(ForEachStatement* stmt, |
3192 Expression* each, | 3183 Expression* each, |
(...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4278 *expected_property_count, scope_->language_mode(), | 4269 *expected_property_count, scope_->language_mode(), |
4279 scope_->uses_super_property(), scope_->calls_eval()); | 4270 scope_->uses_super_property(), scope_->calls_eval()); |
4280 } | 4271 } |
4281 } | 4272 } |
4282 | 4273 |
4283 | 4274 |
4284 void Parser::AddAssertIsConstruct(ZoneList<Statement*>* body, int pos) { | 4275 void Parser::AddAssertIsConstruct(ZoneList<Statement*>* body, int pos) { |
4285 ZoneList<Expression*>* arguments = | 4276 ZoneList<Expression*>* arguments = |
4286 new (zone()) ZoneList<Expression*>(0, zone()); | 4277 new (zone()) ZoneList<Expression*>(0, zone()); |
4287 CallRuntime* construct_check = factory()->NewCallRuntime( | 4278 CallRuntime* construct_check = factory()->NewCallRuntime( |
4288 ast_value_factory()->is_construct_call_string(), | 4279 Runtime::kInlineIsConstructCall, arguments, pos); |
4289 Runtime::FunctionForId(Runtime::kInlineIsConstructCall), arguments, pos); | |
4290 CallRuntime* non_callable_error = factory()->NewCallRuntime( | 4280 CallRuntime* non_callable_error = factory()->NewCallRuntime( |
4291 ast_value_factory()->empty_string(), | 4281 Runtime::kThrowConstructorNonCallableError, arguments, pos); |
4292 Runtime::FunctionForId(Runtime::kThrowConstructorNonCallableError), | |
4293 arguments, pos); | |
4294 IfStatement* if_statement = factory()->NewIfStatement( | 4282 IfStatement* if_statement = factory()->NewIfStatement( |
4295 factory()->NewUnaryOperation(Token::NOT, construct_check, pos), | 4283 factory()->NewUnaryOperation(Token::NOT, construct_check, pos), |
4296 factory()->NewReturnStatement(non_callable_error, pos), | 4284 factory()->NewReturnStatement(non_callable_error, pos), |
4297 factory()->NewEmptyStatement(pos), pos); | 4285 factory()->NewEmptyStatement(pos), pos); |
4298 body->Add(if_statement, zone()); | 4286 body->Add(if_statement, zone()); |
4299 } | 4287 } |
4300 | 4288 |
4301 | 4289 |
4302 Statement* Parser::BuildAssertIsCoercible(Variable* var) { | 4290 Statement* Parser::BuildAssertIsCoercible(Variable* var) { |
4303 // if (var === null || var === undefined) | 4291 // if (var === null || var === undefined) |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4435 } | 4423 } |
4436 | 4424 |
4437 { | 4425 { |
4438 BlockState block_state(&scope_, inner_scope); | 4426 BlockState block_state(&scope_, inner_scope); |
4439 | 4427 |
4440 // For generators, allocate and yield an iterator on function entry. | 4428 // For generators, allocate and yield an iterator on function entry. |
4441 if (IsGeneratorFunction(kind)) { | 4429 if (IsGeneratorFunction(kind)) { |
4442 ZoneList<Expression*>* arguments = | 4430 ZoneList<Expression*>* arguments = |
4443 new(zone()) ZoneList<Expression*>(0, zone()); | 4431 new(zone()) ZoneList<Expression*>(0, zone()); |
4444 CallRuntime* allocation = factory()->NewCallRuntime( | 4432 CallRuntime* allocation = factory()->NewCallRuntime( |
4445 ast_value_factory()->empty_string(), | 4433 Runtime::kCreateJSGeneratorObject, arguments, pos); |
4446 Runtime::FunctionForId(Runtime::kCreateJSGeneratorObject), arguments, | |
4447 pos); | |
4448 VariableProxy* init_proxy = factory()->NewVariableProxy( | 4434 VariableProxy* init_proxy = factory()->NewVariableProxy( |
4449 function_state_->generator_object_variable()); | 4435 function_state_->generator_object_variable()); |
4450 Assignment* assignment = factory()->NewAssignment( | 4436 Assignment* assignment = factory()->NewAssignment( |
4451 Token::INIT_VAR, init_proxy, allocation, RelocInfo::kNoPosition); | 4437 Token::INIT_VAR, init_proxy, allocation, RelocInfo::kNoPosition); |
4452 VariableProxy* get_proxy = factory()->NewVariableProxy( | 4438 VariableProxy* get_proxy = factory()->NewVariableProxy( |
4453 function_state_->generator_object_variable()); | 4439 function_state_->generator_object_variable()); |
4454 Yield* yield = factory()->NewYield( | 4440 Yield* yield = factory()->NewYield( |
4455 get_proxy, assignment, Yield::kInitial, RelocInfo::kNoPosition); | 4441 get_proxy, assignment, Yield::kInitial, RelocInfo::kNoPosition); |
4456 body->Add(factory()->NewExpressionStatement( | 4442 body->Add(factory()->NewExpressionStatement( |
4457 yield, RelocInfo::kNoPosition), zone()); | 4443 yield, RelocInfo::kNoPosition), zone()); |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4695 DCHECK(!spread_pos.IsValid()); | 4681 DCHECK(!spread_pos.IsValid()); |
4696 | 4682 |
4697 if (extension_ != NULL) { | 4683 if (extension_ != NULL) { |
4698 // The extension structures are only accessible while parsing the | 4684 // The extension structures are only accessible while parsing the |
4699 // very first time not when reparsing because of lazy compilation. | 4685 // very first time not when reparsing because of lazy compilation. |
4700 scope_->DeclarationScope()->ForceEagerCompilation(); | 4686 scope_->DeclarationScope()->ForceEagerCompilation(); |
4701 } | 4687 } |
4702 | 4688 |
4703 const Runtime::Function* function = Runtime::FunctionForName(name->string()); | 4689 const Runtime::Function* function = Runtime::FunctionForName(name->string()); |
4704 | 4690 |
4705 // Check for built-in IS_VAR macro. | 4691 if (function != NULL) { |
4706 if (function != NULL && | 4692 // Check for built-in IS_VAR macro. |
4707 function->intrinsic_type == Runtime::RUNTIME && | 4693 if (function->function_id == Runtime::kIS_VAR) { |
4708 function->function_id == Runtime::kIS_VAR) { | 4694 DCHECK_EQ(Runtime::RUNTIME, function->intrinsic_type); |
4709 // %IS_VAR(x) evaluates to x if x is a variable, | 4695 // %IS_VAR(x) evaluates to x if x is a variable, |
4710 // leads to a parse error otherwise. Could be implemented as an | 4696 // leads to a parse error otherwise. Could be implemented as an |
4711 // inline function %_IS_VAR(x) to eliminate this special case. | 4697 // inline function %_IS_VAR(x) to eliminate this special case. |
4712 if (args->length() == 1 && args->at(0)->AsVariableProxy() != NULL) { | 4698 if (args->length() == 1 && args->at(0)->AsVariableProxy() != NULL) { |
4713 return args->at(0); | 4699 return args->at(0); |
4714 } else { | 4700 } else { |
4715 ReportMessage(MessageTemplate::kNotIsvar); | 4701 ReportMessage(MessageTemplate::kNotIsvar); |
| 4702 *ok = false; |
| 4703 return NULL; |
| 4704 } |
| 4705 } |
| 4706 |
| 4707 // Check that the expected number of arguments are being passed. |
| 4708 if (function->nargs != -1 && function->nargs != args->length()) { |
| 4709 ReportMessage(MessageTemplate::kIllegalAccess); |
4716 *ok = false; | 4710 *ok = false; |
4717 return NULL; | 4711 return NULL; |
4718 } | 4712 } |
| 4713 |
| 4714 return factory()->NewCallRuntime(function, args, pos); |
4719 } | 4715 } |
4720 | 4716 |
4721 // Check that the expected number of arguments are being passed. | 4717 int context_index = Context::IntrinsicIndexForName(name->string()); |
4722 if (function != NULL && | |
4723 function->nargs != -1 && | |
4724 function->nargs != args->length()) { | |
4725 ReportMessage(MessageTemplate::kIllegalAccess); | |
4726 *ok = false; | |
4727 return NULL; | |
4728 } | |
4729 | 4718 |
4730 // Check that the function is defined if it's an inline runtime call. | 4719 // Check that the function is defined. |
4731 if (function == NULL && name->FirstCharacter() == '_') { | 4720 if (context_index == Context::kNotFound) { |
4732 ParserTraits::ReportMessage(MessageTemplate::kNotDefined, name); | 4721 ParserTraits::ReportMessage(MessageTemplate::kNotDefined, name); |
4733 *ok = false; | 4722 *ok = false; |
4734 return NULL; | 4723 return NULL; |
4735 } | 4724 } |
4736 | 4725 |
4737 // We have a valid intrinsics call or a call to a builtin. | 4726 return factory()->NewCallRuntime(context_index, args, pos); |
4738 return factory()->NewCallRuntime(name, function, args, pos); | |
4739 } | 4727 } |
4740 | 4728 |
4741 | 4729 |
4742 Literal* Parser::GetLiteralUndefined(int position) { | 4730 Literal* Parser::GetLiteralUndefined(int position) { |
4743 return factory()->NewUndefinedLiteral(position); | 4731 return factory()->NewUndefinedLiteral(position); |
4744 } | 4732 } |
4745 | 4733 |
4746 | 4734 |
4747 void Parser::CheckConflictingVarDeclarations(Scope* scope, bool* ok) { | 4735 void Parser::CheckConflictingVarDeclarations(Scope* scope, bool* ok) { |
4748 Declaration* decl = scope->CheckConflictingVarDeclarations(); | 4736 Declaration* decl = scope->CheckConflictingVarDeclarations(); |
(...skipping 1122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5871 int i = 0; | 5859 int i = 0; |
5872 while (i < expressions->length()) { | 5860 while (i < expressions->length()) { |
5873 Expression* sub = expressions->at(i++); | 5861 Expression* sub = expressions->at(i++); |
5874 Expression* cooked_str = cooked_strings->at(i); | 5862 Expression* cooked_str = cooked_strings->at(i); |
5875 | 5863 |
5876 // Let middle be ToString(sub). | 5864 // Let middle be ToString(sub). |
5877 ZoneList<Expression*>* args = | 5865 ZoneList<Expression*>* args = |
5878 new (zone()) ZoneList<Expression*>(1, zone()); | 5866 new (zone()) ZoneList<Expression*>(1, zone()); |
5879 args->Add(sub, zone()); | 5867 args->Add(sub, zone()); |
5880 Expression* middle = factory()->NewCallRuntime( | 5868 Expression* middle = factory()->NewCallRuntime( |
5881 ast_value_factory()->to_string_string(), NULL, args, | 5869 Context::TO_STRING_FUN_INDEX, args, sub->position()); |
5882 sub->position()); | |
5883 | 5870 |
5884 expr = factory()->NewBinaryOperation( | 5871 expr = factory()->NewBinaryOperation( |
5885 Token::ADD, factory()->NewBinaryOperation( | 5872 Token::ADD, factory()->NewBinaryOperation( |
5886 Token::ADD, expr, middle, expr->position()), | 5873 Token::ADD, expr, middle, expr->position()), |
5887 cooked_str, sub->position()); | 5874 cooked_str, sub->position()); |
5888 } | 5875 } |
5889 return expr; | 5876 return expr; |
5890 } else { | 5877 } else { |
5891 uint32_t hash = ComputeTemplateLiteralHash(lit); | 5878 uint32_t hash = ComputeTemplateLiteralHash(lit); |
5892 | 5879 |
(...skipping 11 matching lines...) Expand all Loading... |
5904 const_cast<ZoneList<Expression*>*>(raw_strings), raw_idx, | 5891 const_cast<ZoneList<Expression*>*>(raw_strings), raw_idx, |
5905 is_strong(language_mode()), pos), | 5892 is_strong(language_mode()), pos), |
5906 zone()); | 5893 zone()); |
5907 | 5894 |
5908 // Ensure hash is suitable as a Smi value | 5895 // Ensure hash is suitable as a Smi value |
5909 Smi* hash_obj = Smi::cast(Internals::IntToSmi(static_cast<int>(hash))); | 5896 Smi* hash_obj = Smi::cast(Internals::IntToSmi(static_cast<int>(hash))); |
5910 args->Add(factory()->NewSmiLiteral(hash_obj->value(), pos), zone()); | 5897 args->Add(factory()->NewSmiLiteral(hash_obj->value(), pos), zone()); |
5911 | 5898 |
5912 this->CheckPossibleEvalCall(tag, scope_); | 5899 this->CheckPossibleEvalCall(tag, scope_); |
5913 Expression* call_site = factory()->NewCallRuntime( | 5900 Expression* call_site = factory()->NewCallRuntime( |
5914 ast_value_factory()->get_template_callsite_string(), NULL, args, start); | 5901 Context::GET_TEMPLATE_CALL_SITE_INDEX, args, start); |
5915 | 5902 |
5916 // Call TagFn | 5903 // Call TagFn |
5917 ZoneList<Expression*>* call_args = | 5904 ZoneList<Expression*>* call_args = |
5918 new (zone()) ZoneList<Expression*>(expressions->length() + 1, zone()); | 5905 new (zone()) ZoneList<Expression*>(expressions->length() + 1, zone()); |
5919 call_args->Add(call_site, zone()); | 5906 call_args->Add(call_site, zone()); |
5920 call_args->AddAll(*expressions, zone()); | 5907 call_args->AddAll(*expressions, zone()); |
5921 return factory()->NewCall(tag, call_args, pos); | 5908 return factory()->NewCall(tag, call_args, pos); |
5922 } | 5909 } |
5923 } | 5910 } |
5924 | 5911 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5960 if (list->length() == 1) { | 5947 if (list->length() == 1) { |
5961 // Spread-call with single spread argument produces an InternalArray | 5948 // Spread-call with single spread argument produces an InternalArray |
5962 // containing the values from the array. | 5949 // containing the values from the array. |
5963 // | 5950 // |
5964 // Function is called or constructed with the produced array of arguments | 5951 // Function is called or constructed with the produced array of arguments |
5965 // | 5952 // |
5966 // EG: Apply(Func, Spread(spread0)) | 5953 // EG: Apply(Func, Spread(spread0)) |
5967 ZoneList<Expression*>* spread_list = | 5954 ZoneList<Expression*>* spread_list = |
5968 new (zone()) ZoneList<Expression*>(0, zone()); | 5955 new (zone()) ZoneList<Expression*>(0, zone()); |
5969 spread_list->Add(list->at(0)->AsSpread()->expression(), zone()); | 5956 spread_list->Add(list->at(0)->AsSpread()->expression(), zone()); |
5970 args->Add( | 5957 args->Add(factory()->NewCallRuntime(Context::SPREAD_ITERABLE_INDEX, |
5971 factory()->NewCallRuntime(ast_value_factory()->spread_iterable_string(), | 5958 spread_list, RelocInfo::kNoPosition), |
5972 NULL, spread_list, RelocInfo::kNoPosition), | 5959 zone()); |
5973 zone()); | |
5974 return args; | 5960 return args; |
5975 } else { | 5961 } else { |
5976 // Spread-call with multiple arguments produces array literals for each | 5962 // Spread-call with multiple arguments produces array literals for each |
5977 // sequences of unspread arguments, and converts each spread iterable to | 5963 // sequences of unspread arguments, and converts each spread iterable to |
5978 // an Internal array. Finally, all of these produced arrays are flattened | 5964 // an Internal array. Finally, all of these produced arrays are flattened |
5979 // into a single InternalArray, containing the arguments for the call. | 5965 // into a single InternalArray, containing the arguments for the call. |
5980 // | 5966 // |
5981 // EG: Apply(Func, Flatten([unspread0, unspread1], Spread(spread0), | 5967 // EG: Apply(Func, Flatten([unspread0, unspread1], Spread(spread0), |
5982 // Spread(spread1), [unspread2, unspread3])) | 5968 // Spread(spread1), [unspread2, unspread3])) |
5983 int i = 0; | 5969 int i = 0; |
(...skipping 13 matching lines...) Expand all Loading... |
5997 RelocInfo::kNoPosition), | 5983 RelocInfo::kNoPosition), |
5998 zone()); | 5984 zone()); |
5999 | 5985 |
6000 if (i == n) break; | 5986 if (i == n) break; |
6001 } | 5987 } |
6002 | 5988 |
6003 // Push eagerly spread argument | 5989 // Push eagerly spread argument |
6004 ZoneList<v8::internal::Expression*>* spread_list = | 5990 ZoneList<v8::internal::Expression*>* spread_list = |
6005 new (zone()) ZoneList<v8::internal::Expression*>(1, zone()); | 5991 new (zone()) ZoneList<v8::internal::Expression*>(1, zone()); |
6006 spread_list->Add(list->at(i++)->AsSpread()->expression(), zone()); | 5992 spread_list->Add(list->at(i++)->AsSpread()->expression(), zone()); |
6007 args->Add(factory()->NewCallRuntime( | 5993 args->Add(factory()->NewCallRuntime(Context::SPREAD_ITERABLE_INDEX, |
6008 ast_value_factory()->spread_iterable_string(), NULL, | 5994 spread_list, RelocInfo::kNoPosition), |
6009 spread_list, RelocInfo::kNoPosition), | |
6010 zone()); | 5995 zone()); |
6011 } | 5996 } |
6012 | 5997 |
6013 list = new (zone()) ZoneList<v8::internal::Expression*>(1, zone()); | 5998 list = new (zone()) ZoneList<v8::internal::Expression*>(1, zone()); |
6014 list->Add(factory()->NewCallRuntime( | 5999 list->Add(factory()->NewCallRuntime(Context::SPREAD_ARGUMENTS_INDEX, args, |
6015 ast_value_factory()->spread_arguments_string(), NULL, args, | 6000 RelocInfo::kNoPosition), |
6016 RelocInfo::kNoPosition), | |
6017 zone()); | 6001 zone()); |
6018 return list; | 6002 return list; |
6019 } | 6003 } |
6020 UNREACHABLE(); | 6004 UNREACHABLE(); |
6021 } | 6005 } |
6022 | 6006 |
6023 | 6007 |
6024 Expression* Parser::SpreadCall(Expression* function, | 6008 Expression* Parser::SpreadCall(Expression* function, |
6025 ZoneList<v8::internal::Expression*>* args, | 6009 ZoneList<v8::internal::Expression*>* args, |
6026 int pos) { | 6010 int pos) { |
6027 if (function->IsSuperCallReference()) { | 6011 if (function->IsSuperCallReference()) { |
6028 // Super calls | 6012 // Super calls |
6029 // %ReflectConstruct(%GetPrototype(<this-function>), args, new.target)) | 6013 // %ReflectConstruct(%GetPrototype(<this-function>), args, new.target)) |
6030 ZoneList<Expression*>* tmp = new (zone()) ZoneList<Expression*>(1, zone()); | 6014 ZoneList<Expression*>* tmp = new (zone()) ZoneList<Expression*>(1, zone()); |
6031 tmp->Add(function->AsSuperCallReference()->this_function_var(), zone()); | 6015 tmp->Add(function->AsSuperCallReference()->this_function_var(), zone()); |
6032 Expression* get_prototype = factory()->NewCallRuntime( | 6016 Expression* get_prototype = |
6033 ast_value_factory()->empty_string(), | 6017 factory()->NewCallRuntime(Runtime::kGetPrototype, tmp, pos); |
6034 Runtime::FunctionForId(Runtime::kGetPrototype), tmp, pos); | |
6035 args->InsertAt(0, get_prototype, zone()); | 6018 args->InsertAt(0, get_prototype, zone()); |
6036 args->Add(function->AsSuperCallReference()->new_target_var(), zone()); | 6019 args->Add(function->AsSuperCallReference()->new_target_var(), zone()); |
6037 return factory()->NewCallRuntime( | 6020 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, |
6038 ast_value_factory()->reflect_construct_string(), NULL, args, pos); | 6021 pos); |
6039 } else { | 6022 } else { |
6040 if (function->IsProperty()) { | 6023 if (function->IsProperty()) { |
6041 // Method calls | 6024 // Method calls |
6042 if (function->AsProperty()->IsSuperAccess()) { | 6025 if (function->AsProperty()->IsSuperAccess()) { |
6043 Expression* home = | 6026 Expression* home = |
6044 ThisExpression(scope_, factory(), RelocInfo::kNoPosition); | 6027 ThisExpression(scope_, factory(), RelocInfo::kNoPosition); |
6045 args->InsertAt(0, function, zone()); | 6028 args->InsertAt(0, function, zone()); |
6046 args->InsertAt(1, home, zone()); | 6029 args->InsertAt(1, home, zone()); |
6047 } else { | 6030 } else { |
6048 Variable* temp = | 6031 Variable* temp = |
6049 scope_->NewTemporary(ast_value_factory()->empty_string()); | 6032 scope_->NewTemporary(ast_value_factory()->empty_string()); |
6050 VariableProxy* obj = factory()->NewVariableProxy(temp); | 6033 VariableProxy* obj = factory()->NewVariableProxy(temp); |
6051 Assignment* assign_obj = factory()->NewAssignment( | 6034 Assignment* assign_obj = factory()->NewAssignment( |
6052 Token::ASSIGN, obj, function->AsProperty()->obj(), | 6035 Token::ASSIGN, obj, function->AsProperty()->obj(), |
6053 RelocInfo::kNoPosition); | 6036 RelocInfo::kNoPosition); |
6054 function = factory()->NewProperty( | 6037 function = factory()->NewProperty( |
6055 assign_obj, function->AsProperty()->key(), RelocInfo::kNoPosition); | 6038 assign_obj, function->AsProperty()->key(), RelocInfo::kNoPosition); |
6056 args->InsertAt(0, function, zone()); | 6039 args->InsertAt(0, function, zone()); |
6057 obj = factory()->NewVariableProxy(temp); | 6040 obj = factory()->NewVariableProxy(temp); |
6058 args->InsertAt(1, obj, zone()); | 6041 args->InsertAt(1, obj, zone()); |
6059 } | 6042 } |
6060 } else { | 6043 } else { |
6061 // Non-method calls | 6044 // Non-method calls |
6062 args->InsertAt(0, function, zone()); | 6045 args->InsertAt(0, function, zone()); |
6063 args->InsertAt(1, factory()->NewUndefinedLiteral(RelocInfo::kNoPosition), | 6046 args->InsertAt(1, factory()->NewUndefinedLiteral(RelocInfo::kNoPosition), |
6064 zone()); | 6047 zone()); |
6065 } | 6048 } |
6066 return factory()->NewCallRuntime( | 6049 return factory()->NewCallRuntime(Context::REFLECT_APPLY_INDEX, args, pos); |
6067 ast_value_factory()->reflect_apply_string(), NULL, args, pos); | |
6068 } | 6050 } |
6069 } | 6051 } |
6070 | 6052 |
6071 | 6053 |
6072 Expression* Parser::SpreadCallNew(Expression* function, | 6054 Expression* Parser::SpreadCallNew(Expression* function, |
6073 ZoneList<v8::internal::Expression*>* args, | 6055 ZoneList<v8::internal::Expression*>* args, |
6074 int pos) { | 6056 int pos) { |
6075 args->InsertAt(0, function, zone()); | 6057 args->InsertAt(0, function, zone()); |
6076 | 6058 |
6077 return factory()->NewCallRuntime( | 6059 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); |
6078 ast_value_factory()->reflect_construct_string(), NULL, args, pos); | |
6079 } | 6060 } |
6080 } // namespace internal | 6061 } // namespace internal |
6081 } // namespace v8 | 6062 } // namespace v8 |
OLD | NEW |