summaryrefslogtreecommitdiffstats
path: root/js
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@wolfbeast.com>2019-04-06 06:39:27 +0200
committerwolfbeast <mcwerewolf@wolfbeast.com>2019-04-06 06:39:27 +0200
commit7d56f431ccc11f3b5e2e6deec331bd9c7a06cf80 (patch)
tree6ac572fc5d17fe69c465745deb0fca0d7adab4c0 /js
parent386cc5ee17b4e144fdffda1742031aa0cba7373a (diff)
downloadUXP-7d56f431ccc11f3b5e2e6deec331bd9c7a06cf80.tar
UXP-7d56f431ccc11f3b5e2e6deec331bd9c7a06cf80.tar.gz
UXP-7d56f431ccc11f3b5e2e6deec331bd9c7a06cf80.tar.lz
UXP-7d56f431ccc11f3b5e2e6deec331bd9c7a06cf80.tar.xz
UXP-7d56f431ccc11f3b5e2e6deec331bd9c7a06cf80.zip
Introduce Parser::errorAt
This reduces reporting an error at a particular offset to its bare essentials, simplifying calls.
Diffstat (limited to 'js')
-rw-r--r--js/src/frontend/Parser.cpp71
-rw-r--r--js/src/frontend/Parser.h3
2 files changed, 42 insertions, 32 deletions
diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp
index 34d87528f..b494cc966 100644
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -609,6 +609,20 @@ Parser<ParseHandler>::error(unsigned errorNumber, ...)
}
template <typename ParseHandler>
+void
+Parser<ParseHandler>::errorAt(uint32_t offset, unsigned errorNumber, ...)
+{
+ va_list args;
+ va_start(args, errorNumber);
+#ifdef DEBUG
+ bool result =
+#endif
+ reportHelper(ParseError, false, offset, errorNumber, args);
+ MOZ_ASSERT(!result, "reporting an error returned true?");
+ va_end(args);
+}
+
+template <typename ParseHandler>
bool
Parser<ParseHandler>::warning(unsigned errorNumber, ...)
{
@@ -940,8 +954,7 @@ Parser<ParseHandler>::checkStrictBinding(PropertyName* name, TokenPos pos)
JSAutoByteString bytes;
if (!AtomToPrintableString(context, name, &bytes))
return false;
- return reportWithOffset(ParseStrictError, pc->sc()->strict(), pos.begin,
- JSMSG_BAD_BINDING, bytes.ptr());
+ return strictModeErrorAt(pos.begin, JSMSG_BAD_BINDING, bytes.ptr());
}
return true;
@@ -977,8 +990,7 @@ Parser<ParseHandler>::reportRedeclaration(HandlePropertyName name, DeclarationKi
JSAutoByteString bytes;
if (!AtomToPrintableString(context, name, &bytes))
return;
- reportWithOffset(ParseError, false, pos.begin, JSMSG_REDECLARED_VAR,
- DeclarationKindString(kind), bytes.ptr());
+ errorAt(pos.begin, JSMSG_REDECLARED_VAR, DeclarationKindString(kind), bytes.ptr());
}
// notePositionalFormalParameter is called for both the arguments of a regular
@@ -1247,11 +1259,11 @@ Parser<ParseHandler>::checkLexicalDeclarationDirectlyWithinBlock(ParseContext::S
if (!StatementKindIsBraced(stmt.kind()) &&
stmt.kind() != StatementKind::ForLoopLexicalHead)
{
- reportWithOffset(ParseError, false, pos.begin,
- stmt.kind() == StatementKind::Label
- ? JSMSG_LEXICAL_DECL_LABEL
- : JSMSG_LEXICAL_DECL_NOT_IN_BLOCK,
- DeclarationKindString(kind));
+ errorAt(pos.begin,
+ stmt.kind() == StatementKind::Label
+ ? JSMSG_LEXICAL_DECL_LABEL
+ : JSMSG_LEXICAL_DECL_NOT_IN_BLOCK,
+ DeclarationKindString(kind));
return false;
}
@@ -1341,7 +1353,7 @@ Parser<ParseHandler>::noteDeclaredName(HandlePropertyName name, DeclarationKind
// contain 'let'. (CatchParameter is the only lexical binding form
// without this restriction.)
if (name == context->names().let) {
- reportWithOffset(ParseError, false, pos.begin, JSMSG_LEXICAL_DECL_DEFINES_LET);
+ errorAt(pos.begin, JSMSG_LEXICAL_DECL_DEFINES_LET);
return false;
}
@@ -3730,7 +3742,7 @@ Parser<ParseHandler>::checkUnescapedName()
if (!token.nameContainsEscape())
return true;
- reportWithOffset(ParseError, false, token.pos.begin, JSMSG_ESCAPED_KEYWORD);
+ errorAt(token.pos.begin, JSMSG_ESCAPED_KEYWORD);
return false;
}
@@ -3840,8 +3852,7 @@ Parser<ParseHandler>::maybeParseDirective(Node list, Node possibleDirective, boo
: funbox->hasParameterExprs
? "default"
: "rest";
- reportWithOffset(ParseError, false, directivePos.begin,
- JSMSG_STRICT_NON_SIMPLE_PARAMS, parameterKind);
+ errorAt(directivePos.begin, JSMSG_STRICT_NON_SIMPLE_PARAMS, parameterKind);
return false;
}
}
@@ -4038,7 +4049,7 @@ Parser<ParseHandler>::PossibleError::checkForError(ErrorKind kind)
return true;
Error& err = error(kind);
- parser_.reportWithOffset(ParseError, false, err.offset_, err.errorNumber_);
+ parser_.errorAt(err.offset_, err.errorNumber_);
return false;
}
@@ -4327,11 +4338,11 @@ Parser<ParseHandler>::destructuringDeclarationWithoutYieldOrAwait(DeclarationKin
Node res = destructuringDeclaration(kind, yieldHandling, tt);
if (res) {
if (pc->lastYieldOffset != startYieldOffset) {
- reportWithOffset(ParseError, false, pc->lastYieldOffset, JSMSG_YIELD_IN_DEFAULT);
+ errorAt(pc->lastYieldOffset, JSMSG_YIELD_IN_DEFAULT);
return null();
}
if (pc->lastAwaitOffset != startAwaitOffset) {
- reportWithOffset(ParseError, false, pc->lastAwaitOffset, JSMSG_AWAIT_IN_DEFAULT);
+ errorAt(pc->lastAwaitOffset, JSMSG_AWAIT_IN_DEFAULT);
return null();
}
}
@@ -4779,7 +4790,7 @@ Parser<FullParseHandler>::namedImportsOrNamespaceImport(TokenKind tt, Node impor
return false;
if (tt != TOK_NAME || tokenStream.currentName() != context->names().as) {
- reportWithOffset(ParseError, false, pos().begin, JSMSG_AS_AFTER_IMPORT_STAR);
+ error(JSMSG_AS_AFTER_IMPORT_STAR);
return false;
}
@@ -5662,7 +5673,7 @@ Parser<ParseHandler>::forStatement(YieldHandling yieldHandling)
Node init = startNode;
if (isForEach) {
- reportWithOffset(ParseError, false, begin, JSMSG_BAD_FOR_EACH_LOOP);
+ errorAt(begin, JSMSG_BAD_FOR_EACH_LOOP);
return null();
}
@@ -5897,7 +5908,7 @@ Parser<ParseHandler>::continueStatement(YieldHandling yieldHandling)
if (foundLoop)
error(JSMSG_LABEL_NOT_FOUND);
else
- reportWithOffset(ParseError, false, begin, JSMSG_BAD_CONTINUE);
+ errorAt(begin, JSMSG_BAD_CONTINUE);
return null();
}
@@ -5956,7 +5967,7 @@ Parser<ParseHandler>::breakStatement(YieldHandling yieldHandling)
};
if (!pc->findInnermostStatement(isBreakTarget)) {
- reportWithOffset(ParseError, false, begin, JSMSG_TOUGH_BREAK);
+ errorAt(begin, JSMSG_TOUGH_BREAK);
return null();
}
}
@@ -6111,8 +6122,7 @@ Parser<ParseHandler>::yieldExpression(InHandling inHandling)
}
if (pc->functionBox()->isArrow()) {
- reportWithOffset(ParseError, false, begin,
- JSMSG_YIELD_IN_ARROW, js_yield_str);
+ errorAt(begin, JSMSG_YIELD_IN_ARROW, js_yield_str);
return null();
}
@@ -6120,8 +6130,7 @@ Parser<ParseHandler>::yieldExpression(InHandling inHandling)
pc->functionBox()->function()->isGetter() ||
pc->functionBox()->function()->isSetter())
{
- reportWithOffset(ParseError, false, begin,
- JSMSG_YIELD_IN_METHOD, js_yield_str);
+ errorAt(begin, JSMSG_YIELD_IN_METHOD, js_yield_str);
return null();
}
@@ -6266,7 +6275,7 @@ Parser<ParseHandler>::labeledStatement(YieldHandling yieldHandling)
uint32_t begin = pos().begin;
if (pc->findInnermostStatement<ParseContext::LabelStatement>(hasSameLabel)) {
- reportWithOffset(ParseError, false, begin, JSMSG_DUPLICATE_LABEL);
+ errorAt(begin, JSMSG_DUPLICATE_LABEL);
return null();
}
@@ -8297,8 +8306,7 @@ Parser<ParseHandler>::comprehension(GeneratorKind comprehensionKind)
return null();
if (comprehensionKind != NotGenerator && pc->lastYieldOffset != startYieldOffset) {
- reportWithOffset(ParseError, false, pc->lastYieldOffset,
- JSMSG_BAD_GENEXP_BODY, js_yield_str);
+ errorAt(pc->lastYieldOffset, JSMSG_BAD_GENEXP_BODY, js_yield_str);
return null();
}
@@ -8360,11 +8368,11 @@ Parser<ParseHandler>::assignExprWithoutYieldOrAwait(YieldHandling yieldHandling)
Node res = assignExpr(InAllowed, yieldHandling, TripledotProhibited);
if (res) {
if (pc->lastYieldOffset != startYieldOffset) {
- reportWithOffset(ParseError, false, pc->lastYieldOffset, JSMSG_YIELD_IN_DEFAULT);
+ errorAt(pc->lastYieldOffset, JSMSG_YIELD_IN_DEFAULT);
return null();
}
if (pc->lastAwaitOffset != startAwaitOffset) {
- reportWithOffset(ParseError, false, pc->lastAwaitOffset, JSMSG_AWAIT_IN_DEFAULT);
+ errorAt(pc->lastAwaitOffset, JSMSG_AWAIT_IN_DEFAULT);
return null();
}
}
@@ -9211,8 +9219,7 @@ Parser<ParseHandler>::objectLiteral(YieldHandling yieldHandling, PossibleError*
// Directly report the error when we're not in a
// destructuring context.
if (!possibleError) {
- reportWithOffset(ParseError, false, namePos.begin,
- JSMSG_DUPLICATE_PROTO_PROPERTY);
+ errorAt(namePos.begin, JSMSG_DUPLICATE_PROTO_PROPERTY);
return null();
}
@@ -9459,7 +9466,7 @@ Parser<ParseHandler>::tryNewTarget(Node &newTarget)
return false;
if (!pc->sc()->allowNewTarget()) {
- reportWithOffset(ParseError, false, begin, JSMSG_BAD_NEWTARGET);
+ errorAt(begin, JSMSG_BAD_NEWTARGET);
return false;
}
diff --git a/js/src/frontend/Parser.h b/js/src/frontend/Parser.h
index 13580846b..efbaebafd 100644
--- a/js/src/frontend/Parser.h
+++ b/js/src/frontend/Parser.h
@@ -915,6 +915,9 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
/* Report the given error at the current offset. */
void error(unsigned errorNumber, ...);
+ /* Report the given error at the given offset. */
+ void errorAt(uint32_t offset, unsigned errorNumber, ...);
+
/*
* Handle a strict mode error at the current offset. Report an error if in
* strict mode code, or warn if not, using the given error number and