Commit 52a01ae0 authored by nikolaos's avatar nikolaos Committed by Commit bot

Fix bug with spread rewriting

It was not properly rewriting three cases:

-   [...[42]][0]
-   [...[42]].length
-   [...[42]] `foo`    (which is a type error)

R=rossberg@chromium.org
BUG=v8:4696
LOG=N

Review URL: https://codereview.chromium.org/1617713002

Cr-Commit-Position: refs/heads/master@{#33433}
parent ea820ad5
......@@ -2353,6 +2353,7 @@ ParserBase<Traits>::ParseLeftHandSideExpression(
while (true) {
switch (peek()) {
case Token::LBRACK: {
result = Traits::RewriteNonPattern(result, classifier, CHECK_OK);
BindingPatternUnexpectedToken(classifier);
ArrowFormalParametersUnexpectedToken(classifier);
Consume(Token::LBRACK);
......@@ -2429,6 +2430,7 @@ ParserBase<Traits>::ParseLeftHandSideExpression(
}
case Token::PERIOD: {
result = Traits::RewriteNonPattern(result, classifier, CHECK_OK);
BindingPatternUnexpectedToken(classifier);
ArrowFormalParametersUnexpectedToken(classifier);
Consume(Token::PERIOD);
......@@ -2442,6 +2444,7 @@ ParserBase<Traits>::ParseLeftHandSideExpression(
case Token::TEMPLATE_SPAN:
case Token::TEMPLATE_TAIL: {
result = Traits::RewriteNonPattern(result, classifier, CHECK_OK);
BindingPatternUnexpectedToken(classifier);
ArrowFormalParametersUnexpectedToken(classifier);
result = ParseTemplateLiteral(result, position(), classifier, CHECK_OK);
......@@ -2780,6 +2783,8 @@ ParserBase<Traits>::ParseMemberExpressionContinuation(
while (true) {
switch (peek()) {
case Token::LBRACK: {
expression =
Traits::RewriteNonPattern(expression, classifier, CHECK_OK);
BindingPatternUnexpectedToken(classifier);
ArrowFormalParametersUnexpectedToken(classifier);
......@@ -2795,6 +2800,8 @@ ParserBase<Traits>::ParseMemberExpressionContinuation(
break;
}
case Token::PERIOD: {
expression =
Traits::RewriteNonPattern(expression, classifier, CHECK_OK);
BindingPatternUnexpectedToken(classifier);
ArrowFormalParametersUnexpectedToken(classifier);
......@@ -2810,6 +2817,8 @@ ParserBase<Traits>::ParseMemberExpressionContinuation(
}
case Token::TEMPLATE_SPAN:
case Token::TEMPLATE_TAIL: {
expression =
Traits::RewriteNonPattern(expression, classifier, CHECK_OK);
BindingPatternUnexpectedToken(classifier);
ArrowFormalParametersUnexpectedToken(classifier);
int pos;
......
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(function testSpreadIndex() {
var result = [...[17, 42]][1];
assertEquals(result, 42);
})();
(function testSpreadProperty() {
var result = [...[17, 42]].length;
assertEquals(result, 2);
})();
(function testSpreadMethodCall() {
var result = [...[17, 42]].join("+");
assertEquals(result, "17+42");
})();
(function testSpreadSavedMethodCall() {
var x = [...[17, 42]];
var method = x.join;
var result = method.call(x, "+");
assertEquals(result, "17+42");
})();
(function testSpreadAsTemplateTag() {
assertThrows(function() { [...[17, 42]] `foo`; }, TypeError)
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment