From 17de77bbc1f300573ab13cad2e1a210097539ca4 Mon Sep 17 00:00:00 2001 From: Ted Campbell Date: Wed, 7 Oct 2020 22:20:15 +0000 Subject: [PATCH] Bug 1669847 - Make ScopeStencil instantiation const. r=arai Depends on D92827 Differential Revision: https://phabricator.services.mozilla.com/D92828 --- js/src/frontend/Stencil.cpp | 7 ++++--- js/src/frontend/Stencil.h | 10 +++++----- js/src/vm/Scope.cpp | 24 ++++++++++++------------ 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/js/src/frontend/Stencil.cpp b/js/src/frontend/Stencil.cpp index b4bfab83d8f6..7bd354f6eeeb 100644 --- a/js/src/frontend/Stencil.cpp +++ b/js/src/frontend/Stencil.cpp @@ -37,7 +37,8 @@ using namespace js; using namespace js::frontend; -AbstractScopePtr ScopeStencil::enclosing(CompilationInfo& compilationInfo) { +AbstractScopePtr ScopeStencil::enclosing( + CompilationInfo& compilationInfo) const { if (enclosing_) { return AbstractScopePtr(compilationInfo, *enclosing_); } @@ -47,7 +48,7 @@ AbstractScopePtr ScopeStencil::enclosing(CompilationInfo& compilationInfo) { Scope* ScopeStencil::createScope(JSContext* cx, CompilationInfo& compilationInfo, - CompilationGCOutput& gcOutput) { + CompilationGCOutput& gcOutput) const { Scope* scope = nullptr; switch (kind()) { case ScopeKind::Function: { @@ -310,7 +311,7 @@ static bool InstantiateScopes(JSContext* cx, CompilationInfo& compilationInfo, return false; } - for (auto& scd : compilationInfo.stencil.scopeData) { + for (const ScopeStencil& scd : compilationInfo.stencil.scopeData) { Scope* scope = scd.createScope(cx, compilationInfo, gcOutput); if (!scope) { return false; diff --git a/js/src/frontend/Stencil.h b/js/src/frontend/Stencil.h index 5e628592e1d4..3939425033de 100644 --- a/js/src/frontend/Stencil.h +++ b/js/src/frontend/Stencil.h @@ -244,7 +244,7 @@ class ScopeStencil { mozilla::Maybe enclosing, ScopeIndex* index); - AbstractScopePtr enclosing(CompilationInfo& compilationInfo); + AbstractScopePtr enclosing(CompilationInfo& compilationInfo) const; ScopeKind kind() const { return kind_; } @@ -258,7 +258,7 @@ class ScopeStencil { bool isArrow() const { return isArrow_; } Scope* createScope(JSContext* cx, CompilationInfo& compilationInfo, - CompilationGCOutput& gcOutput); + CompilationGCOutput& gcOutput) const; uint32_t nextFrameSlot() const; @@ -284,7 +284,7 @@ class ScopeStencil { template UniquePtr createSpecificScopeData( JSContext* cx, CompilationInfo& compilationInfo, - CompilationGCOutput& gcOutput); + CompilationGCOutput& gcOutput) const; template uint32_t nextFrameSlot() const { @@ -296,11 +296,11 @@ class ScopeStencil { template MOZ_MUST_USE bool createSpecificShape(JSContext* cx, ScopeKind kind, BaseScopeData* scopeData, - MutableHandleShape shape); + MutableHandleShape shape) const; template Scope* createSpecificScope(JSContext* cx, CompilationInfo& compilationInfo, - CompilationGCOutput& gcOutput); + CompilationGCOutput& gcOutput) const; }; // As an alternative to a ScopeIndex (which references a ScopeStencil), we may diff --git a/js/src/vm/Scope.cpp b/js/src/vm/Scope.cpp index 2911bffd44fd..43dd5a4a1baf 100644 --- a/js/src/vm/Scope.cpp +++ b/js/src/vm/Scope.cpp @@ -2164,7 +2164,7 @@ bool ScopeStencil::createForModuleScope(JSContext* cx, template bool ScopeStencil::createSpecificShape(JSContext* cx, ScopeKind kind, BaseScopeData* scopeData, - MutableHandleShape shape) { + MutableHandleShape shape) const { const JSClass* cls = &SpecificEnvironmentT::class_; uint32_t baseShapeFlags = SpecificEnvironmentT::BASESHAPE_FLAGS; @@ -2203,7 +2203,7 @@ bool ScopeStencil::createForWithScope(JSContext* cx, template UniquePtr ScopeStencil::createSpecificScopeData( JSContext* cx, CompilationInfo& compilationInfo, - CompilationGCOutput& gcOutput) { + CompilationGCOutput& gcOutput) const { return LiftParserScopeData(cx, compilationInfo, &data()); } @@ -2212,7 +2212,7 @@ template <> UniquePtr ScopeStencil::createSpecificScopeData( JSContext* cx, CompilationInfo& compilationInfo, - CompilationGCOutput& gcOutput) { + CompilationGCOutput& gcOutput) const { // Allocate a new vm function-scope. UniquePtr data = LiftParserScopeData( cx, compilationInfo, &this->data()); @@ -2229,7 +2229,7 @@ ScopeStencil::createSpecificScopeData( template <> UniquePtr ScopeStencil::createSpecificScopeData( JSContext* cx, CompilationInfo& compilationInfo, - CompilationGCOutput& gcOutput) { + CompilationGCOutput& gcOutput) const { // Allocate a new vm module-scope. UniquePtr data = LiftParserScopeData( cx, compilationInfo, &this->data()); @@ -2247,7 +2247,7 @@ UniquePtr ScopeStencil::createSpecificScopeData( template <> Scope* ScopeStencil::createSpecificScope( JSContext* cx, CompilationInfo& compilationInfo, - CompilationGCOutput& gcOutput) { + CompilationGCOutput& gcOutput) const { RootedScope enclosingScope( cx, enclosing(compilationInfo).existingScope(gcOutput)); return Scope::create(cx, ScopeKind::With, enclosingScope, nullptr); @@ -2257,7 +2257,7 @@ Scope* ScopeStencil::createSpecificScope( template <> Scope* ScopeStencil::createSpecificScope( JSContext* cx, CompilationInfo& compilationInfo, - CompilationGCOutput& gcOutput) { + CompilationGCOutput& gcOutput) const { Rooted> rootedData( cx, createSpecificScopeData(cx, compilationInfo, gcOutput)); if (!rootedData) { @@ -2273,7 +2273,7 @@ Scope* ScopeStencil::createSpecificScope( template Scope* ScopeStencil::createSpecificScope(JSContext* cx, CompilationInfo& compilationInfo, - CompilationGCOutput& gcOutput) { + CompilationGCOutput& gcOutput) const { Rooted> rootedData( cx, createSpecificScopeData(cx, compilationInfo, gcOutput)); @@ -2297,20 +2297,20 @@ Scope* ScopeStencil::createSpecificScope(JSContext* cx, template Scope* ScopeStencil::createSpecificScope( JSContext* cx, CompilationInfo& compilationInfo, - CompilationGCOutput& gcOutput); + CompilationGCOutput& gcOutput) const; template Scope* ScopeStencil::createSpecificScope( JSContext* cx, CompilationInfo& compilationInfo, - CompilationGCOutput& gcOutput); + CompilationGCOutput& gcOutput) const; template Scope* ScopeStencil::createSpecificScope( JSContext* cx, CompilationInfo& compilationInfo, - CompilationGCOutput& gcOutput); + CompilationGCOutput& gcOutput) const; template Scope* ScopeStencil::createSpecificScope( JSContext* cx, CompilationInfo& compilationInfo, - CompilationGCOutput& gcOutput); + CompilationGCOutput& gcOutput) const; template Scope* ScopeStencil::createSpecificScope( JSContext* cx, CompilationInfo& compilationInfo, - CompilationGCOutput& gcOutput); + CompilationGCOutput& gcOutput) const;