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

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: rebase + clang-format 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 3334 matching lines...) Expand 10 before | Expand all | Expand 10 after
4224 allow_harmony_arrow_functions()); 4225 allow_harmony_arrow_functions());
4225 reusable_preparser_->set_allow_harmony_classes(allow_harmony_classes()); 4226 reusable_preparser_->set_allow_harmony_classes(allow_harmony_classes());
4226 reusable_preparser_->set_allow_harmony_object_literals( 4227 reusable_preparser_->set_allow_harmony_object_literals(
4227 allow_harmony_object_literals()); 4228 allow_harmony_object_literals());
4228 reusable_preparser_->set_allow_harmony_sloppy(allow_harmony_sloppy()); 4229 reusable_preparser_->set_allow_harmony_sloppy(allow_harmony_sloppy());
4229 reusable_preparser_->set_allow_harmony_unicode(allow_harmony_unicode()); 4230 reusable_preparser_->set_allow_harmony_unicode(allow_harmony_unicode());
4230 reusable_preparser_->set_allow_harmony_computed_property_names( 4231 reusable_preparser_->set_allow_harmony_computed_property_names(
4231 allow_harmony_computed_property_names()); 4232 allow_harmony_computed_property_names());
4232 reusable_preparser_->set_allow_harmony_rest_params( 4233 reusable_preparser_->set_allow_harmony_rest_params(
4233 allow_harmony_rest_params()); 4234 allow_harmony_rest_params());
4235 reusable_preparser_->set_allow_harmony_spreadcalls(
4236 allow_harmony_spreadcalls());
4234 reusable_preparser_->set_allow_strong_mode(allow_strong_mode()); 4237 reusable_preparser_->set_allow_strong_mode(allow_strong_mode());
4235 } 4238 }
4236 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( 4239 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction(
4237 language_mode(), function_state_->kind(), logger); 4240 language_mode(), function_state_->kind(), logger);
4238 if (pre_parse_timer_ != NULL) { 4241 if (pre_parse_timer_ != NULL) {
4239 pre_parse_timer_->Stop(); 4242 pre_parse_timer_->Stop();
4240 } 4243 }
4241 return result; 4244 return result;
4242 } 4245 }
4243 4246
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
4342 4345
4343 4346
4344 Expression* Parser::ParseV8Intrinsic(bool* ok) { 4347 Expression* Parser::ParseV8Intrinsic(bool* ok) {
4345 // CallRuntime :: 4348 // CallRuntime ::
4346 // '%' Identifier Arguments 4349 // '%' Identifier Arguments
4347 4350
4348 int pos = peek_position(); 4351 int pos = peek_position();
4349 Expect(Token::MOD, CHECK_OK); 4352 Expect(Token::MOD, CHECK_OK);
4350 // Allow "eval" or "arguments" for backward compatibility. 4353 // Allow "eval" or "arguments" for backward compatibility.
4351 const AstRawString* name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); 4354 const AstRawString* name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK);
4352 ZoneList<Expression*>* args = ParseArguments(CHECK_OK); 4355 Scanner::Location spread_pos;
4356 ZoneList<Expression*>* args = ParseArguments(&spread_pos, CHECK_OK);
4357
4358 DCHECK(!spread_pos.IsValid());
4353 4359
4354 if (extension_ != NULL) { 4360 if (extension_ != NULL) {
4355 // The extension structures are only accessible while parsing the 4361 // The extension structures are only accessible while parsing the
4356 // very first time not when reparsing because of lazy compilation. 4362 // very first time not when reparsing because of lazy compilation.
4357 scope_->DeclarationScope()->ForceEagerCompilation(); 4363 scope_->DeclarationScope()->ForceEagerCompilation();
4358 } 4364 }
4359 4365
4360 const Runtime::Function* function = Runtime::FunctionForName(name->string()); 4366 const Runtime::Function* function = Runtime::FunctionForName(name->string());
4361 4367
4362 // Check for built-in IS_VAR macro. 4368 // Check for built-in IS_VAR macro.
(...skipping 1244 matching lines...) Expand 10 before | Expand all | Expand 10 after
5607 running_hash, data, raw_string->length()); 5613 running_hash, data, raw_string->length());
5608 } else { 5614 } else {
5609 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); 5615 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data());
5610 running_hash = StringHasher::ComputeRunningHash(running_hash, data, 5616 running_hash = StringHasher::ComputeRunningHash(running_hash, data,
5611 raw_string->length()); 5617 raw_string->length());
5612 } 5618 }
5613 } 5619 }
5614 5620
5615 return running_hash; 5621 return running_hash;
5616 } 5622 }
5623
5624
5625 ZoneList<v8::internal::Expression*>* Parser::PrepareSpreadArguments(
5626 ZoneList<v8::internal::Expression*>* list) {
5627 ZoneList<v8::internal::Expression*>* args =
5628 new (zone()) ZoneList<v8::internal::Expression*>(1, zone());
5629 if (list->length() == 1) {
5630 // Spread-call with single spread argument produces an InternalArray
5631 // containing the values from the array.
5632 //
5633 // Function is called or constructed with the produced array of arguments
5634 //
5635 // EG: Apply(Func, Spread(spread0))
5636 ZoneList<Expression*>* spread_list =
5637 new (zone()) ZoneList<Expression*>(0, zone());
5638 spread_list->Add(list->at(0)->AsSpread()->expression(), zone());
5639 args->Add(
5640 factory()->NewCallRuntime(ast_value_factory()->spread_iterable_string(),
5641 NULL, spread_list, RelocInfo::kNoPosition),
5642 zone());
5643 return args;
5644 } else {
5645 // Spread-call with multiple arguments produces array literals for each
5646 // sequences of unspread arguments, and converts each spread iterable to
5647 // an Internal array. Finally, all of these produced arrays are flattened
5648 // into a single InternalArray, containing the arguments for the call.
5649 //
5650 // EG: Apply(Func, Flatten([unspread0, unspread1], Spread(spread0),
5651 // Spread(spread1), [unspread2, unspread3]))
5652 int i = 0;
5653 int n = list->length();
5654 while (i < n) {
5655 if (!list->at(i)->IsSpread()) {
5656 ZoneList<v8::internal::Expression*>* unspread =
5657 new (zone()) ZoneList<v8::internal::Expression*>(1, zone());
5658
5659 // Push array of unspread parameters
5660 while (i < n && !list->at(i)->IsSpread()) {
5661 unspread->Add(list->at(i++), zone());
5662 }
5663 int literal_index = function_state_->NextMaterializedLiteralIndex();
5664 args->Add(factory()->NewArrayLiteral(unspread, literal_index,
5665 RelocInfo::kNoPosition),
5666 zone());
5667
5668 if (i == n) break;
5669 }
5670
5671 // Push eagerly spread argument
5672 ZoneList<v8::internal::Expression*>* spread_list =
5673 new (zone()) ZoneList<v8::internal::Expression*>(1, zone());
5674 spread_list->Add(list->at(i++)->AsSpread()->expression(), zone());
5675 args->Add(factory()->NewCallRuntime(
5676 ast_value_factory()->spread_iterable_string(), NULL,
5677 spread_list, RelocInfo::kNoPosition),
5678 zone());
5679 }
5680
5681 list = new (zone()) ZoneList<v8::internal::Expression*>(1, zone());
5682 list->Add(factory()->NewCallRuntime(
5683 ast_value_factory()->spread_arguments_string(), NULL, args,
5684 RelocInfo::kNoPosition),
5685 zone());
5686 return list;
5687 }
5688 UNREACHABLE();
5689 }
5690
5691
5692 Expression* Parser::SpreadCall(Expression* function,
5693 ZoneList<v8::internal::Expression*>* args,
5694 int pos) {
5695 if (function->IsSuperReference()) {
5696 // Super calls
5697 args->InsertAt(0, function, zone());
5698 args->Add(factory()->NewVariableProxy(scope_->new_target_var()), zone());
5699 Expression* result = factory()->NewCallRuntime(
5700 ast_value_factory()->reflect_construct_string(), NULL, args, pos);
5701 args = new (zone()) ZoneList<Expression*>(0, zone());
5702 args->Add(result, zone());
5703 return factory()->NewCallRuntime(
5704 ast_value_factory()->empty_string(),
5705 Runtime::FunctionForId(Runtime::kInlineCallSuperWithSpread), args, pos);
5706 } else {
5707 if (function->IsProperty()) {
5708 // Method calls
5709 Variable* temp =
5710 scope_->NewTemporary(ast_value_factory()->empty_string());
5711 VariableProxy* obj = factory()->NewVariableProxy(temp);
5712 Assignment* assign_obj = factory()->NewAssignment(
5713 Token::ASSIGN, obj, function->AsProperty()->obj(),
5714 RelocInfo::kNoPosition);
5715 function = factory()->NewProperty(
5716 assign_obj, function->AsProperty()->key(), RelocInfo::kNoPosition);
5717 args->InsertAt(0, function, zone());
5718 obj = factory()->NewVariableProxy(temp);
5719 args->InsertAt(1, obj, zone());
5720 } else {
5721 // Non-method calls
5722 args->InsertAt(0, function, zone());
5723 args->InsertAt(1, factory()->NewUndefinedLiteral(RelocInfo::kNoPosition),
5724 zone());
5725 }
5726 return factory()->NewCallRuntime(
5727 ast_value_factory()->reflect_apply_string(), NULL, args, pos);
5728 }
5729 }
5730
5731
5732 Expression* Parser::SpreadCallNew(Expression* function,
5733 ZoneList<v8::internal::Expression*>* args,
5734 int pos) {
5735 args->InsertAt(0, function, zone());
5736
5737 return factory()->NewCallRuntime(
5738 ast_value_factory()->reflect_construct_string(), NULL, args, pos);
5739 }
5617 } } // namespace v8::internal 5740 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | test/js-perf-test/JSTests.json » ('J')

Powered by Google App Engine
This is Rietveld 408576698