summaryrefslogtreecommitdiffstats
path: root/js/src/frontend/Parser.cpp
diff options
context:
space:
mode:
authorGaming4JC <g4jc@hyperbola.info>2019-07-14 16:37:57 -0400
committerGaming4JC <g4jc@hyperbola.info>2019-07-18 22:38:47 -0400
commit091d00f1bd22f821d3926c46dd1d6cf7fbc746f4 (patch)
treec68c6e96a4104ed0a78807c79f3601cd6f3eee4e /js/src/frontend/Parser.cpp
parent638a904d0dbe4bcc5a625ea472c7e65ac75dbc06 (diff)
downloadUXP-091d00f1bd22f821d3926c46dd1d6cf7fbc746f4.tar
UXP-091d00f1bd22f821d3926c46dd1d6cf7fbc746f4.tar.gz
UXP-091d00f1bd22f821d3926c46dd1d6cf7fbc746f4.tar.lz
UXP-091d00f1bd22f821d3926c46dd1d6cf7fbc746f4.tar.xz
UXP-091d00f1bd22f821d3926c46dd1d6cf7fbc746f4.zip
1339395 - Part 2: Add parser support for rest and spread object properties.
Diffstat (limited to 'js/src/frontend/Parser.cpp')
-rw-r--r--js/src/frontend/Parser.cpp42
1 files changed, 36 insertions, 6 deletions
diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp
index 585eef59d..47e0f943d 100644
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -4367,9 +4367,20 @@ Parser<ParseHandler>::objectBindingPattern(DeclarationKind kind, YieldHandling y
break;
if (tt == TOK_TRIPLEDOT) {
- // TODO: rest-binding property
- error(JSMSG_UNEXPECTED_TOKEN, "property name", TokenKindToDesc(tt));
- return null();
+ // rest-binding property
+ tokenStream.consumeKnownToken(TOK_TRIPLEDOT);
+ uint32_t begin = pos().begin;
+
+ TokenKind tt;
+ if (!tokenStream.getToken(&tt))
+ return null();
+
+ Node inner = bindingIdentifierOrPattern(kind, yieldHandling, tt);
+ if (!inner)
+ return null();
+
+ if (!handler.addSpreadProperty(literal, begin, inner))
+ return null();
} else {
TokenPos namePos = tokenStream.nextToken().pos;
@@ -4439,6 +4450,10 @@ Parser<ParseHandler>::objectBindingPattern(DeclarationKind kind, YieldHandling y
return null();
if (!matched)
break;
+ if (tt == TOK_TRIPLEDOT) {
+ error(JSMSG_REST_WITH_COMMA);
+ return null();
+ }
}
MUST_MATCH_TOKEN_MOD_WITH_REPORT(TOK_RC, TokenStream::None,
@@ -9693,9 +9708,22 @@ Parser<ParseHandler>::objectLiteral(YieldHandling yieldHandling, PossibleError*
break;
if (tt == TOK_TRIPLEDOT) {
- // TODO: object spread
- error(JSMSG_UNEXPECTED_TOKEN, "property name", TokenKindToDesc(tt));
- return null();
+ // object spread
+ tokenStream.consumeKnownToken(TOK_TRIPLEDOT);
+ uint32_t begin = pos().begin;
+
+ TokenPos innerPos;
+ if (!tokenStream.peekTokenPos(&innerPos, TokenStream::Operand))
+ return null();
+
+ Node inner = assignExpr(InAllowed, yieldHandling, TripledotProhibited,
+ possibleError);
+ if (!inner)
+ return null();
+ if (possibleError)
+ checkDestructuringAssignmentTarget(inner, innerPos, possibleError);
+ if (!handler.addSpreadProperty(literal, begin, inner))
+ return null();
} else {
TokenPos namePos = tokenStream.nextToken().pos;
@@ -9860,6 +9888,8 @@ Parser<ParseHandler>::objectLiteral(YieldHandling yieldHandling, PossibleError*
return null();
if (!matched)
break;
+ if (tt == TOK_TRIPLEDOT && possibleError)
+ possibleError->setPendingDestructuringErrorAt(pos(), JSMSG_REST_WITH_COMMA);
}
MUST_MATCH_TOKEN_MOD_WITH_REPORT(TOK_RC, TokenStream::None,