Introduce Parser::warningAt

This reduces reporting an warning at a particular offset to its bare
essentials, simplifying calls.
This commit is contained in:
wolfbeast 2019-04-06 10:33:24 +02:00 • committed by Roy Tam
commit 218c8ce05c
2 changed files with 19 additions and 12 deletions

View file

@ -633,6 +633,17 @@ Parser<ParseHandler>::warning(unsigned errorNumber, ...)
return result; return result;
} }
template <typename ParseHandler>
bool
Parser<ParseHandler>::warningAt(uint32_t offset, unsigned errorNumber, ...)
{
va_list args;
va_start(args, errorNumber);
bool result = reportHelper(ParseWarning, false, offset, errorNumber, args);
va_end(args);
return result;
}
template <typename ParseHandler> template <typename ParseHandler>
bool bool
Parser<ParseHandler>::extraWarning(unsigned errorNumber, ...) Parser<ParseHandler>::extraWarning(unsigned errorNumber, ...)
@ -3858,8 +3869,7 @@ Parser<ParseHandler>::maybeParseDirective(Node list, Node possibleDirective, boo
} else if (directive == context->names().useAsm) { } else if (directive == context->names().useAsm) {
if (pc->isFunctionBox()) if (pc->isFunctionBox())
return asmJS(list); return asmJS(list);
return reportWithOffset(ParseWarning, false, directivePos.begin, return warningAt(directivePos.begin, JSMSG_USE_ASM_DIRECTIVE_FAIL);
JSMSG_USE_ASM_DIRECTIVE_FAIL);
} }
} }
return true; return true;
@ -3903,11 +3913,9 @@ Parser<ParseHandler>::statementList(YieldHandling yieldHandling)
if (!warnedAboutStatementsAfterReturn) { if (!warnedAboutStatementsAfterReturn) {
if (afterReturn) { if (afterReturn) {
if (!handler.isStatementPermittedAfterReturnStatement(next)) { if (!handler.isStatementPermittedAfterReturnStatement(next)) {
if (!reportWithOffset(ParseWarning, false, statementBegin, if (!warningAt(statementBegin, JSMSG_STMT_AFTER_RETURN))
JSMSG_STMT_AFTER_RETURN))
{
return null(); return null();
}
warnedAboutStatementsAfterReturn = true; warnedAboutStatementsAfterReturn = true;
} }
} else if (handler.isReturnStatement(next)) { } else if (handler.isReturnStatement(next)) {
@ -5836,11 +5844,9 @@ Parser<ParseHandler>::switchStatement(YieldHandling yieldHandling)
if (!warnedAboutStatementsAfterReturn) { if (!warnedAboutStatementsAfterReturn) {
if (afterReturn) { if (afterReturn) {
if (!handler.isStatementPermittedAfterReturnStatement(stmt)) { if (!handler.isStatementPermittedAfterReturnStatement(stmt)) {
if (!reportWithOffset(ParseWarning, false, statementBegin, if (!warningAt(statementBegin, JSMSG_STMT_AFTER_RETURN))
JSMSG_STMT_AFTER_RETURN))
{
return null(); return null();
}
warnedAboutStatementsAfterReturn = true; warnedAboutStatementsAfterReturn = true;
} }
} else if (handler.isReturnStatement(stmt)) { } else if (handler.isReturnStatement(stmt)) {

View file

@ -909,8 +909,6 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
public: public:
bool reportWithNode(ParseReportKind kind, bool strict, Node pn, unsigned errorNumber, ...); bool reportWithNode(ParseReportKind kind, bool strict, Node pn, unsigned errorNumber, ...);
bool reportNoOffset(ParseReportKind kind, bool strict, unsigned errorNumber, ...); bool reportNoOffset(ParseReportKind kind, bool strict, unsigned errorNumber, ...);
bool reportWithOffset(ParseReportKind kind, bool strict, uint32_t offset, unsigned errorNumber,
...);
/* Report the given error at the current offset. */ /* Report the given error at the current offset. */
void error(unsigned errorNumber, ...); void error(unsigned errorNumber, ...);
@ -935,6 +933,9 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
/* Report the given warning at the current offset. */ /* Report the given warning at the current offset. */
MOZ_MUST_USE bool warning(unsigned errorNumber, ...); MOZ_MUST_USE bool warning(unsigned errorNumber, ...);
/* Report the given warning at the given offset. */
MOZ_MUST_USE bool warningAt(uint32_t offset, unsigned errorNumber, ...);
/* /*
* If extra warnings are enabled, report the given warning at the current * If extra warnings are enabled, report the given warning at the current
* offset. * offset.