diff options
author | Gaming4JC <g4jc@hyperbola.info> | 2019-07-14 13:39:17 -0400 |
---|---|---|
committer | Gaming4JC <g4jc@hyperbola.info> | 2019-07-18 22:38:45 -0400 |
commit | a4b91b5a8faf9dc09db252c89921775910f1c233 (patch) | |
tree | 08fc210678866596e1a9e38d7b7bc3c0651306c0 /js/src/frontend/Parser.h | |
parent | 55c897db3c504c10650b94d97bb13ed79b0e23c6 (diff) | |
download | UXP-a4b91b5a8faf9dc09db252c89921775910f1c233.tar UXP-a4b91b5a8faf9dc09db252c89921775910f1c233.tar.gz UXP-a4b91b5a8faf9dc09db252c89921775910f1c233.tar.lz UXP-a4b91b5a8faf9dc09db252c89921775910f1c233.tar.xz UXP-a4b91b5a8faf9dc09db252c89921775910f1c233.zip |
1303703 - Part 3: Syntax parse destructuring assignment patterns.
Diffstat (limited to 'js/src/frontend/Parser.h')
-rw-r--r-- | js/src/frontend/Parser.h | 53 |
1 files changed, 33 insertions, 20 deletions
diff --git a/js/src/frontend/Parser.h b/js/src/frontend/Parser.h index 8bd691fc4..88d2dad18 100644 --- a/js/src/frontend/Parser.h +++ b/js/src/frontend/Parser.h @@ -877,6 +877,12 @@ class ParserBase : public StrictModeGetter */ MOZ_MUST_USE bool extraWarning(unsigned errorNumber, ...); + /* + * If extra warnings are enabled, report the given warning at the given + * offset. + */ + MOZ_MUST_USE bool extraWarningAt(uint32_t offset, unsigned errorNumber, ...); + bool isValidStrictBinding(PropertyName* name); bool warnOnceAboutExprClosure(); @@ -941,7 +947,7 @@ class Parser final : public ParserBase, private JS::AutoGCRooter class MOZ_STACK_CLASS PossibleError { private: - enum class ErrorKind { Expression, Destructuring }; + enum class ErrorKind { Expression, Destructuring, DestructuringWarning }; enum class ErrorState { None, Pending }; @@ -956,11 +962,12 @@ class Parser final : public ParserBase, private JS::AutoGCRooter Parser<ParseHandler>& parser_; Error exprError_; Error destructuringError_; + Error destructuringWarning_; // Returns the error report. Error& error(ErrorKind kind); - // Return true if an error is pending without reporting + // Return true if an error is pending without reporting. bool hasError(ErrorKind kind); // Resolve any pending error. @@ -972,7 +979,11 @@ class Parser final : public ParserBase, private JS::AutoGCRooter // If there is a pending error, report it and return false, otherwise // return true. - bool checkForError(ErrorKind kind); + MOZ_MUST_USE bool checkForError(ErrorKind kind); + + // If there is a pending warning, report it and return either false or + // true depending on the werror option, otherwise return true. + MOZ_MUST_USE bool checkForWarning(ErrorKind kind); // Transfer an existing error to another instance. void transferErrorTo(ErrorKind kind, PossibleError* other); @@ -980,23 +991,33 @@ class Parser final : public ParserBase, private JS::AutoGCRooter public: explicit PossibleError(Parser<ParseHandler>& parser); + // Return true if a pending destructuring error is present. + bool hasPendingDestructuringError(); + // Set a pending destructuring error. Only a single error may be set // per instance, i.e. subsequent calls to this method are ignored and // won't overwrite the existing pending error. void setPendingDestructuringErrorAt(const TokenPos& pos, unsigned errorNumber); + // Set a pending destructuring warning. Only a single warning may be + // set per instance, i.e. subsequent calls to this method are ignored + // and won't overwrite the existing pending warning. + void setPendingDestructuringWarningAt(const TokenPos& pos, unsigned errorNumber); + // Set a pending expression error. Only a single error may be set per // instance, i.e. subsequent calls to this method are ignored and won't // overwrite the existing pending error. void setPendingExpressionErrorAt(const TokenPos& pos, unsigned errorNumber); - // If there is a pending destructuring error, report it and return - // false, otherwise return true. Clears any pending expression error. - bool checkForDestructuringError(); + // If there is a pending destructuring error or warning, report it and + // return false, otherwise return true. Clears any pending expression + // error. + MOZ_MUST_USE bool checkForDestructuringErrorOrWarning(); // If there is a pending expression error, report it and return false, - // otherwise return true. Clears any pending destructuring error. - bool checkForExpressionError(); + // otherwise return true. Clears any pending destructuring error or + // warning. + MOZ_MUST_USE bool checkForExpressionError(); // Pass pending errors between possible error instances. This is useful // for extending the lifetime of a pending error beyond the scope of @@ -1496,18 +1517,10 @@ class Parser final : public ParserBase, private JS::AutoGCRooter Node objectBindingPattern(DeclarationKind kind, YieldHandling yieldHandling); Node arrayBindingPattern(DeclarationKind kind, YieldHandling yieldHandling); - // Top-level entrypoint into destructuring assignment pattern checking and - // name-analyzing. - bool checkDestructuringAssignmentPattern(Node pattern, - PossibleError* possibleError = nullptr); - - // Recursive methods for checking/name-analyzing subcomponents of an - // destructuring assignment pattern. The array/object methods *must* be - // passed arrays or objects. The name method may be passed anything but - // will report an error if not passed a name. - bool checkDestructuringAssignmentArray(Node arrayPattern); - bool checkDestructuringAssignmentObject(Node objectPattern); - bool checkDestructuringAssignmentName(Node expr); + void checkDestructuringAssignmentTarget(Node expr, TokenPos exprPos, + PossibleError* possibleError); + void checkDestructuringAssignmentElement(Node expr, TokenPos exprPos, + PossibleError* possibleError); Node newNumber(const Token& tok) { return handler.newNumber(tok.number(), tok.decimalPoint(), tok.pos); |