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

Unified Diff: src/parser.cc

Issue 938443002: [es6] implement spread calls (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add DCHECK() to prevent intrinsics from being called with spread operator Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index 08941f501f333511f612603e597e627327fc9373..f1633b6dff7db5518ed1ef294bd9fde9b69586a4 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) {
@@ -4043,6 +4044,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(
@@ -4154,7 +4157,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
@@ -5474,4 +5481,49 @@ uint32_t Parser::ComputeTemplateLiteralHash(const TemplateLiteral* lit) {
return running_hash;
}
+
+
+ZoneList<v8::internal::Expression*>* Parser::PrepareSpreadCallArguments(
+ Expression* function, ZoneList<v8::internal::Expression*>* list) {
+ int length = list->length() + 3;
+ Expression* thisArg;
+
+ if (function->IsProperty()) {
+ thisArg = function->AsProperty()->obj();
+ } else {
+ thisArg = factory()->NewUndefinedLiteral(RelocInfo::kNoPosition);
+ }
+ list->InsertAt(0, function, zone());
+ list->InsertAt(1, thisArg, zone());
+ list->InsertAt(2, factory()->NewSmiLiteral(length, RelocInfo::kNoPosition),
+ zone());
+
+ for (int i = 3; i < length; ++i) {
+ Expression* arg = list->at(i);
+ if (arg->IsSpreadOperation()) {
+ list->Add(factory()->NewSmiLiteral(i, RelocInfo::kNoPosition), zone());
+ }
+ }
+
+ return list;
+}
+
+
+ZoneList<v8::internal::Expression*>* Parser::PrepareSpreadCallNewArguments(
+ Expression* function, ZoneList<v8::internal::Expression*>* list) {
+ int length = list->length() + 2;
+
+ list->InsertAt(0, function, zone());
+ list->InsertAt(1, factory()->NewSmiLiteral(length, RelocInfo::kNoPosition),
+ zone());
+
+ for (int i = 2; i < length; ++i) {
+ Expression* arg = list->at(i);
+ if (arg->IsSpreadOperation()) {
+ list->Add(factory()->NewSmiLiteral(i, RelocInfo::kNoPosition), zone());
+ }
+ }
+
+ return list;
+}
} } // namespace v8::internal
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | test/mjsunit/harmony/spread-call.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698