Commit 755d09e6 authored by Sathya Gunasekaran's avatar Sathya Gunasekaran Committed by Commit Bot

[parser] Update {Binding,Assignment}RestPattern

Only allow BindingIdentifier in BindingRestPattern and 
ValidReferenceExpression in AssignmentRestPattern.

Also updated to a better, actionable error message.

Bug: v8:6500, v8:6513
Cq-Include-Trybots: master.tryserver.v8:v8_linux_noi18n_rel_ng
Change-Id: Ifaba2f85c20bc20e263267e8c76d50a27075b87d
Reviewed-on: https://chromium-review.googlesource.com/550559
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46653}
parent bd910a98
......@@ -566,6 +566,11 @@ class ErrorUtils : public AllStatic {
T(IllegalLanguageModeDirective, \
"Illegal '%' directive in function with non-simple parameter list") \
T(IllegalReturn, "Illegal return statement") \
T(InvalidRestBindingPattern, \
"`...` must be followed by an identifier in declaration contexts") \
T(InvalidRestAssignmentPattern, \
"`...` must be followed by an assignable reference in assignment " \
"contexts") \
T(InvalidEscapedReservedWord, "Keyword must not contain escaped characters") \
T(InvalidEscapedMetaProperty, "'%' must not contain escaped characters") \
T(InvalidLhsInAssignment, "Invalid left-hand side in assignment") \
......
......@@ -2128,13 +2128,16 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePropertyName(
expression = ParseAssignmentExpression(true, CHECK_OK);
*kind = PropertyKind::kSpreadProperty;
if (expression->IsAssignment()) {
classifier()->RecordPatternError(
if (!impl()->IsIdentifier(expression)) {
classifier()->RecordBindingPatternError(
scanner()->location(),
MessageTemplate::kInvalidDestructuringTarget);
} else {
CheckDestructuringElement(expression, pos,
scanner()->location().end_pos);
MessageTemplate::kInvalidRestBindingPattern);
}
if (!expression->IsValidReferenceExpression()) {
classifier()->RecordAssignmentPatternError(
scanner()->location(),
MessageTemplate::kInvalidRestAssignmentPattern);
}
if (peek() != Token::RBRACE) {
......
......@@ -7368,7 +7368,6 @@ TEST(DestructuringPositiveTests) {
"[{x:x, y:y, ...z}, [a,b,c]]",
"[{x:x = 1, y:y = 2, ...z}, [a = 3, b = 4, c = 5]]",
"{...x}",
"{...{ x = 5} }",
"{x, ...y}",
"{x = 42, y = 15, ...z}",
"{42 : x = 42, ...y}",
......@@ -7541,6 +7540,12 @@ TEST(DestructuringNegativeTests) {
"{ ...method() {} }",
"{ ...function() {} }",
"{ ...*method() {} }",
"{...{x} }",
"{...[x] }",
"{...{ x = 5 } }",
"{...[ x = 5 ] }",
"{...x.f }",
"{...x[0] }",
NULL
};
......@@ -7855,6 +7860,9 @@ TEST(DestructuringAssignmentPositiveTests) {
"{x: { y = 10 } }",
"[(({ x } = { x: 1 }) => x).a]",
"{ ...d.x }",
"{ ...c[0]}",
// v8:4662
"{ x: (y) }",
"{ x: (y) = [] }",
......@@ -7869,9 +7877,12 @@ TEST(DestructuringAssignmentPositiveTests) {
NULL};
// clang-format on
RunParserSyncTest(context_data, data, kSuccess);
static const ParserFlag flags[] = {kAllowHarmonyObjectRestSpread};
RunParserSyncTest(context_data, data, kSuccess, NULL, 0, flags,
arraysize(flags));
RunParserSyncTest(mixed_assignments_context_data, data, kSuccess);
RunParserSyncTest(mixed_assignments_context_data, data, kSuccess, NULL, 0,
flags, arraysize(flags));
const char* empty_context_data[][2] = {
{"'use strict';", ""}, {"", ""}, {NULL, NULL}};
......
// Copyright 2017 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.
({...{}} = {});
*%(basename)s:5: SyntaxError: `...` must be followed by an assignable reference in assignment contexts
({...{}} = {});
^
SyntaxError: `...` must be followed by an assignable reference in assignment contexts
// Copyright 2017 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.
let {...{}} = {};
*%(basename)s:5: SyntaxError: `...` must be followed by an identifier in declaration contexts
let {...{}} = {};
^
SyntaxError: `...` must be followed by an identifier in declaration contexts
......@@ -130,8 +130,13 @@ assertEquals({ 3: 3 }, z);
var [...{...z}] = [{ x: 1}];
assertEquals({ 0: { x: 1} }, z);
var {...{x}} = { x: 1};
assertEquals(1, x);
var x = {};
({ ...x.f } = { a: 1 });
assertEquals(x.f, { a: 1 });
var x = [];
({ ...x[0] } = { a: 1 });
assertEquals(x[0], {a: 1});
var {4294967297: y, ...x} = {4294967297: 1, x: 1};
assertEquals(1, y);
......
......@@ -607,6 +607,57 @@
'harness/detachArrayBuffer': [SKIP],
'harness/detachArrayBuffer-$262.detachArrayBuffer': [SKIP],
# Invalid {Assignment,Binding}RestPattern
# https://bugs.chromium.org/p/v8/issues/detail?id=6500
'language/expressions/assignment/dstr-obj-rest-obj-own-property': [FAIL],
'language/statements/for-of/dstr-obj-rest-obj-own-property': [FAIL],
'language/statements/for-await-of/async-gen-dstr-const-async-obj-ptrn-rest-obj-nested-rest': [FAIL],
'language/statements/for-await-of/async-gen-dstr-let-obj-ptrn-rest-obj-own-property': [FAIL],
'language/statements/for-await-of/async-gen-decl-dstr-obj-rest-nested-obj': [FAIL],
'language/statements/for-await-of/async-gen-dstr-let-async-obj-ptrn-rest-obj-nested-rest': [FAIL],
'language/expressions/assignment/dstr-obj-rest-nested-obj-nested-rest': [FAIL],
'language/statements/for-await-of/async-func-dstr-let-async-obj-ptrn-rest-obj-own-property': [FAIL],
'language/statements/for-await-of/async-gen-dstr-var-obj-ptrn-rest-obj-nested-rest': [FAIL],
'language/statements/for-await-of/async-func-dstr-const-obj-ptrn-rest-nested-obj': [FAIL],
'language/statements/for-await-of/async-func-dstr-const-async-obj-ptrn-rest-obj-own-property': [FAIL],
'language/statements/for-await-of/async-func-dstr-let-obj-ptrn-rest-obj-nested-rest': [FAIL],
'language/statements/for-await-of/async-gen-dstr-var-obj-ptrn-rest-obj-own-property': [FAIL],
'language/expressions/assignment/dstr-obj-rest-nested-obj': [FAIL],
'language/statements/for-await-of/async-gen-dstr-let-obj-ptrn-rest-nested-obj': [FAIL],
'language/statements/for-await-of/async-func-dstr-var-async-obj-ptrn-rest-obj-nested-rest': [FAIL],
'language/statements/for-await-of/async-gen-dstr-let-obj-ptrn-rest-obj-nested-rest': [FAIL],
'language/statements/for-await-of/async-gen-dstr-var-async-obj-ptrn-rest-obj-nested-rest': [FAIL],
'language/statements/for-of/dstr-obj-rest-nested-obj': [FAIL],
'language/statements/for-await-of/async-gen-dstr-const-obj-ptrn-rest-obj-nested-rest': [FAIL],
'language/statements/for-await-of/async-func-dstr-var-async-obj-ptrn-rest-nested-obj': [FAIL],
'language/statements/for-await-of/async-gen-dstr-const-async-obj-ptrn-rest-obj-own-property': [FAIL],
'language/statements/for-await-of/async-gen-decl-dstr-obj-rest-nested-obj-nested-rest': [FAIL],
'language/statements/for-await-of/async-gen-dstr-var-async-obj-ptrn-rest-obj-own-property': [FAIL],
'language/statements/for-await-of/async-gen-dstr-var-obj-ptrn-rest-nested-obj': [FAIL],
'language/statements/for-await-of/async-gen-dstr-const-obj-ptrn-rest-obj-own-property': [FAIL],
'language/statements/for-await-of/async-func-dstr-let-async-obj-ptrn-rest-obj-nested-rest': [FAIL],
'language/statements/for-await-of/async-func-decl-dstr-obj-rest-nested-obj-nested-rest': [FAIL],
'language/statements/for-await-of/async-func-decl-dstr-obj-rest-obj-own-property': [FAIL],
'language/statements/for-await-of/async-func-dstr-const-async-obj-ptrn-rest-nested-obj': [FAIL],
'language/statements/for-await-of/async-gen-dstr-let-async-obj-ptrn-rest-nested-obj': [FAIL],
'language/statements/for-await-of/async-func-dstr-var-obj-ptrn-rest-nested-obj': [FAIL],
'language/statements/for-await-of/async-gen-dstr-const-async-obj-ptrn-rest-nested-obj': [FAIL],
'language/statements/for-await-of/async-func-decl-dstr-obj-rest-nested-obj': [FAIL],
'language/statements/for-await-of/async-func-dstr-var-obj-ptrn-rest-obj-nested-rest': [FAIL],
'language/statements/for-await-of/async-gen-decl-dstr-obj-rest-obj-own-property': [FAIL],
'language/statements/for-await-of/async-func-dstr-const-async-obj-ptrn-rest-obj-nested-rest': [FAIL],
'language/statements/for-await-of/async-func-dstr-let-obj-ptrn-rest-obj-own-property': [FAIL],
'language/statements/for-await-of/async-gen-dstr-var-async-obj-ptrn-rest-nested-obj': [FAIL],
'language/statements/for-of/dstr-obj-rest-nested-obj-nested-rest': [FAIL],
'language/statements/for-await-of/async-func-dstr-const-obj-ptrn-rest-obj-nested-rest': [FAIL],
'language/statements/for-await-of/async-func-dstr-let-obj-ptrn-rest-nested-obj': [FAIL],
'language/statements/for-await-of/async-func-dstr-let-async-obj-ptrn-rest-nested-obj': [FAIL],
'language/statements/for-await-of/async-func-dstr-var-obj-ptrn-rest-obj-own-property': [FAIL],
'language/statements/for-await-of/async-func-dstr-var-async-obj-ptrn-rest-obj-own-property': [FAIL],
'language/statements/for-await-of/async-gen-dstr-let-async-obj-ptrn-rest-obj-own-property': [FAIL],
'language/statements/for-await-of/async-gen-dstr-const-obj-ptrn-rest-nested-obj': [FAIL],
'language/statements/for-await-of/async-func-dstr-const-obj-ptrn-rest-obj-own-property': [FAIL],
############################ SKIPPED TESTS #############################
# These tests take a looong time to run.
......
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