summaryrefslogtreecommitdiffstats
path: root/js/src/frontend/Parser.h
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/frontend/Parser.h')
-rw-r--r--js/src/frontend/Parser.h477
1 files changed, 297 insertions, 180 deletions
diff --git a/js/src/frontend/Parser.h b/js/src/frontend/Parser.h
index 156a1c1b0..88d2dad18 100644
--- a/js/src/frontend/Parser.h
+++ b/js/src/frontend/Parser.h
@@ -85,6 +85,16 @@ class ParseContext : public Nestable<ParseContext>
}
};
+ struct ClassStatement : public Statement
+ {
+ FunctionBox* constructorBox;
+
+ explicit ClassStatement(ParseContext* pc)
+ : Statement(pc, StatementKind::Class),
+ constructorBox(nullptr)
+ { }
+ };
+
// The intra-function scope stack.
//
// Tracks declared and used names within a scope.
@@ -146,9 +156,9 @@ class ParseContext : public Nestable<ParseContext>
}
MOZ_MUST_USE bool addDeclaredName(ParseContext* pc, AddDeclaredNamePtr& p, JSAtom* name,
- DeclarationKind kind)
+ DeclarationKind kind, uint32_t pos)
{
- return maybeReportOOM(pc, declared_->add(p, name, DeclaredNameInfo(kind)));
+ return maybeReportOOM(pc, declared_->add(p, name, DeclaredNameInfo(kind, pos)));
}
// Remove all VarForAnnexBLexicalFunction declarations of a certain
@@ -330,17 +340,6 @@ class ParseContext : public Nestable<ParseContext>
// pointer may be nullptr.
Directives* newDirectives;
- // Set when parsing a declaration-like destructuring pattern. This flag
- // causes PrimaryExpr to create PN_NAME parse nodes for variable references
- // which are not hooked into any definition's use chain, added to any tree
- // context's AtomList, etc. etc. checkDestructuring will do that work
- // later.
- //
- // The comments atop checkDestructuring explain the distinction between
- // assignment-like and declaration-like destructuring patterns, and why
- // they need to be treated differently.
- mozilla::Maybe<DeclarationKind> inDestructuringDecl;
-
// Set when parsing a function and it has 'return <expr>;'
bool funHasReturnExpr;
@@ -432,6 +431,11 @@ class ParseContext : public Nestable<ParseContext>
return Statement::findNearest<T>(innermostStatement_, predicate);
}
+ template <typename T>
+ T* findInnermostStatement() {
+ return Statement::findNearest<T>(innermostStatement_);
+ }
+
AtomVector& positionalFormalParameterNames() {
return *positionalFormalParameterNames_;
}
@@ -532,6 +536,13 @@ ParseContext::Statement::is<ParseContext::LabelStatement>() const
return kind_ == StatementKind::Label;
}
+template <>
+inline bool
+ParseContext::Statement::is<ParseContext::ClassStatement>() const
+{
+ return kind_ == StatementKind::Class;
+}
+
template <typename T>
inline T&
ParseContext::Statement::as()
@@ -735,7 +746,155 @@ class UsedNameTracker
};
template <typename ParseHandler>
-class Parser final : private JS::AutoGCRooter, public StrictModeGetter
+class AutoAwaitIsKeyword;
+
+class ParserBase : public StrictModeGetter
+{
+ private:
+ ParserBase* thisForCtor() { return this; }
+
+ public:
+ ExclusiveContext* const context;
+
+ LifoAlloc& alloc;
+
+ TokenStream tokenStream;
+ LifoAlloc::Mark tempPoolMark;
+
+ /* list of parsed objects for GC tracing */
+ ObjectBox* traceListHead;
+
+ /* innermost parse context (stack-allocated) */
+ ParseContext* pc;
+
+ // For tracking used names in this parsing session.
+ UsedNameTracker& usedNames;
+
+ /* Compression token for aborting. */
+ SourceCompressionTask* sct;
+
+ ScriptSource* ss;
+
+ /* Root atoms and objects allocated for the parsed tree. */
+ AutoKeepAtoms keepAtoms;
+
+ /* Perform constant-folding; must be true when interfacing with the emitter. */
+ const bool foldConstants:1;
+
+ protected:
+#if DEBUG
+ /* Our fallible 'checkOptions' member function has been called. */
+ bool checkOptionsCalled:1;
+#endif
+
+ /*
+ * Not all language constructs can be handled during syntax parsing. If it
+ * is not known whether the parse succeeds or fails, this bit is set and
+ * the parse will return false.
+ */
+ bool abortedSyntaxParse:1;
+
+ /* Unexpected end of input, i.e. TOK_EOF not at top-level. */
+ bool isUnexpectedEOF_:1;
+
+ bool awaitIsKeyword_:1;
+
+ public:
+ bool awaitIsKeyword() const {
+ return awaitIsKeyword_;
+ }
+
+ ParserBase(ExclusiveContext* cx, LifoAlloc& alloc, const ReadOnlyCompileOptions& options,
+ const char16_t* chars, size_t length, bool foldConstants,
+ UsedNameTracker& usedNames, Parser<SyntaxParseHandler>* syntaxParser,
+ LazyScript* lazyOuterFunction);
+ ~ParserBase();
+
+ const char* getFilename() const { return tokenStream.getFilename(); }
+ JSVersion versionNumber() const { return tokenStream.versionNumber(); }
+ TokenPos pos() const { return tokenStream.currentToken().pos; }
+
+ // Determine whether |yield| is a valid name in the current context, or
+ // whether it's prohibited due to strictness, JS version, or occurrence
+ // inside a star generator.
+ bool yieldExpressionsSupported() {
+ return (versionNumber() >= JSVERSION_1_7 || pc->isGenerator()) && !pc->isAsync();
+ }
+
+ virtual bool strictMode() { return pc->sc()->strict(); }
+ bool setLocalStrictMode(bool strict) {
+ MOZ_ASSERT(tokenStream.debugHasNoLookahead());
+ return pc->sc()->setLocalStrictMode(strict);
+ }
+
+ const ReadOnlyCompileOptions& options() const {
+ return tokenStream.options();
+ }
+
+ bool hadAbortedSyntaxParse() {
+ return abortedSyntaxParse;
+ }
+ void clearAbortedSyntaxParse() {
+ abortedSyntaxParse = false;
+ }
+
+ bool isUnexpectedEOF() const { return isUnexpectedEOF_; }
+
+ bool reportNoOffset(ParseReportKind kind, bool strict, unsigned errorNumber, ...);
+
+ /* Report the given error at the current offset. */
+ void error(unsigned errorNumber, ...);
+ void errorWithNotes(UniquePtr<JSErrorNotes> notes, unsigned errorNumber, ...);
+
+ /* Report the given error at the given offset. */
+ void errorAt(uint32_t offset, unsigned errorNumber, ...);
+ void errorWithNotesAt(UniquePtr<JSErrorNotes> notes, 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, ...);
+
+ /*
+ * 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, ...);
+
+ /* Report the given warning at the given offset. */
+ MOZ_MUST_USE bool warningAt(uint32_t offset, unsigned errorNumber, ...);
+
+ /*
+ * If extra warnings are enabled, report the given warning at the current
+ * offset.
+ */
+ 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();
+ bool warnOnceAboutForEach();
+
+ protected:
+ enum InvokedPrediction { PredictUninvoked = false, PredictInvoked = true };
+ enum ForInitLocation { InForInit, NotInForInit };
+};
+
+template <typename ParseHandler>
+class Parser final : public ParserBase, private JS::AutoGCRooter
{
private:
using Node = typename ParseHandler::Node;
@@ -788,7 +947,7 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
class MOZ_STACK_CLASS PossibleError
{
private:
- enum class ErrorKind { Expression, Destructuring };
+ enum class ErrorKind { Expression, Destructuring, DestructuringWarning };
enum class ErrorState { None, Pending };
@@ -803,11 +962,12 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
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.
@@ -819,7 +979,11 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
// 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);
@@ -827,23 +991,33 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
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
@@ -853,50 +1027,6 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
};
public:
- ExclusiveContext* const context;
-
- LifoAlloc& alloc;
-
- TokenStream tokenStream;
- LifoAlloc::Mark tempPoolMark;
-
- /* list of parsed objects for GC tracing */
- ObjectBox* traceListHead;
-
- /* innermost parse context (stack-allocated) */
- ParseContext* pc;
-
- // For tracking used names in this parsing session.
- UsedNameTracker& usedNames;
-
- /* Compression token for aborting. */
- SourceCompressionTask* sct;
-
- ScriptSource* ss;
-
- /* Root atoms and objects allocated for the parsed tree. */
- AutoKeepAtoms keepAtoms;
-
- /* Perform constant-folding; must be true when interfacing with the emitter. */
- const bool foldConstants:1;
-
- private:
-#if DEBUG
- /* Our fallible 'checkOptions' member function has been called. */
- bool checkOptionsCalled:1;
-#endif
-
- /*
- * Not all language constructs can be handled during syntax parsing. If it
- * is not known whether the parse succeeds or fails, this bit is set and
- * the parse will return false.
- */
- bool abortedSyntaxParse:1;
-
- /* Unexpected end of input, i.e. TOK_EOF not at top-level. */
- bool isUnexpectedEOF_:1;
-
- public:
/* State specific to the kind of parse being performed. */
ParseHandler handler;
@@ -904,45 +1034,14 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
void freeTree(Node node) { handler.freeTree(node); }
public:
- bool reportNoOffset(ParseReportKind kind, bool strict, unsigned errorNumber, ...);
-
- /* Report the given error at the current offset. */
- void error(unsigned errorNumber, ...);
-
- /* Report the given error at the given offset. */
- void errorAt(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, ...);
-
- /*
- * 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, ...);
-
- /* Report the given warning at the given offset. */
- MOZ_MUST_USE bool warningAt(uint32_t offset, unsigned errorNumber, ...);
-
- /*
- * If extra warnings are enabled, report the given warning at the current
- * offset.
- */
- MOZ_MUST_USE bool extraWarning(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);
~Parser();
+ friend class AutoAwaitIsKeyword<ParseHandler>;
+ void setAwaitIsKeyword(bool isKeyword);
+
bool checkOptions();
// A Parser::Mark is the extension of the LifoAlloc::Mark to the entire
@@ -967,9 +1066,6 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
friend void js::frontend::MarkParser(JSTracer* trc, JS::AutoGCRooter* parser);
- const char* getFilename() const { return tokenStream.getFilename(); }
- JSVersion versionNumber() const { return tokenStream.versionNumber(); }
-
/*
* Parse a top-level JS script.
*/
@@ -980,7 +1076,7 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
* cx->tempLifoAlloc.
*/
ObjectBox* newObjectBox(JSObject* obj);
- FunctionBox* newFunctionBox(Node fn, JSFunction* fun, uint32_t preludeStart,
+ FunctionBox* newFunctionBox(Node fn, JSFunction* fun, uint32_t toStringStart,
Directives directives,
GeneratorKind generatorKind, FunctionAsyncKind asyncKind,
bool tryAnnexB);
@@ -995,24 +1091,14 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
void trace(JSTracer* trc);
- bool hadAbortedSyntaxParse() {
- return abortedSyntaxParse;
- }
- void clearAbortedSyntaxParse() {
- abortedSyntaxParse = false;
- }
-
- bool isUnexpectedEOF() const { return isUnexpectedEOF_; }
-
- bool checkUnescapedName();
-
private:
Parser* thisForCtor() { return this; }
JSAtom* stopStringCompression();
Node stringLiteral();
- Node noSubstitutionTemplate();
+ Node noSubstitutionTaggedTemplate();
+ Node noSubstitutionUntaggedTemplate();
Node templateLiteral(YieldHandling yieldHandling);
bool taggedTemplate(YieldHandling yieldHandling, Node nodeList, TokenKind tt);
bool appendToCallSiteObj(Node callSiteObj);
@@ -1061,7 +1147,7 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
// Parse an inner function given an enclosing ParseContext and a
// FunctionBox for the inner function.
- bool innerFunction(Node pn, ParseContext* outerpc, FunctionBox* funbox, uint32_t preludeStart,
+ bool innerFunction(Node pn, ParseContext* outerpc, FunctionBox* funbox, uint32_t toStringStart,
InHandling inHandling, YieldHandling yieldHandling,
FunctionSyntaxKind kind,
Directives inheritedDirectives, Directives* newDirectives);
@@ -1070,35 +1156,14 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
// ParseContext is already on the stack.
bool functionFormalParametersAndBody(InHandling inHandling, YieldHandling yieldHandling,
Node pn, FunctionSyntaxKind kind,
- mozilla::Maybe<uint32_t> parameterListEnd = mozilla::Nothing());
-
-
- // Determine whether |yield| is a valid name in the current context, or
- // whether it's prohibited due to strictness, JS version, or occurrence
- // inside a star generator.
- bool yieldExpressionsSupported() {
- return (versionNumber() >= JSVERSION_1_7 || pc->isGenerator()) && !pc->isAsync();
- }
+ mozilla::Maybe<uint32_t> parameterListEnd = mozilla::Nothing(),
+ bool isStandaloneFunction = false);
// Match the current token against the BindingIdentifier production with
// the given Yield parameter. If there is no match, report a syntax
// error.
PropertyName* bindingIdentifier(YieldHandling yieldHandling);
- virtual bool strictMode() { return pc->sc()->strict(); }
- bool setLocalStrictMode(bool strict) {
- MOZ_ASSERT(tokenStream.debugHasNoLookahead());
- return pc->sc()->setLocalStrictMode(strict);
- }
-
- const ReadOnlyCompileOptions& options() const {
- return tokenStream.options();
- }
-
- private:
- enum InvokedPrediction { PredictUninvoked = false, PredictInvoked = true };
- enum ForInitLocation { InForInit, NotInForInit };
-
private:
/*
* JS parsers, from lowest to highest precedence.
@@ -1116,10 +1181,10 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
* Some parsers have two versions: an always-inlined version (with an 'i'
* suffix) and a never-inlined version (with an 'n' suffix).
*/
- Node functionStmt(uint32_t preludeStart,
+ Node functionStmt(uint32_t toStringStart,
YieldHandling yieldHandling, DefaultHandling defaultHandling,
FunctionAsyncKind asyncKind = SyncFunction);
- Node functionExpr(uint32_t preludeStart, InvokedPrediction invoked = PredictUninvoked,
+ Node functionExpr(uint32_t toStringStart, InvokedPrediction invoked = PredictUninvoked,
FunctionAsyncKind asyncKind = SyncFunction);
Node statementList(YieldHandling yieldHandling);
@@ -1160,9 +1225,27 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
// continues a LexicalDeclaration.
bool nextTokenContinuesLetDeclaration(TokenKind next, YieldHandling yieldHandling);
- Node lexicalDeclaration(YieldHandling yieldHandling, bool isConst);
+ Node lexicalDeclaration(YieldHandling yieldHandling, DeclarationKind kind);
Node importDeclaration();
+
+ bool processExport(Node node);
+ bool processExportFrom(Node node);
+
+ Node exportFrom(uint32_t begin, Node specList);
+ Node exportBatch(uint32_t begin);
+ bool checkLocalExportNames(Node node);
+ Node exportClause(uint32_t begin);
+ Node exportFunctionDeclaration(uint32_t begin);
+ Node exportVariableStatement(uint32_t begin);
+ Node exportClassDeclaration(uint32_t begin);
+ Node exportLexicalDeclaration(uint32_t begin, DeclarationKind kind);
+ Node exportDefaultFunctionDeclaration(uint32_t begin,
+ FunctionAsyncKind asyncKind = SyncFunction);
+ Node exportDefaultClassDeclaration(uint32_t begin);
+ Node exportDefaultAssignExpr(uint32_t begin);
+ Node exportDefault(uint32_t begin);
+
Node exportDeclaration();
Node expressionStatement(YieldHandling yieldHandling,
InvokedPrediction invoked = PredictUninvoked);
@@ -1250,7 +1333,7 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
bool tryNewTarget(Node& newTarget);
bool checkAndMarkSuperScope();
- Node methodDefinition(uint32_t preludeStart, PropertyType propType, HandleAtom funName);
+ Node methodDefinition(uint32_t toStringStart, PropertyType propType, HandleAtom funName);
/*
* Additional JS parsers.
@@ -1258,7 +1341,7 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
bool functionArguments(YieldHandling yieldHandling, FunctionSyntaxKind kind,
Node funcpn);
- Node functionDefinition(uint32_t preludeStart, Node pn,
+ Node functionDefinition(uint32_t toStringStart, Node pn,
InHandling inHandling, YieldHandling yieldHandling, HandleAtom name,
FunctionSyntaxKind kind,
GeneratorKind generatorKind, FunctionAsyncKind asyncKind,
@@ -1294,21 +1377,34 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
bool checkExportedName(JSAtom* exportName);
bool checkExportedNamesForDeclaration(Node node);
+ bool checkExportedNameForClause(Node node);
+ bool checkExportedNameForFunction(Node node);
+ bool checkExportedNameForClass(Node node);
+
enum ClassContext { ClassStatement, ClassExpression };
Node classDefinition(YieldHandling yieldHandling, ClassContext classContext,
DefaultHandling defaultHandling);
- PropertyName* labelOrIdentifierReference(YieldHandling yieldHandling,
- bool yieldTokenizedAsName);
+ bool checkLabelOrIdentifierReference(HandlePropertyName ident,
+ uint32_t offset,
+ YieldHandling yieldHandling);
+
+ bool checkLocalExportName(HandlePropertyName ident, uint32_t offset) {
+ return checkLabelOrIdentifierReference(ident, offset, YieldIsName);
+ }
+
+ bool checkBindingIdentifier(HandlePropertyName ident,
+ uint32_t offset,
+ YieldHandling yieldHandling);
+
+ PropertyName* labelOrIdentifierReference(YieldHandling yieldHandling);
PropertyName* labelIdentifier(YieldHandling yieldHandling) {
- return labelOrIdentifierReference(yieldHandling, false);
+ return labelOrIdentifierReference(yieldHandling);
}
- PropertyName* identifierReference(YieldHandling yieldHandling,
- bool yieldTokenizedAsName = false)
- {
- return labelOrIdentifierReference(yieldHandling, yieldTokenizedAsName);
+ PropertyName* identifierReference(YieldHandling yieldHandling) {
+ return labelOrIdentifierReference(yieldHandling);
}
PropertyName* importedBinding() {
@@ -1337,23 +1433,27 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
Node newDotGeneratorName();
bool declareDotGeneratorName();
- bool skipLazyInnerFunction(Node pn, uint32_t preludeStart, FunctionSyntaxKind kind,
+ bool skipLazyInnerFunction(Node pn, uint32_t toStringStart, FunctionSyntaxKind kind,
bool tryAnnexB);
- bool innerFunction(Node pn, ParseContext* outerpc, HandleFunction fun, uint32_t preludeStart,
+ bool innerFunction(Node pn, ParseContext* outerpc, HandleFunction fun, uint32_t toStringStart,
InHandling inHandling, YieldHandling yieldHandling,
FunctionSyntaxKind kind,
GeneratorKind generatorKind, FunctionAsyncKind asyncKind, bool tryAnnexB,
Directives inheritedDirectives, Directives* newDirectives);
- bool trySyntaxParseInnerFunction(Node pn, HandleFunction fun, uint32_t preludeStart,
+ bool trySyntaxParseInnerFunction(Node pn, HandleFunction fun, uint32_t toStringStart,
InHandling inHandling, YieldHandling yieldHandling,
FunctionSyntaxKind kind,
GeneratorKind generatorKind, FunctionAsyncKind asyncKind,
bool tryAnnexB,
Directives inheritedDirectives, Directives* newDirectives);
- bool finishFunctionScopes();
- bool finishFunction();
+ bool finishFunctionScopes(bool isStandaloneFunction);
+ bool finishFunction(bool isStandaloneFunction = false);
bool leaveInnerFunction(ParseContext* outerpc);
+ bool matchOrInsertSemicolonHelper(TokenStream::Modifier modifier);
+ bool matchOrInsertSemicolonAfterExpression();
+ bool matchOrInsertSemicolonAfterNonExpression();
+
public:
enum FunctionCallBehavior {
PermitAssignmentToFunctionCalls,
@@ -1366,21 +1466,22 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
private:
bool checkIncDecOperand(Node operand, uint32_t operandOffset);
bool checkStrictAssignment(Node lhs);
- bool checkStrictBinding(PropertyName* name, TokenPos pos);
bool hasValidSimpleStrictParameterNames();
- bool isValidStrictBinding(PropertyName* name);
+ void reportMissingClosing(unsigned errorNumber, unsigned noteNumber, uint32_t openedPos);
- void reportRedeclaration(HandlePropertyName name, DeclarationKind kind, TokenPos pos);
- bool notePositionalFormalParameter(Node fn, HandlePropertyName name,
+ void reportRedeclaration(HandlePropertyName name, DeclarationKind prevKind, TokenPos pos,
+ uint32_t prevPos);
+ bool notePositionalFormalParameter(Node fn, HandlePropertyName name, uint32_t beginPos,
bool disallowDuplicateParams, bool* duplicatedParam);
bool noteDestructuredPositionalFormalParameter(Node fn, Node destruct);
mozilla::Maybe<DeclarationKind> isVarRedeclaredInEval(HandlePropertyName name,
DeclarationKind kind);
- bool tryDeclareVar(HandlePropertyName name, DeclarationKind kind,
- mozilla::Maybe<DeclarationKind>* redeclaredKind);
- bool tryDeclareVarForAnnexBLexicalFunction(HandlePropertyName name, bool* tryAnnexB);
+ bool tryDeclareVar(HandlePropertyName name, DeclarationKind kind, uint32_t beginPos,
+ mozilla::Maybe<DeclarationKind>* redeclaredKind, uint32_t* prevPos);
+ bool tryDeclareVarForAnnexBLexicalFunction(HandlePropertyName name, uint32_t beginPos,
+ bool* tryAnnexB);
bool checkLexicalDeclarationDirectlyWithinBlock(ParseContext::Statement& stmt,
DeclarationKind kind, TokenPos pos);
bool noteDeclaredName(HandlePropertyName name, DeclarationKind kind, TokenPos pos);
@@ -1399,25 +1500,27 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
mozilla::Maybe<LexicalScope::Data*> newLexicalScopeData(ParseContext::Scope& scope);
Node finishLexicalScope(ParseContext::Scope& scope, Node body);
- Node propertyName(YieldHandling yieldHandling, Node propList,
+ Node propertyName(YieldHandling yieldHandling,
+ const mozilla::Maybe<DeclarationKind>& maybeDecl, Node propList,
PropertyType* propType, MutableHandleAtom propAtom);
- Node computedPropertyName(YieldHandling yieldHandling, Node literal);
+ Node computedPropertyName(YieldHandling yieldHandling,
+ const mozilla::Maybe<DeclarationKind>& maybeDecl, Node literal);
Node arrayInitializer(YieldHandling yieldHandling, PossibleError* possibleError);
Node newRegExp();
Node objectLiteral(YieldHandling yieldHandling, PossibleError* possibleError);
- // Top-level entrypoint into destructuring pattern checking/name-analyzing.
- bool checkDestructuringPattern(Node pattern, mozilla::Maybe<DeclarationKind> maybeDecl,
- PossibleError* possibleError = nullptr);
+ Node bindingInitializer(Node lhs, DeclarationKind kind, YieldHandling yieldHandling);
+ Node bindingIdentifier(DeclarationKind kind, YieldHandling yieldHandling);
+ Node bindingIdentifierOrPattern(DeclarationKind kind, YieldHandling yieldHandling,
+ TokenKind tt);
+ Node objectBindingPattern(DeclarationKind kind, YieldHandling yieldHandling);
+ Node arrayBindingPattern(DeclarationKind kind, YieldHandling yieldHandling);
- // Recursive methods for checking/name-analyzing subcomponents of a
- // destructuring 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 checkDestructuringArray(Node arrayPattern, mozilla::Maybe<DeclarationKind> maybeDecl);
- bool checkDestructuringObject(Node objectPattern, mozilla::Maybe<DeclarationKind> maybeDecl);
- bool checkDestructuringName(Node expr, mozilla::Maybe<DeclarationKind> maybeDecl);
+ 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);
@@ -1427,12 +1530,26 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
JSAtom* prefixAccessorName(PropertyType propType, HandleAtom propAtom);
- TokenPos pos() const { return tokenStream.currentToken().pos; }
-
bool asmJS(Node list);
+};
- bool warnOnceAboutExprClosure();
- bool warnOnceAboutForEach();
+template <typename ParseHandler>
+class MOZ_STACK_CLASS AutoAwaitIsKeyword
+{
+ private:
+ Parser<ParseHandler>* parser_;
+ bool oldAwaitIsKeyword_;
+
+ public:
+ AutoAwaitIsKeyword(Parser<ParseHandler>* parser, bool awaitIsKeyword) {
+ parser_ = parser;
+ oldAwaitIsKeyword_ = parser_->awaitIsKeyword_;
+ parser_->setAwaitIsKeyword(awaitIsKeyword);
+ }
+
+ ~AutoAwaitIsKeyword() {
+ parser_->setAwaitIsKeyword(oldAwaitIsKeyword_);
+ }
};
} /* namespace frontend */