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

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: Nits Created 5 years, 8 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 859 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); 870 set_allow_natives(FLAG_allow_natives_syntax || info->is_native());
871 set_allow_harmony_modules(!info->is_native() && FLAG_harmony_modules); 871 set_allow_harmony_modules(!info->is_native() && FLAG_harmony_modules);
872 set_allow_harmony_arrow_functions(FLAG_harmony_arrow_functions); 872 set_allow_harmony_arrow_functions(FLAG_harmony_arrow_functions);
873 set_allow_harmony_classes(FLAG_harmony_classes); 873 set_allow_harmony_classes(FLAG_harmony_classes);
874 set_allow_harmony_object_literals(FLAG_harmony_object_literals); 874 set_allow_harmony_object_literals(FLAG_harmony_object_literals);
875 set_allow_harmony_sloppy(FLAG_harmony_sloppy); 875 set_allow_harmony_sloppy(FLAG_harmony_sloppy);
876 set_allow_harmony_unicode(FLAG_harmony_unicode); 876 set_allow_harmony_unicode(FLAG_harmony_unicode);
877 set_allow_harmony_computed_property_names( 877 set_allow_harmony_computed_property_names(
878 FLAG_harmony_computed_property_names); 878 FLAG_harmony_computed_property_names);
879 set_allow_harmony_rest_params(FLAG_harmony_rest_parameters); 879 set_allow_harmony_rest_params(FLAG_harmony_rest_parameters);
880 set_allow_harmony_spreadcalls(FLAG_harmony_spreadcalls);
880 set_allow_strong_mode(FLAG_strong_mode); 881 set_allow_strong_mode(FLAG_strong_mode);
881 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; 882 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount;
882 ++feature) { 883 ++feature) {
883 use_counts_[feature] = 0; 884 use_counts_[feature] = 0;
884 } 885 }
885 if (info->ast_value_factory() == NULL) { 886 if (info->ast_value_factory() == NULL) {
886 // info takes ownership of AstValueFactory. 887 // info takes ownership of AstValueFactory.
887 info->set_ast_value_factory(new AstValueFactory(zone(), info->hash_seed())); 888 info->set_ast_value_factory(new AstValueFactory(zone(), info->hash_seed()));
888 info->set_ast_value_factory_owned(); 889 info->set_ast_value_factory_owned();
889 ast_value_factory_ = info->ast_value_factory(); 890 ast_value_factory_ = info->ast_value_factory();
(...skipping 3283 matching lines...) Expand 10 before | Expand all | Expand 10 after
4173 allow_harmony_arrow_functions()); 4174 allow_harmony_arrow_functions());
4174 reusable_preparser_->set_allow_harmony_classes(allow_harmony_classes()); 4175 reusable_preparser_->set_allow_harmony_classes(allow_harmony_classes());
4175 reusable_preparser_->set_allow_harmony_object_literals( 4176 reusable_preparser_->set_allow_harmony_object_literals(
4176 allow_harmony_object_literals()); 4177 allow_harmony_object_literals());
4177 reusable_preparser_->set_allow_harmony_sloppy(allow_harmony_sloppy()); 4178 reusable_preparser_->set_allow_harmony_sloppy(allow_harmony_sloppy());
4178 reusable_preparser_->set_allow_harmony_unicode(allow_harmony_unicode()); 4179 reusable_preparser_->set_allow_harmony_unicode(allow_harmony_unicode());
4179 reusable_preparser_->set_allow_harmony_computed_property_names( 4180 reusable_preparser_->set_allow_harmony_computed_property_names(
4180 allow_harmony_computed_property_names()); 4181 allow_harmony_computed_property_names());
4181 reusable_preparser_->set_allow_harmony_rest_params( 4182 reusable_preparser_->set_allow_harmony_rest_params(
4182 allow_harmony_rest_params()); 4183 allow_harmony_rest_params());
4184 reusable_preparser_->set_allow_harmony_spreadcalls(
4185 allow_harmony_spreadcalls());
4183 reusable_preparser_->set_allow_strong_mode(allow_strong_mode()); 4186 reusable_preparser_->set_allow_strong_mode(allow_strong_mode());
4184 } 4187 }
4185 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( 4188 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction(
4186 language_mode(), function_state_->kind(), logger); 4189 language_mode(), function_state_->kind(), logger);
4187 if (pre_parse_timer_ != NULL) { 4190 if (pre_parse_timer_ != NULL) {
4188 pre_parse_timer_->Stop(); 4191 pre_parse_timer_->Stop();
4189 } 4192 }
4190 return result; 4193 return result;
4191 } 4194 }
4192 4195
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
4291 4294
4292 4295
4293 Expression* Parser::ParseV8Intrinsic(bool* ok) { 4296 Expression* Parser::ParseV8Intrinsic(bool* ok) {
4294 // CallRuntime :: 4297 // CallRuntime ::
4295 // '%' Identifier Arguments 4298 // '%' Identifier Arguments
4296 4299
4297 int pos = peek_position(); 4300 int pos = peek_position();
4298 Expect(Token::MOD, CHECK_OK); 4301 Expect(Token::MOD, CHECK_OK);
4299 // Allow "eval" or "arguments" for backward compatibility. 4302 // Allow "eval" or "arguments" for backward compatibility.
4300 const AstRawString* name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); 4303 const AstRawString* name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK);
4301 ZoneList<Expression*>* args = ParseArguments(CHECK_OK); 4304 Scanner::Location spread_pos;
4305 ZoneList<Expression*>* args = ParseArguments(&spread_pos, CHECK_OK);
4306
4307 DCHECK(!spread_pos.IsValid());
4302 4308
4303 if (extension_ != NULL) { 4309 if (extension_ != NULL) {
4304 // The extension structures are only accessible while parsing the 4310 // The extension structures are only accessible while parsing the
4305 // very first time not when reparsing because of lazy compilation. 4311 // very first time not when reparsing because of lazy compilation.
4306 scope_->DeclarationScope()->ForceEagerCompilation(); 4312 scope_->DeclarationScope()->ForceEagerCompilation();
4307 } 4313 }
4308 4314
4309 const Runtime::Function* function = Runtime::FunctionForName(name->string()); 4315 const Runtime::Function* function = Runtime::FunctionForName(name->string());
4310 4316
4311 // Check for built-in IS_VAR macro. 4317 // Check for built-in IS_VAR macro.
(...skipping 1244 matching lines...) Expand 10 before | Expand all | Expand 10 after
5556 running_hash, data, raw_string->length()); 5562 running_hash, data, raw_string->length());
5557 } else { 5563 } else {
5558 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); 5564 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data());
5559 running_hash = StringHasher::ComputeRunningHash(running_hash, data, 5565 running_hash = StringHasher::ComputeRunningHash(running_hash, data,
5560 raw_string->length()); 5566 raw_string->length());
5561 } 5567 }
5562 } 5568 }
5563 5569
5564 return running_hash; 5570 return running_hash;
5565 } 5571 }
5572
5573
5574 ZoneList<v8::internal::Expression*>* Parser::PrepareSpreadArguments(
5575 ZoneList<v8::internal::Expression*>* list) {
5576 ZoneList<v8::internal::Expression*>* args =
5577 new (zone()) ZoneList<v8::internal::Expression*>(1, zone());
5578 if (list->length() == 1) {
5579 // Spread-call with single spread argument produces an InternalArray
5580 // containing the values from the array.
5581 //
5582 // Function is called or constructed with the produced array of arguments
5583 //
5584 // EG: Apply(Func, Spread(spread0))
5585 ZoneList<Expression*>* spread_list =
5586 new (zone()) ZoneList<Expression*>(0, zone());
5587 spread_list->Add(list->at(0)->AsSpread()->expression(), zone());
5588 args->Add(
5589 factory()->NewCallRuntime(ast_value_factory()->spread_iterable_string(),
5590 NULL, spread_list, RelocInfo::kNoPosition),
5591 zone());
5592 return args;
5593 } else {
5594 // Spread-call with multiple arguments produces array literals for each
5595 // sequences of unspread arguments, and converts each spread iterable to
5596 // an Internal array. Finally, all of these produced arrays are flattened
5597 // into a single InternalArray, containing the arguments for the call.
5598 //
5599 // EG: Apply(Func, Flatten([unspread0, unspread1], Spread(spread0),
5600 // Spread(spread1), [unspread2, unspread3]))
5601 int i = 0;
5602 int n = list->length();
5603 while (i < n) {
5604 if (!list->at(i)->IsSpread()) {
5605 ZoneList<v8::internal::Expression*>* unspread =
5606 new (zone()) ZoneList<v8::internal::Expression*>(1, zone());
5607
5608 // Push array of unspread parameters
5609 while (i < n && !list->at(i)->IsSpread()) {
5610 unspread->Add(list->at(i++), zone());
5611 }
5612 int literal_index = function_state_->NextMaterializedLiteralIndex();
5613 args->Add(factory()->NewArrayLiteral(unspread, literal_index,
5614 RelocInfo::kNoPosition),
5615 zone());
5616
5617 if (i == n) break;
5618 }
5619
5620 // Push eagerly spread argument
5621 ZoneList<v8::internal::Expression*>* spread_list =
5622 new (zone()) ZoneList<v8::internal::Expression*>(1, zone());
5623 spread_list->Add(list->at(i++)->AsSpread()->expression(), zone());
5624 args->Add(factory()->NewCallRuntime(
5625 ast_value_factory()->spread_iterable_string(), NULL,
5626 spread_list, RelocInfo::kNoPosition),
5627 zone());
5628 }
5629
5630 list = new (zone()) ZoneList<v8::internal::Expression*>(1, zone());
5631 list->Add(factory()->NewCallRuntime(
5632 ast_value_factory()->spread_arguments_string(), NULL, args,
5633 RelocInfo::kNoPosition),
5634 zone());
5635 return list;
5636 }
5637 UNREACHABLE();
5638 }
5639
5640
5641 Expression* Parser::SpreadCall(Expression* function,
5642 ZoneList<v8::internal::Expression*>* args,
5643 int pos) {
5644 if (function->IsSuperReference()) {
5645 // Super calls
5646 args->InsertAt(0, function, zone());
5647 args->Add(factory()->NewVariableProxy(scope_->new_target_var()), zone());
5648 Expression* result = factory()->NewCallRuntime(
5649 ast_value_factory()->reflect_construct_string(), NULL, args, pos);
5650 args = new (zone()) ZoneList<Expression*>(0, zone());
5651 args->Add(result, zone());
5652 return factory()->NewCallRuntime(
5653 ast_value_factory()->empty_string(),
5654 Runtime::FunctionForId(Runtime::kInlineCallSuperWithSpread), args, pos);
5655 } else {
5656 if (function->IsProperty()) {
5657 // Method calls
5658 Variable* temp =
5659 scope_->NewTemporary(ast_value_factory()->empty_string());
5660 VariableProxy* obj = factory()->NewVariableProxy(temp);
5661 Assignment* assign_obj = factory()->NewAssignment(
5662 Token::ASSIGN, obj, function->AsProperty()->obj(),
5663 RelocInfo::kNoPosition);
5664 function = factory()->NewProperty(
5665 assign_obj, function->AsProperty()->key(), RelocInfo::kNoPosition);
5666 args->InsertAt(0, function, zone());
5667 obj = factory()->NewVariableProxy(temp);
5668 args->InsertAt(1, obj, zone());
5669 } else {
5670 // Non-method calls
5671 args->InsertAt(0, function, zone());
5672 args->InsertAt(1, factory()->NewUndefinedLiteral(RelocInfo::kNoPosition),
5673 zone());
5674 }
5675 return factory()->NewCallRuntime(
5676 ast_value_factory()->reflect_apply_string(), NULL, args, pos);
5677 }
5678 }
5679
5680
5681 Expression* Parser::SpreadCallNew(Expression* function,
5682 ZoneList<v8::internal::Expression*>* args,
5683 int pos) {
5684 args->InsertAt(0, function, zone());
5685
5686 return factory()->NewCallRuntime(
5687 ast_value_factory()->reflect_construct_string(), NULL, args, pos);
5688 }
5566 } } // namespace v8::internal 5689 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698