| Index: src/parser.cc
|
| diff --git a/src/parser.cc b/src/parser.cc
|
| index b1d427e2529f4ec23a4ac702094ba4f874657443..ed57c9ef4f19699590c6fcab7b4fdf2bfd45ad14 100644
|
| --- a/src/parser.cc
|
| +++ b/src/parser.cc
|
| @@ -815,6 +815,7 @@ Parser::Parser(CompilationInfo* info, uintptr_t stack_limit, uint32_t hash_seed,
|
| set_allow_harmony_computed_property_names(
|
| FLAG_harmony_computed_property_names);
|
| set_allow_harmony_rest_params(FLAG_harmony_rest_parameters);
|
| + set_allow_harmony_spreadcalls(FLAG_harmony_spreadcalls);
|
| set_allow_strong_mode(FLAG_strong_mode);
|
| for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount;
|
| ++feature) {
|
| @@ -4059,6 +4060,8 @@ PreParser::PreParseResult Parser::ParseLazyFunctionBodyWithPreParser(
|
| allow_harmony_computed_property_names());
|
| reusable_preparser_->set_allow_harmony_rest_params(
|
| allow_harmony_rest_params());
|
| + reusable_preparser_->set_allow_harmony_spreadcalls(
|
| + allow_harmony_spreadcalls());
|
| reusable_preparser_->set_allow_strong_mode(allow_strong_mode());
|
| }
|
| PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction(
|
| @@ -4170,7 +4173,11 @@ Expression* Parser::ParseV8Intrinsic(bool* ok) {
|
| Expect(Token::MOD, CHECK_OK);
|
| // Allow "eval" or "arguments" for backward compatibility.
|
| const AstRawString* name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK);
|
| - ZoneList<Expression*>* args = ParseArguments(CHECK_OK);
|
| + Scanner::Location spread_pos;
|
| + ZoneList<Expression*>* args = ParseArguments(&spread_pos, CHECK_OK);
|
| +
|
| + // TODO(caitp): support intrinsics
|
| + DCHECK(!spread_pos.IsValid());
|
|
|
| if (extension_ != NULL) {
|
| // The extension structures are only accessible while parsing the
|
| @@ -5491,4 +5498,86 @@ uint32_t Parser::ComputeTemplateLiteralHash(const TemplateLiteral* lit) {
|
|
|
| return running_hash;
|
| }
|
| +
|
| +
|
| +ZoneList<v8::internal::Expression*>* Parser::PrepareSpreadArguments(
|
| + ZoneList<v8::internal::Expression*>* list) {
|
| + ZoneList<v8::internal::Expression*>* args =
|
| + new (zone()) ZoneList<v8::internal::Expression*>(1, zone());
|
| + if (list->length() == 1) {
|
| + args->Add(
|
| + factory()->NewCallRuntime(ast_value_factory()->spread_iterable_string(),
|
| + NULL, list, RelocInfo::kNoPosition),
|
| + zone());
|
| + return args;
|
| + } else {
|
| + int i = 0;
|
| + int n = list->length();
|
| + while (i < n) {
|
| + if (!list->at(i)->IsSpreadOperation()) {
|
| + ZoneList<v8::internal::Expression*>* unspread =
|
| + new (zone()) ZoneList<v8::internal::Expression*>(1, zone());
|
| +
|
| + // Push array of unspread parameters
|
| + while (i < n && !list->at(i)->IsSpreadOperation()) {
|
| + unspread->Add(list->at(i++), zone());
|
| + }
|
| + int literal_index = function_state_->NextMaterializedLiteralIndex();
|
| + args->Add(factory()->NewArrayLiteral(unspread, literal_index,
|
| + RelocInfo::kNoPosition),
|
| + zone());
|
| +
|
| + if (i == n) break;
|
| + }
|
| +
|
| + // Push eagerly spread argument
|
| + ZoneList<v8::internal::Expression*>* spread =
|
| + new (zone()) ZoneList<v8::internal::Expression*>(1, zone());
|
| + spread->Add(list->at(i++), zone());
|
| + args->Add(factory()->NewCallRuntime(
|
| + ast_value_factory()->spread_iterable_string(), NULL, spread,
|
| + RelocInfo::kNoPosition),
|
| + zone());
|
| + }
|
| +
|
| + list = new (zone()) ZoneList<v8::internal::Expression*>(1, zone());
|
| + list->Add(factory()->NewCallRuntime(
|
| + ast_value_factory()->spread_arguments_string(), NULL, args,
|
| + RelocInfo::kNoPosition),
|
| + zone());
|
| + return list;
|
| + }
|
| + UNREACHABLE();
|
| +}
|
| +
|
| +
|
| +Expression* Parser::SpreadCall(Expression* function,
|
| + ZoneList<v8::internal::Expression*>* args,
|
| + int pos) {
|
| + Expression* receiver;
|
| + if (function->IsProperty()) {
|
| + receiver = function->AsProperty()->obj();
|
| + } else {
|
| + receiver = factory()->NewUndefinedLiteral(pos);
|
| + }
|
| +
|
| + args->InsertAt(0, function, zone());
|
| + args->InsertAt(1, receiver, zone());
|
| +
|
| + const Runtime::Function* apply = Runtime::FunctionForId(Runtime::kApplyCall);
|
| + return factory()->NewCallRuntime(ast_value_factory()->empty_string(), apply,
|
| + args, pos);
|
| +}
|
| +
|
| +
|
| +Expression* Parser::SpreadCallNew(Expression* function,
|
| + ZoneList<v8::internal::Expression*>* args,
|
| + int pos) {
|
| + args->InsertAt(0, function, zone());
|
| +
|
| + const Runtime::Function* apply =
|
| + Runtime::FunctionForId(Runtime::kApplyConstruct);
|
| + return factory()->NewCallRuntime(ast_value_factory()->empty_string(), apply,
|
| + args, pos);
|
| +}
|
| } } // namespace v8::internal
|
|
|