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

Unified Diff: src/parsing/parser-base.h

Issue 1522693002: [es6] strict eval/arguments and strong undefined in AssignmentPattern (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « no previous file | src/parsing/preparser.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parsing/parser-base.h
diff --git a/src/parsing/parser-base.h b/src/parsing/parser-base.h
index 581015f5c9b88196869e988a16165481d66d3139..70c9548483154b04e02241c98735d494aad2a969 100644
--- a/src/parsing/parser-base.h
+++ b/src/parsing/parser-base.h
@@ -1523,8 +1523,14 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseArrayLiteral(
first_spread_index = values->length();
}
- CheckDestructuringElement(argument, classifier, start_pos,
- scanner()->location().end_pos);
+ if (argument->IsAssignment()) {
+ classifier->RecordPatternError(
+ Scanner::Location(start_pos, scanner()->location().end_pos),
+ MessageTemplate::kInvalidDestructuringTarget);
+ } else {
+ CheckDestructuringElement(argument, classifier, start_pos,
+ scanner()->location().end_pos);
+ }
if (peek() == Token::COMMA) {
classifier->RecordPatternError(
@@ -1534,12 +1540,6 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseArrayLiteral(
} else {
elem = this->ParseAssignmentExpression(true, kIsPatternElement,
classifier, CHECK_OK);
- if (!this->IsValidReferenceExpression(elem) &&
- !classifier->is_valid_assignment_pattern()) {
- classifier->RecordPatternError(
- Scanner::Location(pos, scanner()->location().end_pos),
- MessageTemplate::kInvalidDestructuringTarget);
- }
}
values->Add(elem, zone_);
if (peek() != Token::RBRACK) {
@@ -1666,18 +1666,10 @@ ParserBase<Traits>::ParsePropertyDefinition(
CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
}
Consume(Token::COLON);
- int pos = peek_position();
value = this->ParseAssignmentExpression(
true, kIsPatternElement, classifier,
CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
- if (!this->IsValidReferenceExpression(value) &&
- !classifier->is_valid_assignment_pattern()) {
- classifier->RecordPatternError(
- Scanner::Location(pos, scanner()->location().end_pos),
- MessageTemplate::kInvalidDestructuringTarget);
- }
-
return factory()->NewObjectLiteralProperty(name_expression, value, false,
*is_computed_name);
}
@@ -1710,6 +1702,7 @@ ParserBase<Traits>::ParsePropertyDefinition(
ExpressionT lhs = this->ExpressionFromIdentifier(
name, next_beg_pos, next_end_pos, scope_, factory());
+ CheckDestructuringElement(lhs, classifier, next_beg_pos, next_end_pos);
if (peek() == Token::ASSIGN) {
Consume(Token::ASSIGN);
@@ -2045,16 +2038,12 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, int flags,
bool maybe_pattern =
expression->IsObjectLiteral() || expression->IsArrayLiteral();
- // bool binding_pattern =
- // allow_harmony_destructuring_bind() && maybe_pattern && !is_rhs;
if (!Token::IsAssignmentOp(peek())) {
// Parsed conditional expression only (no assignment).
- if (is_pattern_element && !this->IsValidReferenceExpression(expression) &&
- !maybe_pattern) {
- classifier->RecordPatternError(
- Scanner::Location(lhs_beg_pos, scanner()->location().end_pos),
- MessageTemplate::kInvalidDestructuringTarget);
+ if (is_pattern_element) {
+ CheckDestructuringElement(expression, classifier, lhs_beg_pos,
+ scanner()->location().end_pos);
} else if (is_rhs && maybe_pattern) {
ValidateExpression(classifier, CHECK_OK);
}
@@ -2077,6 +2066,10 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, int flags,
classifier, expression, lhs_beg_pos, scanner()->location().end_pos,
MessageTemplate::kInvalidLhsInAssignment);
} else {
+ if (is_pattern_element) {
+ CheckDestructuringElement(expression, classifier, lhs_beg_pos,
+ scanner()->location().end_pos);
+ }
expression = this->CheckAndRewriteReferenceExpression(
expression, lhs_beg_pos, scanner()->location().end_pos,
MessageTemplate::kInvalidLhsInAssignment, CHECK_OK);
@@ -3284,13 +3277,14 @@ void ParserBase<Traits>::CheckDestructuringElement(
int end) {
static const MessageTemplate::Template message =
MessageTemplate::kInvalidDestructuringTarget;
- if (!this->IsAssignableIdentifier(expression)) {
- const Scanner::Location location(begin, end);
+ const Scanner::Location location(begin, end);
+ if (expression->IsArrayLiteral() || expression->IsObjectLiteral() ||
+ expression->IsAssignment())
+ return;
adamk 2015/12/16 09:45:42 Nit: wrap this in a block (required by style since
+ if (expression->IsProperty()) {
classifier->RecordBindingPatternError(location, message);
- if (!expression->IsProperty() &&
- !(expression->IsObjectLiteral() || expression->IsArrayLiteral())) {
- classifier->RecordAssignmentPatternError(location, message);
- }
+ } else if (!this->IsAssignableIdentifier(expression)) {
+ classifier->RecordPatternError(location, message);
}
}
« no previous file with comments | « no previous file | src/parsing/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698