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

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: Eagerly iterate spread expressions, make parser more complicated, simplify harmony-spread 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 3208 matching lines...) Expand 10 before | Expand all | Expand 10 after
4036 reusable_preparser_->set_allow_harmony_classes(allow_harmony_classes()); 4037 reusable_preparser_->set_allow_harmony_classes(allow_harmony_classes());
4037 reusable_preparser_->set_allow_harmony_object_literals( 4038 reusable_preparser_->set_allow_harmony_object_literals(
4038 allow_harmony_object_literals()); 4039 allow_harmony_object_literals());
4039 reusable_preparser_->set_allow_harmony_templates(allow_harmony_templates()); 4040 reusable_preparser_->set_allow_harmony_templates(allow_harmony_templates());
4040 reusable_preparser_->set_allow_harmony_sloppy(allow_harmony_sloppy()); 4041 reusable_preparser_->set_allow_harmony_sloppy(allow_harmony_sloppy());
4041 reusable_preparser_->set_allow_harmony_unicode(allow_harmony_unicode()); 4042 reusable_preparser_->set_allow_harmony_unicode(allow_harmony_unicode());
4042 reusable_preparser_->set_allow_harmony_computed_property_names( 4043 reusable_preparser_->set_allow_harmony_computed_property_names(
4043 allow_harmony_computed_property_names()); 4044 allow_harmony_computed_property_names());
4044 reusable_preparser_->set_allow_harmony_rest_params( 4045 reusable_preparser_->set_allow_harmony_rest_params(
4045 allow_harmony_rest_params()); 4046 allow_harmony_rest_params());
4047 reusable_preparser_->set_allow_harmony_spreadcalls(
4048 allow_harmony_spreadcalls());
4046 reusable_preparser_->set_allow_strong_mode(allow_strong_mode()); 4049 reusable_preparser_->set_allow_strong_mode(allow_strong_mode());
4047 } 4050 }
4048 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( 4051 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction(
4049 language_mode(), function_state_->kind(), logger); 4052 language_mode(), function_state_->kind(), logger);
4050 if (pre_parse_timer_ != NULL) { 4053 if (pre_parse_timer_ != NULL) {
4051 pre_parse_timer_->Stop(); 4054 pre_parse_timer_->Stop();
4052 } 4055 }
4053 return result; 4056 return result;
4054 } 4057 }
4055 4058
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
4147 4150
4148 4151
4149 Expression* Parser::ParseV8Intrinsic(bool* ok) { 4152 Expression* Parser::ParseV8Intrinsic(bool* ok) {
4150 // CallRuntime :: 4153 // CallRuntime ::
4151 // '%' Identifier Arguments 4154 // '%' Identifier Arguments
4152 4155
4153 int pos = peek_position(); 4156 int pos = peek_position();
4154 Expect(Token::MOD, CHECK_OK); 4157 Expect(Token::MOD, CHECK_OK);
4155 // Allow "eval" or "arguments" for backward compatibility. 4158 // Allow "eval" or "arguments" for backward compatibility.
4156 const AstRawString* name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); 4159 const AstRawString* name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK);
4157 ZoneList<Expression*>* args = ParseArguments(CHECK_OK); 4160 Scanner::Location spread_pos;
4161 ZoneList<Expression*>* args = ParseArguments(&spread_pos, CHECK_OK);
4162
4163 // TODO(caitp): support intrinsics
4164 DCHECK(!spread_pos.IsValid());
4158 4165
4159 if (extension_ != NULL) { 4166 if (extension_ != NULL) {
4160 // The extension structures are only accessible while parsing the 4167 // The extension structures are only accessible while parsing the
4161 // very first time not when reparsing because of lazy compilation. 4168 // very first time not when reparsing because of lazy compilation.
4162 scope_->DeclarationScope()->ForceEagerCompilation(); 4169 scope_->DeclarationScope()->ForceEagerCompilation();
4163 } 4170 }
4164 4171
4165 const Runtime::Function* function = Runtime::FunctionForName(name->string()); 4172 const Runtime::Function* function = Runtime::FunctionForName(name->string());
4166 4173
4167 // Check for built-in IS_VAR macro. 4174 // Check for built-in IS_VAR macro.
(...skipping 1299 matching lines...) Expand 10 before | Expand all | Expand 10 after
5467 running_hash, data, raw_string->length()); 5474 running_hash, data, raw_string->length());
5468 } else { 5475 } else {
5469 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); 5476 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data());
5470 running_hash = StringHasher::ComputeRunningHash(running_hash, data, 5477 running_hash = StringHasher::ComputeRunningHash(running_hash, data,
5471 raw_string->length()); 5478 raw_string->length());
5472 } 5479 }
5473 } 5480 }
5474 5481
5475 return running_hash; 5482 return running_hash;
5476 } 5483 }
5484
5485
5486 ZoneList<v8::internal::Expression*>* Parser::PrepareSpreadArguments(
5487 ZoneList<v8::internal::Expression*>* list) {
5488 ZoneList<v8::internal::Expression*>* args =
5489 new (zone()) ZoneList<v8::internal::Expression*>(1, zone());
5490 if (list->length() == 1) {
5491 args->Add(
5492 factory()->NewCallRuntime(ast_value_factory()->spread_iterable_string(),
5493 NULL, list, RelocInfo::kNoPosition),
5494 zone());
5495 return args;
5496 } else {
5497 int i = 0;
arv (Not doing code reviews) 2015/02/23 17:55:56 This could use a comment explaining what it desuga
rossberg 2015/02/25 14:28:18 +1
caitp (gmail) 2015/02/25 14:49:08 Acknowledged.
5498 int n = list->length();
5499 while (i < n) {
5500 ZoneList<v8::internal::Expression*>* unspread =
5501 new (zone()) ZoneList<v8::internal::Expression*>(1, zone());
5502
5503 // Push array of unspread parameters
5504 while (i < n && !list->at(i)->IsSpreadOperation()) {
5505 unspread->Add(list->at(i++), zone());
5506 }
5507 int literal_index = function_state_->NextMaterializedLiteralIndex();
5508 args->Add(factory()->NewArrayLiteral(unspread, literal_index,
arv (Not doing code reviews) 2015/02/23 17:55:56 Will this be observable if someone overrides Array
caitp (gmail) 2015/02/25 14:49:08 The unspread array literals aren't iterated via it
5509 RelocInfo::kNoPosition),
5510 zone());
5511
5512 if (i == n) break;
5513
5514 // Push eagerly spread argument
5515 ZoneList<v8::internal::Expression*>* spread =
5516 new (zone()) ZoneList<v8::internal::Expression*>(1, zone());
5517 spread->Add(list->at(i++), zone());
5518 args->Add(factory()->NewCallRuntime(
5519 ast_value_factory()->spread_iterable_string(), NULL, spread,
5520 RelocInfo::kNoPosition),
5521 zone());
5522 }
5523
5524 list = new (zone()) ZoneList<v8::internal::Expression*>(1, zone());
5525 list->Add(factory()->NewCallRuntime(
5526 ast_value_factory()->spread_arguments_string(), NULL, args,
5527 RelocInfo::kNoPosition),
5528 zone());
5529 return list;
5530 }
5531 UNREACHABLE();
5532 }
5533
5534
5535 Expression* Parser::SpreadCall(Expression* function,
5536 ZoneList<v8::internal::Expression*>* args,
5537 int pos) {
5538 Expression* receiver;
5539 if (function->IsProperty()) {
5540 receiver = function->AsProperty()->obj();
5541 } else {
5542 receiver = factory()->NewUndefinedLiteral(pos);
5543 }
5544
5545 args->InsertAt(0, function, zone());
5546 args->InsertAt(1, receiver, zone());
5547
5548 const Runtime::Function* apply = Runtime::FunctionForId(Runtime::kApply);
5549 return factory()->NewCallRuntime(ast_value_factory()->empty_string(), apply,
5550 args, pos);
5551 }
5552
5553
5554 Expression* Parser::SpreadCallNew(Expression* function,
5555 ZoneList<v8::internal::Expression*>* args,
5556 int pos) {
5557 args->InsertAt(0, function, zone());
5558
5559 const Runtime::Function* apply =
5560 Runtime::FunctionForId(Runtime::kApplyConstruct);
5561 return factory()->NewCallRuntime(ast_value_factory()->empty_string(), apply,
5562 args, pos);
5563 }
5477 } } // namespace v8::internal 5564 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698