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

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 | test/cctest/test-parsing.cc » ('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..af6ee90eea4070a0c5c4ff3bced52e61fda32f6b 100644
--- a/src/parsing/parser-base.h
+++ b/src/parsing/parser-base.h
@@ -812,6 +812,9 @@ class ParserBase : public Traits {
ExpressionClassifier* classifier, ExpressionT expression, int beg_pos,
int end_pos, MessageTemplate::Template message,
ParseErrorType type = kSyntaxError);
+ void ClassifyReferenceExpression(ExpressionClassifier* classifier,
+ ExpressionT expression, int beg_pos,
+ int end_pos);
ExpressionT CheckAndRewriteReferenceExpression(
ExpressionT expression, int beg_pos, int end_pos,
MessageTemplate::Template message, ParseErrorType type, bool* ok);
@@ -1517,6 +1520,8 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseArrayLiteral(
Consume(Token::ELLIPSIS);
ExpressionT argument =
this->ParseAssignmentExpression(true, classifier, CHECK_OK);
+ ClassifyReferenceExpression(classifier, argument, start_pos,
+ scanner()->location().end_pos);
elem = factory()->NewSpread(argument, start_pos);
if (first_spread_index < 0) {
@@ -1534,6 +1539,8 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseArrayLiteral(
} else {
elem = this->ParseAssignmentExpression(true, kIsPatternElement,
classifier, CHECK_OK);
+ ClassifyReferenceExpression(classifier, elem, pos,
+ scanner()->location().end_pos);
if (!this->IsValidReferenceExpression(elem) &&
!classifier->is_valid_assignment_pattern()) {
classifier->RecordPatternError(
@@ -1670,7 +1677,8 @@ ParserBase<Traits>::ParsePropertyDefinition(
value = this->ParseAssignmentExpression(
true, kIsPatternElement, classifier,
CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
-
+ ClassifyReferenceExpression(classifier, value, pos,
+ scanner()->location().end_pos);
if (!this->IsValidReferenceExpression(value) &&
!classifier->is_valid_assignment_pattern()) {
classifier->RecordPatternError(
@@ -1711,6 +1719,8 @@ ParserBase<Traits>::ParsePropertyDefinition(
ExpressionT lhs = this->ExpressionFromIdentifier(
name, next_beg_pos, next_end_pos, scope_, factory());
+ ClassifyReferenceExpression(classifier, lhs, next_beg_pos, next_end_pos);
+
if (peek() == Token::ASSIGN) {
Consume(Token::ASSIGN);
ExpressionClassifier rhs_classifier;
@@ -2050,6 +2060,10 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, int flags,
if (!Token::IsAssignmentOp(peek())) {
// Parsed conditional expression only (no assignment).
+ if (is_pattern_element && !maybe_pattern) {
+ ClassifyReferenceExpression(classifier, expression, lhs_beg_pos,
+ scanner()->location().end_pos);
+ }
if (is_pattern_element && !this->IsValidReferenceExpression(expression) &&
!maybe_pattern) {
classifier->RecordPatternError(
@@ -3238,6 +3252,23 @@ ParserBase<Traits>::CheckAndRewriteReferenceExpression(
template <typename Traits>
+void ParserBase<Traits>::ClassifyReferenceExpression(
adamk 2015/12/12 01:03:35 Indeed, this code is very close to the existing Ch
+ ExpressionClassifier* classifier, ExpressionT expression, int beg_pos,
+ int end_pos) {
+ if (!this->IsIdentifier(expression)) return;
+ IdentifierT ref = this->AsIdentifier(expression);
+ if (is_strict(language_mode()) && this->IsEvalOrArguments(ref)) {
+ classifier->RecordAssignmentPatternError(
+ Scanner::Location(beg_pos, end_pos),
+ MessageTemplate::kStrictEvalArguments);
+ } else if (is_strong(language_mode()) && this->IsUndefined(ref)) {
+ classifier->RecordAssignmentPatternError(
+ Scanner::Location(beg_pos, end_pos), MessageTemplate::kStrongUndefined);
+ }
+}
+
+
+template <typename Traits>
typename ParserBase<Traits>::ExpressionT
ParserBase<Traits>::ClassifyAndRewriteReferenceExpression(
ExpressionClassifier* classifier, ExpressionT expression, int beg_pos,
@@ -3248,12 +3279,16 @@ ParserBase<Traits>::ClassifyAndRewriteReferenceExpression(
this->IsEvalOrArguments(this->AsIdentifier(expression))) {
classifier->RecordExpressionError(
location, MessageTemplate::kStrictEvalArguments, kSyntaxError);
+ classifier->RecordAssignmentPatternError(
+ location, MessageTemplate::kStrictEvalArguments);
return expression;
}
if (is_strong(language_mode()) &&
this->IsUndefined(this->AsIdentifier(expression))) {
classifier->RecordExpressionError(
location, MessageTemplate::kStrongUndefined, kSyntaxError);
+ classifier->RecordAssignmentPatternError(
+ location, MessageTemplate::kStrongUndefined);
return expression;
}
}
« no previous file with comments | « no previous file | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698