summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--js/src/frontend/Parser.cpp19
-rw-r--r--js/src/frontend/Parser.h7
2 files changed, 24 insertions, 2 deletions
diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp
index afbf4c4c9..f625595a2 100644
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -643,6 +643,17 @@ Parser<ParseHandler>::strictModeError(unsigned errorNumber, ...)
template <typename ParseHandler>
bool
+Parser<ParseHandler>::strictModeErrorAt(uint32_t offset, unsigned errorNumber, ...)
+{
+ va_list args;
+ va_start(args, errorNumber);
+ bool res = reportHelper(ParseStrictError, pc->sc()->strict(), offset, errorNumber, args);
+ va_end(args);
+ return res;
+}
+
+template <typename ParseHandler>
+bool
Parser<ParseHandler>::reportWithNode(ParseReportKind kind, bool strict, Node pn, unsigned errorNumber, ...)
{
uint32_t offset = (pn ? handler.getPosition(pn) : pos()).begin;
@@ -8031,6 +8042,10 @@ Parser<ParseHandler>::unaryExpr(YieldHandling yieldHandling, TripledotHandling t
}
case TOK_DELETE: {
+ uint32_t exprOffset;
+ if (!tokenStream.peekOffset(&exprOffset, TokenStream::Operand))
+ return null();
+
Node expr = unaryExpr(yieldHandling, TripledotProhibited);
if (!expr)
return null();
@@ -8038,9 +8053,9 @@ Parser<ParseHandler>::unaryExpr(YieldHandling yieldHandling, TripledotHandling t
// Per spec, deleting any unary expression is valid -- it simply
// returns true -- except for one case that is illegal in strict mode.
if (handler.isNameAnyParentheses(expr)) {
- bool strict = pc->sc()->strict();
- if (!reportWithNode(ParseStrictError, strict, expr, JSMSG_DEPRECATED_DELETE_OPERAND))
+ if (!strictModeErrorAt(exprOffset, JSMSG_DEPRECATED_DELETE_OPERAND))
return null();
+
pc->sc()->setBindingsAccessedDynamically();
}
diff --git a/js/src/frontend/Parser.h b/js/src/frontend/Parser.h
index feead0e63..c8914a2d7 100644
--- a/js/src/frontend/Parser.h
+++ b/js/src/frontend/Parser.h
@@ -922,6 +922,13 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
*/
MOZ_MUST_USE bool strictModeError(unsigned errorNumber, ...);
+ /*
+ * Handle a strict mode error at the given offset. Report an error if in
+ * strict mode code, or warn if not, using the given error number and
+ * arguments.
+ */
+ MOZ_MUST_USE bool strictModeErrorAt(uint32_t offset, unsigned errorNumber, ...);
+
/* Report the given warning at the current offset. */
MOZ_MUST_USE bool warning(unsigned errorNumber, ...);