From 8c3bcd64f242a65339851f2d108210602c341439 Mon Sep 17 00:00:00 2001 From: Jeff Walden Date: Sun, 12 May 2019 01:38:24 +0000 Subject: [PATCH] Bug 1550616 - Make FunctionBox::setEnd take the actual uint32_t end, not TokenStreamAnyChars&, and add ParserBase::setFunctionEndFromCurrentToken that calls it passing the correct value, to eliminate another SharedContext.h dependency on... r=tcampbell ...TokenStream.h. r=tcampbell Depends on D30574 Differential Revision: https://phabricator.services.mozilla.com/D30575 --HG-- extra : moz-landing-system : lando --- js/src/frontend/Parser.cpp | 12 ++++++++---- js/src/frontend/Parser.h | 3 +++ js/src/frontend/SharedContext.h | 6 ++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp index 22edacc244e1..e0606b1a7df1 100644 --- a/js/src/frontend/Parser.cpp +++ b/js/src/frontend/Parser.cpp @@ -2912,6 +2912,10 @@ FunctionNode* Parser::standaloneLazyFunction( return funNode; } +void ParserBase::setFunctionEndFromCurrentToken(FunctionBox* funbox) const { + funbox->setEnd(anyChars.currentToken().pos.end); +} + template bool GeneralParser::functionFormalParametersAndBody( InHandling inHandling, YieldHandling yieldHandling, @@ -3052,7 +3056,7 @@ bool GeneralParser::functionFormalParametersAndBody( return false; } - funbox->setEnd(anyChars); + setFunctionEndFromCurrentToken(funbox); } else { MOZ_ASSERT(kind == FunctionSyntaxKind::Arrow); @@ -3060,7 +3064,7 @@ bool GeneralParser::functionFormalParametersAndBody( return false; } - funbox->setEnd(anyChars); + setFunctionEndFromCurrentToken(funbox); if (kind == FunctionSyntaxKind::Statement) { if (!matchOrInsertSemicolon()) { @@ -7161,7 +7165,7 @@ GeneralParser::synthesizeConstructor( } funbox->initWithEnclosingParseContext(pc_, functionSyntaxKind); handler_.setFunctionBox(funNode, funbox); - funbox->setEnd(anyChars); + setFunctionEndFromCurrentToken(funbox); // Push a SourceParseContext on to the stack. SourceParseContext funpc(this, funbox, /* newDirectives = */ nullptr); @@ -7352,7 +7356,7 @@ GeneralParser::fieldInitializerOpt( // Update the end position of the parse node. handler_.setEndPosition(funNode, wholeInitializerPos.end); - funbox->setEnd(anyChars); + setFunctionEndFromCurrentToken(funbox); // Create a ListNode for the parameters + body (there are no parameters). ListNodeType argsbody = diff --git a/js/src/frontend/Parser.h b/js/src/frontend/Parser.h index d6a6105e7447..21fed2a5e0a9 100644 --- a/js/src/frontend/Parser.h +++ b/js/src/frontend/Parser.h @@ -457,6 +457,8 @@ class MOZ_STACK_CLASS ParserBase : public ParserSharedBase, JSAtom* prefixAccessorName(PropertyType propType, HandleAtom propAtom); MOZ_MUST_USE bool setSourceMapInfo(); + + void setFunctionEndFromCurrentToken(FunctionBox* funbox) const; }; enum FunctionCallBehavior { @@ -824,6 +826,7 @@ class MOZ_STACK_CLASS GeneralParser : public PerHandlerParser { using Base::prefixAccessorName; using Base::processExport; using Base::processExportFrom; + using Base::setFunctionEndFromCurrentToken; private: inline FinalParser* asFinalParser(); diff --git a/js/src/frontend/SharedContext.h b/js/src/frontend/SharedContext.h index 55ca96924fee..c08b4cd9e353 100644 --- a/js/src/frontend/SharedContext.h +++ b/js/src/frontend/SharedContext.h @@ -555,13 +555,11 @@ class FunctionBox : public ObjectBox, public SharedContext { startColumn = column; } - void setEnd(const TokenStreamAnyChars& anyChars) { + void setEnd(uint32_t end) { // For all functions except class constructors, the buffer and // toString ending positions are the same. Class constructors override // the toString ending position with the end of the class definition. - uint32_t offset = anyChars.currentToken().pos.end; - bufEnd = offset; - toStringEnd = offset; + bufEnd = toStringEnd = end; } void trace(JSTracer* trc) override;