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

Unified Diff: src/preparser.h

Issue 919703003: WIP: Implement ES6 Spread-calls (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: AssignmentExpressions are not spreadable, add cctests for parsing 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/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index 4b526f5f1f3c6f039ae730c70b07eccfa8a20444..a0931ef7aa3ddc752c78d60e03ed77ab931156bb 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -578,6 +578,13 @@ class ParserBase : public Traits {
ExpressionT expression,
Scanner::Location location, const char* message, bool* ok);
+ ExpressionT MaybeSpread(ExpressionT expression, bool is_spread, int pos) {
+ if (is_spread) {
+ return factory()->NewSpreadOperation(scope_, expression, pos);
+ }
+ return expression;
+ }
+
// Used to validate property names in object literals and class literals
enum PropertyKind {
kAccessorProperty,
@@ -762,6 +769,11 @@ class PreParserExpression {
return PreParserExpression(TypeField::encode(kExpression));
}
+ static PreParserExpression Spread(PreParserExpression expression) {
+ DCHECK(!expression.IsSpreadExpression() || expression.is_parenthesized());
+ return PreParserExpression(TypeField::encode(kSpreadExpression));
+ }
+
static PreParserExpression FromIdentifier(PreParserIdentifier id) {
return PreParserExpression(TypeField::encode(kIdentifierExpression) |
IdentifierTypeField::encode(id.type_));
@@ -895,6 +907,10 @@ class PreParserExpression {
ExpressionTypeField::decode(code_) == kNoTemplateTagExpression;
}
+ bool IsSpreadExpression() const {
+ return TypeField::decode(code_) == kSpreadExpression;
+ }
+
PreParserExpression AsFunctionLiteral() { return *this; }
bool IsBinaryOperation() const {
@@ -927,7 +943,8 @@ class PreParserExpression {
kExpression,
kIdentifierExpression,
kStringLiteralExpression,
- kBinaryOperationExpression
+ kBinaryOperationExpression,
+ kSpreadExpression
};
enum Parenthesization {
@@ -955,7 +972,7 @@ class PreParserExpression {
}
// The first four bits are for the Type and Parenthesization.
- typedef BitField<Type, 0, 2> TypeField;
+ typedef BitField<Type, 0, 3> TypeField;
typedef BitField<Parenthesization, TypeField::kNext, 2> ParenthesizationField;
// The rest of the bits are interpreted depending on the value
@@ -1172,6 +1189,11 @@ class PreParserFactory {
return PreParserExpression::Default();
}
+ PreParserExpression NewSpreadOperation(
+ Scope* scope, PreParserExpression expression, int pos) {
+ return PreParserExpression::Spread(expression);
+ }
+
// Return the object itself as AstVisitor and implement the needed
// dummy method right in this class.
PreParserFactory* visitor() { return this; }
@@ -2276,9 +2298,15 @@ typename Traits::Type::ExpressionList ParserBase<Traits>::ParseArguments(
Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullExpressionList));
bool done = (peek() == Token::RPAREN);
while (!done) {
+ bool is_spread = peek() == Token::ELLIPSIS;
arv (Not doing code reviews) 2015/02/12 21:41:34 needs feature flag
+ int spread_pos = -1;
+ if (is_spread) {
+ spread_pos = peek_position();
+ Consume(Token::ELLIPSIS);
+ }
ExpressionT argument = this->ParseAssignmentExpression(
true, CHECK_OK_CUSTOM(NullExpressionList));
- result->Add(argument, zone_);
+ result->Add(MaybeSpread(argument, is_spread, spread_pos), zone_);
if (result->length() > Code::kMaxArguments) {
ReportMessage("too_many_arguments");
*ok = false;

Powered by Google App Engine
This is Rietveld 408576698