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

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: Remove --harmony-spread flag 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 860 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_numeric_literals(FLAG_harmony_numeric_literals); 873 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals);
874 set_allow_harmony_classes(FLAG_harmony_classes); 874 set_allow_harmony_classes(FLAG_harmony_classes);
875 set_allow_harmony_object_literals(FLAG_harmony_object_literals); 875 set_allow_harmony_object_literals(FLAG_harmony_object_literals);
876 set_allow_harmony_sloppy(FLAG_harmony_sloppy); 876 set_allow_harmony_sloppy(FLAG_harmony_sloppy);
877 set_allow_harmony_unicode(FLAG_harmony_unicode); 877 set_allow_harmony_unicode(FLAG_harmony_unicode);
878 set_allow_harmony_computed_property_names( 878 set_allow_harmony_computed_property_names(
879 FLAG_harmony_computed_property_names); 879 FLAG_harmony_computed_property_names);
880 set_allow_harmony_rest_params(FLAG_harmony_rest_parameters); 880 set_allow_harmony_rest_params(FLAG_harmony_rest_parameters);
881 set_allow_harmony_spreadcalls(FLAG_harmony_spreadcalls);
881 set_allow_strong_mode(FLAG_strong_mode); 882 set_allow_strong_mode(FLAG_strong_mode);
882 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; 883 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount;
883 ++feature) { 884 ++feature) {
884 use_counts_[feature] = 0; 885 use_counts_[feature] = 0;
885 } 886 }
886 if (info->ast_value_factory() == NULL) { 887 if (info->ast_value_factory() == NULL) {
887 // info takes ownership of AstValueFactory. 888 // info takes ownership of AstValueFactory.
888 info->set_ast_value_factory(new AstValueFactory(zone(), info->hash_seed())); 889 info->set_ast_value_factory(new AstValueFactory(zone(), info->hash_seed()));
889 info->set_ast_value_factory_owned(); 890 info->set_ast_value_factory_owned();
890 ast_value_factory_ = info->ast_value_factory(); 891 ast_value_factory_ = info->ast_value_factory();
(...skipping 3278 matching lines...) Expand 10 before | Expand all | Expand 10 after
4169 allow_harmony_numeric_literals()); 4170 allow_harmony_numeric_literals());
4170 reusable_preparser_->set_allow_harmony_classes(allow_harmony_classes()); 4171 reusable_preparser_->set_allow_harmony_classes(allow_harmony_classes());
4171 reusable_preparser_->set_allow_harmony_object_literals( 4172 reusable_preparser_->set_allow_harmony_object_literals(
4172 allow_harmony_object_literals()); 4173 allow_harmony_object_literals());
4173 reusable_preparser_->set_allow_harmony_sloppy(allow_harmony_sloppy()); 4174 reusable_preparser_->set_allow_harmony_sloppy(allow_harmony_sloppy());
4174 reusable_preparser_->set_allow_harmony_unicode(allow_harmony_unicode()); 4175 reusable_preparser_->set_allow_harmony_unicode(allow_harmony_unicode());
4175 reusable_preparser_->set_allow_harmony_computed_property_names( 4176 reusable_preparser_->set_allow_harmony_computed_property_names(
4176 allow_harmony_computed_property_names()); 4177 allow_harmony_computed_property_names());
4177 reusable_preparser_->set_allow_harmony_rest_params( 4178 reusable_preparser_->set_allow_harmony_rest_params(
4178 allow_harmony_rest_params()); 4179 allow_harmony_rest_params());
4180 reusable_preparser_->set_allow_harmony_spreadcalls(
4181 allow_harmony_spreadcalls());
4179 reusable_preparser_->set_allow_strong_mode(allow_strong_mode()); 4182 reusable_preparser_->set_allow_strong_mode(allow_strong_mode());
4180 } 4183 }
4181 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( 4184 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction(
4182 language_mode(), function_state_->kind(), logger); 4185 language_mode(), function_state_->kind(), logger);
4183 if (pre_parse_timer_ != NULL) { 4186 if (pre_parse_timer_ != NULL) {
4184 pre_parse_timer_->Stop(); 4187 pre_parse_timer_->Stop();
4185 } 4188 }
4186 return result; 4189 return result;
4187 } 4190 }
4188 4191
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
4287 4290
4288 4291
4289 Expression* Parser::ParseV8Intrinsic(bool* ok) { 4292 Expression* Parser::ParseV8Intrinsic(bool* ok) {
4290 // CallRuntime :: 4293 // CallRuntime ::
4291 // '%' Identifier Arguments 4294 // '%' Identifier Arguments
4292 4295
4293 int pos = peek_position(); 4296 int pos = peek_position();
4294 Expect(Token::MOD, CHECK_OK); 4297 Expect(Token::MOD, CHECK_OK);
4295 // Allow "eval" or "arguments" for backward compatibility. 4298 // Allow "eval" or "arguments" for backward compatibility.
4296 const AstRawString* name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); 4299 const AstRawString* name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK);
4297 ZoneList<Expression*>* args = ParseArguments(CHECK_OK); 4300 Scanner::Location spread_pos;
4301 ZoneList<Expression*>* args = ParseArguments(&spread_pos, CHECK_OK);
4302
4303 // TODO(caitp): support intrinsics
4304 DCHECK(!spread_pos.IsValid());
4298 4305
4299 if (extension_ != NULL) { 4306 if (extension_ != NULL) {
4300 // The extension structures are only accessible while parsing the 4307 // The extension structures are only accessible while parsing the
4301 // very first time not when reparsing because of lazy compilation. 4308 // very first time not when reparsing because of lazy compilation.
4302 scope_->DeclarationScope()->ForceEagerCompilation(); 4309 scope_->DeclarationScope()->ForceEagerCompilation();
4303 } 4310 }
4304 4311
4305 const Runtime::Function* function = Runtime::FunctionForName(name->string()); 4312 const Runtime::Function* function = Runtime::FunctionForName(name->string());
4306 4313
4307 // Check for built-in IS_VAR macro. 4314 // Check for built-in IS_VAR macro.
(...skipping 1247 matching lines...) Expand 10 before | Expand all | Expand 10 after
5555 running_hash, data, raw_string->length()); 5562 running_hash, data, raw_string->length());
5556 } else { 5563 } else {
5557 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); 5564 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data());
5558 running_hash = StringHasher::ComputeRunningHash(running_hash, data, 5565 running_hash = StringHasher::ComputeRunningHash(running_hash, data,
5559 raw_string->length()); 5566 raw_string->length());
5560 } 5567 }
5561 } 5568 }
5562 5569
5563 return running_hash; 5570 return running_hash;
5564 } 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 args->Add(
5586 factory()->NewCallRuntime(ast_value_factory()->spread_iterable_string(),
5587 NULL, list, RelocInfo::kNoPosition),
5588 zone());
5589 return args;
5590 } else {
5591 // Spread-call with multiple arguments produces array literals for each
5592 // sequences of unspread arguments, and converts each spread iterable to
5593 // an Internal array. Finally, all of these produced arrays are flattened
5594 // into a single InternalArray, containing the arguments for the call.
5595 //
5596 // EG: Apply(Func, Flatten([unspread0, unspread1], Spread(spread0),
5597 // Spread(spread1), [unspread2, unspread3]))
5598 int i = 0;
5599 int n = list->length();
5600 while (i < n) {
5601 if (!list->at(i)->IsSpreadOperation()) {
5602 ZoneList<v8::internal::Expression*>* unspread =
5603 new (zone()) ZoneList<v8::internal::Expression*>(1, zone());
5604
5605 // Push array of unspread parameters
5606 while (i < n && !list->at(i)->IsSpreadOperation()) {
5607 unspread->Add(list->at(i++), zone());
5608 }
5609 int literal_index = function_state_->NextMaterializedLiteralIndex();
5610 args->Add(factory()->NewArrayLiteral(unspread, literal_index,
5611 RelocInfo::kNoPosition),
5612 zone());
5613
5614 if (i == n) break;
5615 }
5616
5617 // Push eagerly spread argument
5618 ZoneList<v8::internal::Expression*>* spread =
5619 new (zone()) ZoneList<v8::internal::Expression*>(1, zone());
5620 spread->Add(list->at(i++), zone());
5621 args->Add(factory()->NewCallRuntime(
5622 ast_value_factory()->spread_iterable_string(), NULL, spread,
5623 RelocInfo::kNoPosition),
5624 zone());
5625 }
5626
5627 list = new (zone()) ZoneList<v8::internal::Expression*>(1, zone());
5628 list->Add(factory()->NewCallRuntime(
5629 ast_value_factory()->spread_arguments_string(), NULL, args,
5630 RelocInfo::kNoPosition),
5631 zone());
5632 return list;
5633 }
5634 UNREACHABLE();
5635 }
5636
5637
5638 Expression* Parser::SpreadCall(Expression* function,
5639 ZoneList<v8::internal::Expression*>* args,
5640 int pos) {
5641 Expression* receiver;
5642 bool is_super = function->IsSuperReference();
5643
5644 const AstRawString* fn;
5645 args->InsertAt(0, function, zone());
5646 if (is_super) {
5647 fn = ast_value_factory()->reflect_construct_string();
5648 args->Add(factory()->NewVariableProxy(scope_->new_target_var()), zone());
5649 } else {
5650 fn = ast_value_factory()->reflect_apply_string();
5651 if (function->IsProperty()) {
5652 receiver = function->AsProperty()->obj();
5653 } else {
5654 receiver = factory()->NewUndefinedLiteral(pos);
5655 }
5656 args->InsertAt(1, receiver, zone());
5657 }
5658
5659 Expression* result = factory()->NewCallRuntime(fn, NULL, args, pos);
5660 if (is_super) {
5661 result->AsCallRuntime()->SetIsSuperCall();
5662 }
5663 return result;
5664 }
5665
5666
5667 Expression* Parser::SpreadCallNew(Expression* function,
5668 ZoneList<v8::internal::Expression*>* args,
5669 int pos) {
5670 args->InsertAt(0, function, zone());
5671
5672 return factory()->NewCallRuntime(
5673 ast_value_factory()->reflect_construct_string(), NULL, args, pos);
5674 }
5565 } } // namespace v8::internal 5675 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698