diff options
author | wolfbeast <mcwerewolf@wolfbeast.com> | 2019-04-05 21:32:55 +0200 |
---|---|---|
committer | wolfbeast <mcwerewolf@wolfbeast.com> | 2019-04-05 21:32:55 +0200 |
commit | 11a1f58b9a0ebf83c17087a89e6b4ba83748374a (patch) | |
tree | 86c539b27aab1dccfe18de803e80a44ad1a161ad /js | |
parent | 1ee96e39db760004c33a235ea691ab06bac21375 (diff) | |
download | UXP-11a1f58b9a0ebf83c17087a89e6b4ba83748374a.tar UXP-11a1f58b9a0ebf83c17087a89e6b4ba83748374a.tar.gz UXP-11a1f58b9a0ebf83c17087a89e6b4ba83748374a.tar.lz UXP-11a1f58b9a0ebf83c17087a89e6b4ba83748374a.tar.xz UXP-11a1f58b9a0ebf83c17087a89e6b4ba83748374a.zip |
Track strict mode errors in unary deletions correctly when
syntax-parsing.
Diffstat (limited to 'js')
-rw-r--r-- | js/src/frontend/Parser.cpp | 19 | ||||
-rw-r--r-- | js/src/frontend/Parser.h | 7 |
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, ...); |