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

Side by Side Diff: src/parser.cc

Issue 1306993003: Call JS functions via native context instead of js builtins object. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase Created 5 years, 3 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/object-observe.js ('k') | src/pattern-rewriter.cc » ('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/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
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
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
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 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
3201 factory()->NewCall(next_property, next_arguments, pos); 3196 factory()->NewCall(next_property, next_arguments, pos);
3202 Expression* result_proxy = factory()->NewVariableProxy(result); 3197 Expression* result_proxy = factory()->NewVariableProxy(result);
3203 Expression* left = 3198 Expression* left =
3204 factory()->NewAssignment(Token::ASSIGN, result_proxy, next_call, pos); 3199 factory()->NewAssignment(Token::ASSIGN, result_proxy, next_call, pos);
3205 3200
3206 // %_IsSpecObject(...) 3201 // %_IsSpecObject(...)
3207 ZoneList<Expression*>* is_spec_object_args = 3202 ZoneList<Expression*>* is_spec_object_args =
3208 new (zone()) ZoneList<Expression*>(1, zone()); 3203 new (zone()) ZoneList<Expression*>(1, zone());
3209 is_spec_object_args->Add(left, zone()); 3204 is_spec_object_args->Add(left, zone());
3210 Expression* is_spec_object_call = factory()->NewCallRuntime( 3205 Expression* is_spec_object_call = factory()->NewCallRuntime(
3211 ast_value_factory()->is_spec_object_string(), 3206 Runtime::kInlineIsSpecObject, is_spec_object_args, pos);
3212 Runtime::FunctionForId(Runtime::kInlineIsSpecObject), is_spec_object_args,
3213 pos);
3214 3207
3215 // %ThrowIteratorResultNotAnObject(result) 3208 // %ThrowIteratorResultNotAnObject(result)
3216 Expression* result_proxy_again = factory()->NewVariableProxy(result); 3209 Expression* result_proxy_again = factory()->NewVariableProxy(result);
3217 ZoneList<Expression*>* throw_arguments = 3210 ZoneList<Expression*>* throw_arguments =
3218 new (zone()) ZoneList<Expression*>(1, zone()); 3211 new (zone()) ZoneList<Expression*>(1, zone());
3219 throw_arguments->Add(result_proxy_again, zone()); 3212 throw_arguments->Add(result_proxy_again, zone());
3220 Expression* throw_call = factory()->NewCallRuntime( 3213 Expression* throw_call = factory()->NewCallRuntime(
3221 ast_value_factory()->throw_iterator_result_not_an_object_string(), 3214 Runtime::kThrowIteratorResultNotAnObject, throw_arguments, pos);
3222 Runtime::FunctionForId(Runtime::kThrowIteratorResultNotAnObject),
3223 throw_arguments, pos);
3224 3215
3225 return factory()->NewBinaryOperation( 3216 return factory()->NewBinaryOperation(
3226 Token::AND, 3217 Token::AND,
3227 factory()->NewUnaryOperation(Token::NOT, is_spec_object_call, pos), 3218 factory()->NewUnaryOperation(Token::NOT, is_spec_object_call, pos),
3228 throw_call, pos); 3219 throw_call, pos);
3229 } 3220 }
3230 3221
3231 3222
3232 void Parser::InitializeForEachStatement(ForEachStatement* stmt, 3223 void Parser::InitializeForEachStatement(ForEachStatement* stmt,
3233 Expression* each, 3224 Expression* each,
(...skipping 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after
4315 *expected_property_count, scope_->language_mode(), 4306 *expected_property_count, scope_->language_mode(),
4316 scope_->uses_super_property(), scope_->calls_eval()); 4307 scope_->uses_super_property(), scope_->calls_eval());
4317 } 4308 }
4318 } 4309 }
4319 4310
4320 4311
4321 void Parser::AddAssertIsConstruct(ZoneList<Statement*>* body, int pos) { 4312 void Parser::AddAssertIsConstruct(ZoneList<Statement*>* body, int pos) {
4322 ZoneList<Expression*>* arguments = 4313 ZoneList<Expression*>* arguments =
4323 new (zone()) ZoneList<Expression*>(0, zone()); 4314 new (zone()) ZoneList<Expression*>(0, zone());
4324 CallRuntime* construct_check = factory()->NewCallRuntime( 4315 CallRuntime* construct_check = factory()->NewCallRuntime(
4325 ast_value_factory()->is_construct_call_string(), 4316 Runtime::kInlineIsConstructCall, arguments, pos);
4326 Runtime::FunctionForId(Runtime::kInlineIsConstructCall), arguments, pos);
4327 CallRuntime* non_callable_error = factory()->NewCallRuntime( 4317 CallRuntime* non_callable_error = factory()->NewCallRuntime(
4328 ast_value_factory()->empty_string(), 4318 Runtime::kThrowConstructorNonCallableError, arguments, pos);
4329 Runtime::FunctionForId(Runtime::kThrowConstructorNonCallableError),
4330 arguments, pos);
4331 IfStatement* if_statement = factory()->NewIfStatement( 4319 IfStatement* if_statement = factory()->NewIfStatement(
4332 factory()->NewUnaryOperation(Token::NOT, construct_check, pos), 4320 factory()->NewUnaryOperation(Token::NOT, construct_check, pos),
4333 factory()->NewReturnStatement(non_callable_error, pos), 4321 factory()->NewReturnStatement(non_callable_error, pos),
4334 factory()->NewEmptyStatement(pos), pos); 4322 factory()->NewEmptyStatement(pos), pos);
4335 body->Add(if_statement, zone()); 4323 body->Add(if_statement, zone());
4336 } 4324 }
4337 4325
4338 4326
4339 Statement* Parser::BuildAssertIsCoercible(Variable* var) { 4327 Statement* Parser::BuildAssertIsCoercible(Variable* var) {
4340 // if (var === null || var === undefined) 4328 // if (var === null || var === undefined)
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
4472 } 4460 }
4473 4461
4474 { 4462 {
4475 BlockState block_state(&scope_, inner_scope); 4463 BlockState block_state(&scope_, inner_scope);
4476 4464
4477 // For generators, allocate and yield an iterator on function entry. 4465 // For generators, allocate and yield an iterator on function entry.
4478 if (IsGeneratorFunction(kind)) { 4466 if (IsGeneratorFunction(kind)) {
4479 ZoneList<Expression*>* arguments = 4467 ZoneList<Expression*>* arguments =
4480 new(zone()) ZoneList<Expression*>(0, zone()); 4468 new(zone()) ZoneList<Expression*>(0, zone());
4481 CallRuntime* allocation = factory()->NewCallRuntime( 4469 CallRuntime* allocation = factory()->NewCallRuntime(
4482 ast_value_factory()->empty_string(), 4470 Runtime::kCreateJSGeneratorObject, arguments, pos);
4483 Runtime::FunctionForId(Runtime::kCreateJSGeneratorObject), arguments,
4484 pos);
4485 VariableProxy* init_proxy = factory()->NewVariableProxy( 4471 VariableProxy* init_proxy = factory()->NewVariableProxy(
4486 function_state_->generator_object_variable()); 4472 function_state_->generator_object_variable());
4487 Assignment* assignment = factory()->NewAssignment( 4473 Assignment* assignment = factory()->NewAssignment(
4488 Token::INIT_VAR, init_proxy, allocation, RelocInfo::kNoPosition); 4474 Token::INIT_VAR, init_proxy, allocation, RelocInfo::kNoPosition);
4489 VariableProxy* get_proxy = factory()->NewVariableProxy( 4475 VariableProxy* get_proxy = factory()->NewVariableProxy(
4490 function_state_->generator_object_variable()); 4476 function_state_->generator_object_variable());
4491 Yield* yield = factory()->NewYield( 4477 Yield* yield = factory()->NewYield(
4492 get_proxy, assignment, Yield::kInitial, RelocInfo::kNoPosition); 4478 get_proxy, assignment, Yield::kInitial, RelocInfo::kNoPosition);
4493 body->Add(factory()->NewExpressionStatement( 4479 body->Add(factory()->NewExpressionStatement(
4494 yield, RelocInfo::kNoPosition), zone()); 4480 yield, RelocInfo::kNoPosition), zone());
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
4732 DCHECK(!spread_pos.IsValid()); 4718 DCHECK(!spread_pos.IsValid());
4733 4719
4734 if (extension_ != NULL) { 4720 if (extension_ != NULL) {
4735 // The extension structures are only accessible while parsing the 4721 // The extension structures are only accessible while parsing the
4736 // very first time not when reparsing because of lazy compilation. 4722 // very first time not when reparsing because of lazy compilation.
4737 scope_->DeclarationScope()->ForceEagerCompilation(); 4723 scope_->DeclarationScope()->ForceEagerCompilation();
4738 } 4724 }
4739 4725
4740 const Runtime::Function* function = Runtime::FunctionForName(name->string()); 4726 const Runtime::Function* function = Runtime::FunctionForName(name->string());
4741 4727
4742 // Check for built-in IS_VAR macro. 4728 if (function != NULL) {
4743 if (function != NULL && 4729 // Check for built-in IS_VAR macro.
4744 function->intrinsic_type == Runtime::RUNTIME && 4730 if (function->function_id == Runtime::kIS_VAR) {
4745 function->function_id == Runtime::kIS_VAR) { 4731 DCHECK_EQ(Runtime::RUNTIME, function->intrinsic_type);
4746 // %IS_VAR(x) evaluates to x if x is a variable, 4732 // %IS_VAR(x) evaluates to x if x is a variable,
4747 // leads to a parse error otherwise. Could be implemented as an 4733 // leads to a parse error otherwise. Could be implemented as an
4748 // inline function %_IS_VAR(x) to eliminate this special case. 4734 // inline function %_IS_VAR(x) to eliminate this special case.
4749 if (args->length() == 1 && args->at(0)->AsVariableProxy() != NULL) { 4735 if (args->length() == 1 && args->at(0)->AsVariableProxy() != NULL) {
4750 return args->at(0); 4736 return args->at(0);
4751 } else { 4737 } else {
4752 ReportMessage(MessageTemplate::kNotIsvar); 4738 ReportMessage(MessageTemplate::kNotIsvar);
4739 *ok = false;
4740 return NULL;
4741 }
4742 }
4743
4744 // Check that the expected number of arguments are being passed.
4745 if (function->nargs != -1 && function->nargs != args->length()) {
4746 ReportMessage(MessageTemplate::kIllegalAccess);
4753 *ok = false; 4747 *ok = false;
4754 return NULL; 4748 return NULL;
4755 } 4749 }
4750
4751 return factory()->NewCallRuntime(function, args, pos);
4756 } 4752 }
4757 4753
4758 // Check that the expected number of arguments are being passed. 4754 int context_index = Context::IntrinsicIndexForName(name->string());
4759 if (function != NULL &&
4760 function->nargs != -1 &&
4761 function->nargs != args->length()) {
4762 ReportMessage(MessageTemplate::kIllegalAccess);
4763 *ok = false;
4764 return NULL;
4765 }
4766 4755
4767 // Check that the function is defined if it's an inline runtime call. 4756 // Check that the function is defined.
4768 if (function == NULL && name->FirstCharacter() == '_') { 4757 if (context_index == Context::kNotFound) {
4769 ParserTraits::ReportMessage(MessageTemplate::kNotDefined, name); 4758 ParserTraits::ReportMessage(MessageTemplate::kNotDefined, name);
4770 *ok = false; 4759 *ok = false;
4771 return NULL; 4760 return NULL;
4772 } 4761 }
4773 4762
4774 // We have a valid intrinsics call or a call to a builtin. 4763 return factory()->NewCallRuntime(context_index, args, pos);
4775 return factory()->NewCallRuntime(name, function, args, pos);
4776 } 4764 }
4777 4765
4778 4766
4779 Literal* Parser::GetLiteralUndefined(int position) { 4767 Literal* Parser::GetLiteralUndefined(int position) {
4780 return factory()->NewUndefinedLiteral(position); 4768 return factory()->NewUndefinedLiteral(position);
4781 } 4769 }
4782 4770
4783 4771
4784 void Parser::CheckConflictingVarDeclarations(Scope* scope, bool* ok) { 4772 void Parser::CheckConflictingVarDeclarations(Scope* scope, bool* ok) {
4785 Declaration* decl = scope->CheckConflictingVarDeclarations(); 4773 Declaration* decl = scope->CheckConflictingVarDeclarations();
(...skipping 1122 matching lines...) Expand 10 before | Expand all | Expand 10 after
5908 int i = 0; 5896 int i = 0;
5909 while (i < expressions->length()) { 5897 while (i < expressions->length()) {
5910 Expression* sub = expressions->at(i++); 5898 Expression* sub = expressions->at(i++);
5911 Expression* cooked_str = cooked_strings->at(i); 5899 Expression* cooked_str = cooked_strings->at(i);
5912 5900
5913 // Let middle be ToString(sub). 5901 // Let middle be ToString(sub).
5914 ZoneList<Expression*>* args = 5902 ZoneList<Expression*>* args =
5915 new (zone()) ZoneList<Expression*>(1, zone()); 5903 new (zone()) ZoneList<Expression*>(1, zone());
5916 args->Add(sub, zone()); 5904 args->Add(sub, zone());
5917 Expression* middle = factory()->NewCallRuntime( 5905 Expression* middle = factory()->NewCallRuntime(
5918 ast_value_factory()->to_string_string(), NULL, args, 5906 Context::TO_STRING_FUN_INDEX, args, sub->position());
5919 sub->position());
5920 5907
5921 expr = factory()->NewBinaryOperation( 5908 expr = factory()->NewBinaryOperation(
5922 Token::ADD, factory()->NewBinaryOperation( 5909 Token::ADD, factory()->NewBinaryOperation(
5923 Token::ADD, expr, middle, expr->position()), 5910 Token::ADD, expr, middle, expr->position()),
5924 cooked_str, sub->position()); 5911 cooked_str, sub->position());
5925 } 5912 }
5926 return expr; 5913 return expr;
5927 } else { 5914 } else {
5928 uint32_t hash = ComputeTemplateLiteralHash(lit); 5915 uint32_t hash = ComputeTemplateLiteralHash(lit);
5929 5916
(...skipping 11 matching lines...) Expand all
5941 const_cast<ZoneList<Expression*>*>(raw_strings), raw_idx, 5928 const_cast<ZoneList<Expression*>*>(raw_strings), raw_idx,
5942 is_strong(language_mode()), pos), 5929 is_strong(language_mode()), pos),
5943 zone()); 5930 zone());
5944 5931
5945 // Ensure hash is suitable as a Smi value 5932 // Ensure hash is suitable as a Smi value
5946 Smi* hash_obj = Smi::cast(Internals::IntToSmi(static_cast<int>(hash))); 5933 Smi* hash_obj = Smi::cast(Internals::IntToSmi(static_cast<int>(hash)));
5947 args->Add(factory()->NewSmiLiteral(hash_obj->value(), pos), zone()); 5934 args->Add(factory()->NewSmiLiteral(hash_obj->value(), pos), zone());
5948 5935
5949 this->CheckPossibleEvalCall(tag, scope_); 5936 this->CheckPossibleEvalCall(tag, scope_);
5950 Expression* call_site = factory()->NewCallRuntime( 5937 Expression* call_site = factory()->NewCallRuntime(
5951 ast_value_factory()->get_template_callsite_string(), NULL, args, start); 5938 Context::GET_TEMPLATE_CALL_SITE_INDEX, args, start);
5952 5939
5953 // Call TagFn 5940 // Call TagFn
5954 ZoneList<Expression*>* call_args = 5941 ZoneList<Expression*>* call_args =
5955 new (zone()) ZoneList<Expression*>(expressions->length() + 1, zone()); 5942 new (zone()) ZoneList<Expression*>(expressions->length() + 1, zone());
5956 call_args->Add(call_site, zone()); 5943 call_args->Add(call_site, zone());
5957 call_args->AddAll(*expressions, zone()); 5944 call_args->AddAll(*expressions, zone());
5958 return factory()->NewCall(tag, call_args, pos); 5945 return factory()->NewCall(tag, call_args, pos);
5959 } 5946 }
5960 } 5947 }
5961 5948
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
5997 if (list->length() == 1) { 5984 if (list->length() == 1) {
5998 // Spread-call with single spread argument produces an InternalArray 5985 // Spread-call with single spread argument produces an InternalArray
5999 // containing the values from the array. 5986 // containing the values from the array.
6000 // 5987 //
6001 // Function is called or constructed with the produced array of arguments 5988 // Function is called or constructed with the produced array of arguments
6002 // 5989 //
6003 // EG: Apply(Func, Spread(spread0)) 5990 // EG: Apply(Func, Spread(spread0))
6004 ZoneList<Expression*>* spread_list = 5991 ZoneList<Expression*>* spread_list =
6005 new (zone()) ZoneList<Expression*>(0, zone()); 5992 new (zone()) ZoneList<Expression*>(0, zone());
6006 spread_list->Add(list->at(0)->AsSpread()->expression(), zone()); 5993 spread_list->Add(list->at(0)->AsSpread()->expression(), zone());
6007 args->Add( 5994 args->Add(factory()->NewCallRuntime(Context::SPREAD_ITERABLE_INDEX,
6008 factory()->NewCallRuntime(ast_value_factory()->spread_iterable_string(), 5995 spread_list, RelocInfo::kNoPosition),
6009 NULL, spread_list, RelocInfo::kNoPosition), 5996 zone());
6010 zone());
6011 return args; 5997 return args;
6012 } else { 5998 } else {
6013 // Spread-call with multiple arguments produces array literals for each 5999 // Spread-call with multiple arguments produces array literals for each
6014 // sequences of unspread arguments, and converts each spread iterable to 6000 // sequences of unspread arguments, and converts each spread iterable to
6015 // an Internal array. Finally, all of these produced arrays are flattened 6001 // an Internal array. Finally, all of these produced arrays are flattened
6016 // into a single InternalArray, containing the arguments for the call. 6002 // into a single InternalArray, containing the arguments for the call.
6017 // 6003 //
6018 // EG: Apply(Func, Flatten([unspread0, unspread1], Spread(spread0), 6004 // EG: Apply(Func, Flatten([unspread0, unspread1], Spread(spread0),
6019 // Spread(spread1), [unspread2, unspread3])) 6005 // Spread(spread1), [unspread2, unspread3]))
6020 int i = 0; 6006 int i = 0;
(...skipping 13 matching lines...) Expand all
6034 RelocInfo::kNoPosition), 6020 RelocInfo::kNoPosition),
6035 zone()); 6021 zone());
6036 6022
6037 if (i == n) break; 6023 if (i == n) break;
6038 } 6024 }
6039 6025
6040 // Push eagerly spread argument 6026 // Push eagerly spread argument
6041 ZoneList<v8::internal::Expression*>* spread_list = 6027 ZoneList<v8::internal::Expression*>* spread_list =
6042 new (zone()) ZoneList<v8::internal::Expression*>(1, zone()); 6028 new (zone()) ZoneList<v8::internal::Expression*>(1, zone());
6043 spread_list->Add(list->at(i++)->AsSpread()->expression(), zone()); 6029 spread_list->Add(list->at(i++)->AsSpread()->expression(), zone());
6044 args->Add(factory()->NewCallRuntime( 6030 args->Add(factory()->NewCallRuntime(Context::SPREAD_ITERABLE_INDEX,
6045 ast_value_factory()->spread_iterable_string(), NULL, 6031 spread_list, RelocInfo::kNoPosition),
6046 spread_list, RelocInfo::kNoPosition),
6047 zone()); 6032 zone());
6048 } 6033 }
6049 6034
6050 list = new (zone()) ZoneList<v8::internal::Expression*>(1, zone()); 6035 list = new (zone()) ZoneList<v8::internal::Expression*>(1, zone());
6051 list->Add(factory()->NewCallRuntime( 6036 list->Add(factory()->NewCallRuntime(Context::SPREAD_ARGUMENTS_INDEX, args,
6052 ast_value_factory()->spread_arguments_string(), NULL, args, 6037 RelocInfo::kNoPosition),
6053 RelocInfo::kNoPosition),
6054 zone()); 6038 zone());
6055 return list; 6039 return list;
6056 } 6040 }
6057 UNREACHABLE(); 6041 UNREACHABLE();
6058 } 6042 }
6059 6043
6060 6044
6061 Expression* Parser::SpreadCall(Expression* function, 6045 Expression* Parser::SpreadCall(Expression* function,
6062 ZoneList<v8::internal::Expression*>* args, 6046 ZoneList<v8::internal::Expression*>* args,
6063 int pos) { 6047 int pos) {
6064 if (function->IsSuperCallReference()) { 6048 if (function->IsSuperCallReference()) {
6065 // Super calls 6049 // Super calls
6066 // %ReflectConstruct(%GetPrototype(<this-function>), args, new.target)) 6050 // %ReflectConstruct(%GetPrototype(<this-function>), args, new.target))
6067 ZoneList<Expression*>* tmp = new (zone()) ZoneList<Expression*>(1, zone()); 6051 ZoneList<Expression*>* tmp = new (zone()) ZoneList<Expression*>(1, zone());
6068 tmp->Add(function->AsSuperCallReference()->this_function_var(), zone()); 6052 tmp->Add(function->AsSuperCallReference()->this_function_var(), zone());
6069 Expression* get_prototype = factory()->NewCallRuntime( 6053 Expression* get_prototype =
6070 ast_value_factory()->empty_string(), 6054 factory()->NewCallRuntime(Runtime::kGetPrototype, tmp, pos);
6071 Runtime::FunctionForId(Runtime::kGetPrototype), tmp, pos);
6072 args->InsertAt(0, get_prototype, zone()); 6055 args->InsertAt(0, get_prototype, zone());
6073 args->Add(function->AsSuperCallReference()->new_target_var(), zone()); 6056 args->Add(function->AsSuperCallReference()->new_target_var(), zone());
6074 return factory()->NewCallRuntime( 6057 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args,
6075 ast_value_factory()->reflect_construct_string(), NULL, args, pos); 6058 pos);
6076 } else { 6059 } else {
6077 if (function->IsProperty()) { 6060 if (function->IsProperty()) {
6078 // Method calls 6061 // Method calls
6079 if (function->AsProperty()->IsSuperAccess()) { 6062 if (function->AsProperty()->IsSuperAccess()) {
6080 Expression* home = 6063 Expression* home =
6081 ThisExpression(scope_, factory(), RelocInfo::kNoPosition); 6064 ThisExpression(scope_, factory(), RelocInfo::kNoPosition);
6082 args->InsertAt(0, function, zone()); 6065 args->InsertAt(0, function, zone());
6083 args->InsertAt(1, home, zone()); 6066 args->InsertAt(1, home, zone());
6084 } else { 6067 } else {
6085 Variable* temp = 6068 Variable* temp =
6086 scope_->NewTemporary(ast_value_factory()->empty_string()); 6069 scope_->NewTemporary(ast_value_factory()->empty_string());
6087 VariableProxy* obj = factory()->NewVariableProxy(temp); 6070 VariableProxy* obj = factory()->NewVariableProxy(temp);
6088 Assignment* assign_obj = factory()->NewAssignment( 6071 Assignment* assign_obj = factory()->NewAssignment(
6089 Token::ASSIGN, obj, function->AsProperty()->obj(), 6072 Token::ASSIGN, obj, function->AsProperty()->obj(),
6090 RelocInfo::kNoPosition); 6073 RelocInfo::kNoPosition);
6091 function = factory()->NewProperty( 6074 function = factory()->NewProperty(
6092 assign_obj, function->AsProperty()->key(), RelocInfo::kNoPosition); 6075 assign_obj, function->AsProperty()->key(), RelocInfo::kNoPosition);
6093 args->InsertAt(0, function, zone()); 6076 args->InsertAt(0, function, zone());
6094 obj = factory()->NewVariableProxy(temp); 6077 obj = factory()->NewVariableProxy(temp);
6095 args->InsertAt(1, obj, zone()); 6078 args->InsertAt(1, obj, zone());
6096 } 6079 }
6097 } else { 6080 } else {
6098 // Non-method calls 6081 // Non-method calls
6099 args->InsertAt(0, function, zone()); 6082 args->InsertAt(0, function, zone());
6100 args->InsertAt(1, factory()->NewUndefinedLiteral(RelocInfo::kNoPosition), 6083 args->InsertAt(1, factory()->NewUndefinedLiteral(RelocInfo::kNoPosition),
6101 zone()); 6084 zone());
6102 } 6085 }
6103 return factory()->NewCallRuntime( 6086 return factory()->NewCallRuntime(Context::REFLECT_APPLY_INDEX, args, pos);
6104 ast_value_factory()->reflect_apply_string(), NULL, args, pos);
6105 } 6087 }
6106 } 6088 }
6107 6089
6108 6090
6109 Expression* Parser::SpreadCallNew(Expression* function, 6091 Expression* Parser::SpreadCallNew(Expression* function,
6110 ZoneList<v8::internal::Expression*>* args, 6092 ZoneList<v8::internal::Expression*>* args,
6111 int pos) { 6093 int pos) {
6112 args->InsertAt(0, function, zone()); 6094 args->InsertAt(0, function, zone());
6113 6095
6114 return factory()->NewCallRuntime( 6096 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos);
6115 ast_value_factory()->reflect_construct_string(), NULL, args, pos);
6116 } 6097 }
6117 } // namespace internal 6098 } // namespace internal
6118 } // namespace v8 6099 } // namespace v8
OLDNEW
« no previous file with comments | « src/object-observe.js ('k') | src/pattern-rewriter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698