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

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

Powered by Google App Engine
This is Rietveld 408576698