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

Side by Side Diff: src/parser.cc

Issue 938443002: [es6] implement spread calls (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add more variations to evaluation order tests Created 5 years, 9 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
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/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/bailout-reason.h" 9 #include "src/bailout-reason.h"
10 #include "src/base/platform/platform.h" 10 #include "src/base/platform/platform.h"
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 set_allow_harmony_arrow_functions(FLAG_harmony_arrow_functions); 808 set_allow_harmony_arrow_functions(FLAG_harmony_arrow_functions);
809 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); 809 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals);
810 set_allow_harmony_classes(FLAG_harmony_classes); 810 set_allow_harmony_classes(FLAG_harmony_classes);
811 set_allow_harmony_object_literals(FLAG_harmony_object_literals); 811 set_allow_harmony_object_literals(FLAG_harmony_object_literals);
812 set_allow_harmony_templates(FLAG_harmony_templates); 812 set_allow_harmony_templates(FLAG_harmony_templates);
813 set_allow_harmony_sloppy(FLAG_harmony_sloppy); 813 set_allow_harmony_sloppy(FLAG_harmony_sloppy);
814 set_allow_harmony_unicode(FLAG_harmony_unicode); 814 set_allow_harmony_unicode(FLAG_harmony_unicode);
815 set_allow_harmony_computed_property_names( 815 set_allow_harmony_computed_property_names(
816 FLAG_harmony_computed_property_names); 816 FLAG_harmony_computed_property_names);
817 set_allow_harmony_rest_params(FLAG_harmony_rest_parameters); 817 set_allow_harmony_rest_params(FLAG_harmony_rest_parameters);
818 set_allow_harmony_spreadcalls(FLAG_harmony_spreadcalls);
818 set_allow_strong_mode(FLAG_strong_mode); 819 set_allow_strong_mode(FLAG_strong_mode);
819 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; 820 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount;
820 ++feature) { 821 ++feature) {
821 use_counts_[feature] = 0; 822 use_counts_[feature] = 0;
822 } 823 }
823 if (info->ast_value_factory() == NULL) { 824 if (info->ast_value_factory() == NULL) {
824 // info takes ownership of AstValueFactory. 825 // info takes ownership of AstValueFactory.
825 info->SetAstValueFactory(new AstValueFactory(zone(), hash_seed)); 826 info->SetAstValueFactory(new AstValueFactory(zone(), hash_seed));
826 ast_value_factory_ = info->ast_value_factory(); 827 ast_value_factory_ = info->ast_value_factory();
827 } 828 }
(...skipping 3224 matching lines...) Expand 10 before | Expand all | Expand 10 after
4052 reusable_preparser_->set_allow_harmony_classes(allow_harmony_classes()); 4053 reusable_preparser_->set_allow_harmony_classes(allow_harmony_classes());
4053 reusable_preparser_->set_allow_harmony_object_literals( 4054 reusable_preparser_->set_allow_harmony_object_literals(
4054 allow_harmony_object_literals()); 4055 allow_harmony_object_literals());
4055 reusable_preparser_->set_allow_harmony_templates(allow_harmony_templates()); 4056 reusable_preparser_->set_allow_harmony_templates(allow_harmony_templates());
4056 reusable_preparser_->set_allow_harmony_sloppy(allow_harmony_sloppy()); 4057 reusable_preparser_->set_allow_harmony_sloppy(allow_harmony_sloppy());
4057 reusable_preparser_->set_allow_harmony_unicode(allow_harmony_unicode()); 4058 reusable_preparser_->set_allow_harmony_unicode(allow_harmony_unicode());
4058 reusable_preparser_->set_allow_harmony_computed_property_names( 4059 reusable_preparser_->set_allow_harmony_computed_property_names(
4059 allow_harmony_computed_property_names()); 4060 allow_harmony_computed_property_names());
4060 reusable_preparser_->set_allow_harmony_rest_params( 4061 reusable_preparser_->set_allow_harmony_rest_params(
4061 allow_harmony_rest_params()); 4062 allow_harmony_rest_params());
4063 reusable_preparser_->set_allow_harmony_spreadcalls(
4064 allow_harmony_spreadcalls());
4062 reusable_preparser_->set_allow_strong_mode(allow_strong_mode()); 4065 reusable_preparser_->set_allow_strong_mode(allow_strong_mode());
4063 } 4066 }
4064 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( 4067 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction(
4065 language_mode(), function_state_->kind(), logger); 4068 language_mode(), function_state_->kind(), logger);
4066 if (pre_parse_timer_ != NULL) { 4069 if (pre_parse_timer_ != NULL) {
4067 pre_parse_timer_->Stop(); 4070 pre_parse_timer_->Stop();
4068 } 4071 }
4069 return result; 4072 return result;
4070 } 4073 }
4071 4074
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
4163 4166
4164 4167
4165 Expression* Parser::ParseV8Intrinsic(bool* ok) { 4168 Expression* Parser::ParseV8Intrinsic(bool* ok) {
4166 // CallRuntime :: 4169 // CallRuntime ::
4167 // '%' Identifier Arguments 4170 // '%' Identifier Arguments
4168 4171
4169 int pos = peek_position(); 4172 int pos = peek_position();
4170 Expect(Token::MOD, CHECK_OK); 4173 Expect(Token::MOD, CHECK_OK);
4171 // Allow "eval" or "arguments" for backward compatibility. 4174 // Allow "eval" or "arguments" for backward compatibility.
4172 const AstRawString* name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); 4175 const AstRawString* name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK);
4173 ZoneList<Expression*>* args = ParseArguments(CHECK_OK); 4176 Scanner::Location spread_pos;
4177 ZoneList<Expression*>* args = ParseArguments(&spread_pos, CHECK_OK);
4178
4179 // TODO(caitp): support intrinsics
4180 DCHECK(!spread_pos.IsValid());
4174 4181
4175 if (extension_ != NULL) { 4182 if (extension_ != NULL) {
4176 // The extension structures are only accessible while parsing the 4183 // The extension structures are only accessible while parsing the
4177 // very first time not when reparsing because of lazy compilation. 4184 // very first time not when reparsing because of lazy compilation.
4178 scope_->DeclarationScope()->ForceEagerCompilation(); 4185 scope_->DeclarationScope()->ForceEagerCompilation();
4179 } 4186 }
4180 4187
4181 const Runtime::Function* function = Runtime::FunctionForName(name->string()); 4188 const Runtime::Function* function = Runtime::FunctionForName(name->string());
4182 4189
4183 // Check for built-in IS_VAR macro. 4190 // Check for built-in IS_VAR macro.
(...skipping 1300 matching lines...) Expand 10 before | Expand all | Expand 10 after
5484 running_hash, data, raw_string->length()); 5491 running_hash, data, raw_string->length());
5485 } else { 5492 } else {
5486 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); 5493 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data());
5487 running_hash = StringHasher::ComputeRunningHash(running_hash, data, 5494 running_hash = StringHasher::ComputeRunningHash(running_hash, data,
5488 raw_string->length()); 5495 raw_string->length());
5489 } 5496 }
5490 } 5497 }
5491 5498
5492 return running_hash; 5499 return running_hash;
5493 } 5500 }
5501
5502
5503 ZoneList<v8::internal::Expression*>* Parser::PrepareSpreadArguments(
5504 ZoneList<v8::internal::Expression*>* list) {
5505 ZoneList<v8::internal::Expression*>* args =
5506 new (zone()) ZoneList<v8::internal::Expression*>(1, zone());
5507 if (list->length() == 1) {
5508 args->Add(
5509 factory()->NewCallRuntime(ast_value_factory()->spread_iterable_string(),
5510 NULL, list, RelocInfo::kNoPosition),
5511 zone());
5512 return args;
5513 } else {
5514 int i = 0;
5515 int n = list->length();
5516 while (i < n) {
5517 if (!list->at(i)->IsSpreadOperation()) {
5518 ZoneList<v8::internal::Expression*>* unspread =
5519 new (zone()) ZoneList<v8::internal::Expression*>(1, zone());
5520
5521 // Push array of unspread parameters
5522 while (i < n && !list->at(i)->IsSpreadOperation()) {
5523 unspread->Add(list->at(i++), zone());
5524 }
5525 int literal_index = function_state_->NextMaterializedLiteralIndex();
5526 args->Add(factory()->NewArrayLiteral(unspread, literal_index,
5527 RelocInfo::kNoPosition),
5528 zone());
5529
5530 if (i == n) break;
5531 }
5532
5533 // Push eagerly spread argument
5534 ZoneList<v8::internal::Expression*>* spread =
5535 new (zone()) ZoneList<v8::internal::Expression*>(1, zone());
5536 spread->Add(list->at(i++), zone());
5537 args->Add(factory()->NewCallRuntime(
5538 ast_value_factory()->spread_iterable_string(), NULL, spread,
5539 RelocInfo::kNoPosition),
5540 zone());
5541 }
5542
5543 list = new (zone()) ZoneList<v8::internal::Expression*>(1, zone());
5544 list->Add(factory()->NewCallRuntime(
5545 ast_value_factory()->spread_arguments_string(), NULL, args,
5546 RelocInfo::kNoPosition),
5547 zone());
5548 return list;
5549 }
5550 UNREACHABLE();
5551 }
5552
5553
5554 Expression* Parser::SpreadCall(Expression* function,
5555 ZoneList<v8::internal::Expression*>* args,
5556 int pos) {
5557 Expression* receiver;
5558 if (function->IsProperty()) {
5559 receiver = function->AsProperty()->obj();
5560 } else {
5561 receiver = factory()->NewUndefinedLiteral(pos);
5562 }
5563
5564 args->InsertAt(0, function, zone());
5565 args->InsertAt(1, receiver, zone());
5566
5567 const Runtime::Function* apply = Runtime::FunctionForId(Runtime::kApplyCall);
5568 return factory()->NewCallRuntime(ast_value_factory()->empty_string(), apply,
5569 args, pos);
5570 }
5571
5572
5573 Expression* Parser::SpreadCallNew(Expression* function,
5574 ZoneList<v8::internal::Expression*>* args,
5575 int pos) {
5576 args->InsertAt(0, function, zone());
5577
5578 const Runtime::Function* apply =
5579 Runtime::FunctionForId(Runtime::kApplyConstruct);
5580 return factory()->NewCallRuntime(ast_value_factory()->empty_string(), apply,
5581 args, pos);
5582 }
5494 } } // namespace v8::internal 5583 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698