Bug 1296814 - Split out Parser::strictError for the two calls that don't pass |bool strict = false|, so that |bool strict| can be removed from the current signature. r=arai

--HG--
extra : rebase_source : 061e1d88515399cb8824d3d12857e84c1c0e8b00
This commit is contained in:
Jeff Walden 2016-11-07 15:23:17 -08:00
parent 3b14786056
commit 2afe6227ce
2 changed files with 24 additions and 7 deletions

View File

@ -599,6 +599,17 @@ Parser<ParseHandler>::zeport(ParseReportKind kind, bool strict, unsigned errorNu
return result;
}
template <typename ParseHandler>
bool
Parser<ParseHandler>::strictModeError(unsigned errorNumber, ...)
{
va_list args;
va_start(args, errorNumber);
bool res = reportHelper(ParseStrictError, pc->sc()->strict(), pos().begin, errorNumber, args);
va_end(args);
return res;
}
template <typename ParseHandler>
bool
Parser<ParseHandler>::reportWithNode(ParseReportKind kind, bool strict, Node pn, unsigned errorNumber, ...)
@ -955,7 +966,7 @@ Parser<ParseHandler>::notePositionalFormalParameter(Node fn, HandlePropertyName
JSAutoByteString bytes;
if (!AtomToPrintableString(context, name, &bytes))
return false;
if (!zeport(ParseStrictError, pc->sc()->strict(), JSMSG_DUPLICATE_FORMAL, bytes.ptr()))
if (!strictModeError(JSMSG_DUPLICATE_FORMAL, bytes.ptr()))
return false;
}
@ -6102,14 +6113,13 @@ Parser<ParseHandler>::withStatement(YieldHandling yieldHandling)
MOZ_ASSERT(tokenStream.isCurrentTokenType(TOK_WITH));
uint32_t begin = pos().begin;
// In most cases, we want the constructs forbidden in strict mode code to be
// a subset of those that JSOPTION_EXTRA_WARNINGS warns about, and we should
// use reportStrictModeError. However, 'with' is the sole instance of a
// construct that is forbidden in strict mode code, but doesn't even merit a
// warning under JSOPTION_EXTRA_WARNINGS. See
// Usually we want the constructs forbidden in strict mode code to be a
// subset of those that ContextOptions::extraWarnings() warns about, and we
// use strictModeError directly. But while 'with' is forbidden in strict
// mode code, it doesn't even merit a warning in non-strict code. See
// https://bugzilla.mozilla.org/show_bug.cgi?id=514576#c1.
if (pc->sc()->strict()) {
if (!zeport(ParseStrictError, true, JSMSG_STRICT_CODE_WITH))
if (!strictModeError(JSMSG_STRICT_CODE_WITH))
return null();
}

View File

@ -913,6 +913,13 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
bool reportWithOffset(ParseReportKind kind, bool strict, 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
* arguments.
*/
MOZ_MUST_USE bool strictModeError(unsigned errorNumber, ...);
Parser(ExclusiveContext* cx, LifoAlloc& alloc, const ReadOnlyCompileOptions& options,
const char16_t* chars, size_t length, bool foldConstants, UsedNameTracker& usedNames,
Parser<SyntaxParseHandler>* syntaxParser, LazyScript* lazyOuterFunction);