Commit 3b30f4d3 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Change pattern error message so we can drop ExpressionClassifier::Error::arg

Changes [ x **= 2 ] = [] from

[ x **= 2 ] = []
    ^^^
SyntaxError: Unexpected token **=

to:

[ x **= 2 ] = []
  ^^^^^^^

SyntaxError: Invalid destructuring assignment target
Change-Id: I07170d12c151a94a7f99d37dce17197a3aa6f503
Reviewed-on: https://chromium-review.googlesource.com/c/1355140Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57940}
parent a35da84b
......@@ -85,11 +85,10 @@ class ExpressionClassifierBase {
V8_INLINE Error()
: location(Scanner::Location::invalid()),
message_(static_cast<int>(MessageTemplate::kNone)),
kind(kUnusedError),
arg(nullptr) {}
kind(kUnusedError) {}
V8_INLINE explicit Error(Scanner::Location loc, MessageTemplate msg,
ErrorKind k, const char* a = nullptr)
: location(loc), message_(static_cast<int>(msg)), kind(k), arg(a) {}
: location(loc), message_(static_cast<int>(msg)), kind(k) {}
Scanner::Location location;
// GCC doesn't like storing the enum class directly in 28 bits, so we
......@@ -101,7 +100,6 @@ class ExpressionClassifierBase {
}
int message_ : 28;
unsigned kind : 4;
const char* arg;
};
// clang-format off
......@@ -398,57 +396,51 @@ class ExpressionClassifier
V8_INLINE bool does_error_reporting() { return ReportErrors; }
void RecordExpressionError(const Scanner::Location& loc,
MessageTemplate message,
const char* arg = nullptr) {
MessageTemplate message) {
this->Add(TP::ExpressionProduction,
Error(loc, message, ErrorKind::kExpressionProduction, arg));
Error(loc, message, ErrorKind::kExpressionProduction));
}
void RecordFormalParameterInitializerError(const Scanner::Location& loc,
MessageTemplate message,
const char* arg = nullptr) {
this->Add(TP::FormalParameterInitializerProduction,
Error(loc, message,
ErrorKind::kFormalParameterInitializerProduction, arg));
MessageTemplate message) {
this->Add(
TP::FormalParameterInitializerProduction,
Error(loc, message, ErrorKind::kFormalParameterInitializerProduction));
}
void RecordPatternError(const Scanner::Location& loc, MessageTemplate message,
const char* arg = nullptr) {
void RecordPatternError(const Scanner::Location& loc,
MessageTemplate message) {
this->Add(TP::PatternProduction,
Error(loc, message, ErrorKind::kPatternProduction, arg));
Error(loc, message, ErrorKind::kPatternProduction));
}
void RecordBindingPatternError(const Scanner::Location& loc,
MessageTemplate message,
const char* arg = nullptr) {
MessageTemplate message) {
this->Add(TP::BindingPatternProduction,
Error(loc, message, ErrorKind::kBindingPatternProduction, arg));
Error(loc, message, ErrorKind::kBindingPatternProduction));
}
void RecordAsyncArrowFormalParametersError(const Scanner::Location& loc,
MessageTemplate message,
const char* arg = nullptr) {
this->Add(TP::AsyncArrowFormalParametersProduction,
Error(loc, message,
ErrorKind::kAsyncArrowFormalParametersProduction, arg));
MessageTemplate message) {
this->Add(
TP::AsyncArrowFormalParametersProduction,
Error(loc, message, ErrorKind::kAsyncArrowFormalParametersProduction));
}
// Record a binding that would be invalid in strict mode. Confusingly this
// is not the same as StrictFormalParameterList, which simply forbids
// duplicate bindings.
void RecordStrictModeFormalParameterError(const Scanner::Location& loc,
MessageTemplate message,
const char* arg = nullptr) {
this->Add(TP::StrictModeFormalParametersProduction,
Error(loc, message,
ErrorKind::kStrictModeFormalParametersProduction, arg));
MessageTemplate message) {
this->Add(
TP::StrictModeFormalParametersProduction,
Error(loc, message, ErrorKind::kStrictModeFormalParametersProduction));
}
void RecordLetPatternError(const Scanner::Location& loc,
MessageTemplate message,
const char* arg = nullptr) {
MessageTemplate message) {
this->Add(TP::LetPatternProduction,
Error(loc, message, ErrorKind::kLetPatternProduction, arg));
Error(loc, message, ErrorKind::kLetPatternProduction));
}
ExpressionClassifier* previous() const { return previous_; }
......
......@@ -952,7 +952,7 @@ class ParserBase {
V8_NOINLINE void ReportClassifierError(
const typename ExpressionClassifier::Error& error) {
if (classifier()->does_error_reporting()) {
impl()->ReportMessageAt(error.location, error.message(), error.arg);
impl()->ReportMessageAt(error.location, error.message());
} else {
impl()->ReportUnidentifiableError();
}
......@@ -2731,7 +2731,7 @@ ParserBase<Impl>::ParseAssignmentExpression() {
impl()->MarkExpressionAsAssigned(expression);
Consume(op);
Scanner::Location op_location = scanner()->location();
int op_position = position();
ExpressionT right = ParseAssignmentExpression();
// This is definitely not an assignment pattern, so don't accumulate
......@@ -2766,11 +2766,12 @@ ParserBase<Impl>::ParseAssignmentExpression() {
}
} else {
classifier()->RecordPatternError(
op_location, MessageTemplate::kUnexpectedToken, Token::String(op));
Scanner::Location(expression->position(), end_position()),
MessageTemplate::kInvalidDestructuringTarget);
fni_.RemoveLastFunction();
}
return factory()->NewAssignment(op, expression, right, op_location.beg_pos);
return factory()->NewAssignment(op, expression, right, op_position);
}
template <typename Impl>
......
......@@ -256,9 +256,9 @@ class Scanner {
Location() : beg_pos(0), end_pos(0) { }
int length() const { return end_pos - beg_pos; }
bool IsValid() const { return beg_pos >= 0 && end_pos >= beg_pos; }
bool IsValid() const { return IsInRange(beg_pos, 0, end_pos); }
static Location invalid() { return Location(-1, -1); }
static Location invalid() { return Location(-1, 0); }
int beg_pos;
int end_pos;
......
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