Remove Parser::reportBadReturn

Report simpler errors that don't use the offset of a node as location.
This commit is contained in:
wolfbeast 2019-04-06 06:54:09 +02:00 committed by Roy Tam
commit f1f8d377a9
6 changed files with 11 additions and 30 deletions

View file

@ -909,21 +909,6 @@ Parser<ParseHandler>::parse()
return pn;
}
template <typename ParseHandler>
bool
Parser<ParseHandler>::reportBadReturn(Node pn, ParseReportKind kind,
unsigned errnum, unsigned anonerrnum)
{
JSAutoByteString name;
if (JSAtom* atom = pc->functionBox()->function()->explicitName()) {
if (!AtomToPrintableString(context, atom, &name))
return false;
} else {
errnum = anonerrnum;
}
return reportWithNode(kind, pc->sc()->strict(), pn, errnum, name.ptr());
}
/*
* Strict mode forbids introducing new definitions for 'eval', 'arguments', or
* for any strict mode reserved keyword.
@ -6023,10 +6008,9 @@ Parser<ParseHandler>::returnStatement(YieldHandling yieldHandling)
if (!pn)
return null();
/* Disallow "return v;" in legacy generators. */
if (pc->isLegacyGenerator() && exprNode) {
/* Disallow "return v;" in legacy generators. */
reportBadReturn(pn, ParseError, JSMSG_BAD_GENERATOR_RETURN,
JSMSG_BAD_ANON_GENERATOR_RETURN);
errorAt(begin, JSMSG_BAD_GENERATOR_RETURN);
return null();
}
@ -6141,8 +6125,7 @@ Parser<ParseHandler>::yieldExpression(InHandling inHandling)
)
{
/* As in Python (see PEP-255), disallow return v; in generators. */
reportBadReturn(null(), ParseError, JSMSG_BAD_GENERATOR_RETURN,
JSMSG_BAD_ANON_GENERATOR_RETURN);
errorAt(begin, JSMSG_BAD_GENERATOR_RETURN);
return null();
}