From 11cbc0243527e9e585d120d00967f62a2cf888a4 Mon Sep 17 00:00:00 2001 From: caroline Date: Wed, 29 Apr 2020 02:20:24 +0000 Subject: [PATCH] Bug 1627358 - Make SharedContext::Kind be defined but SharedContext::ImmutableFlags. r=tcampbell Differential Revision: https://phabricator.services.mozilla.com/D72892 --- js/src/frontend/SharedContext.cpp | 9 ++++----- js/src/frontend/SharedContext.h | 30 ++++++++++++++++-------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/js/src/frontend/SharedContext.cpp b/js/src/frontend/SharedContext.cpp index 5ee4a7c7f5c7..83e16b6fb61d 100644 --- a/js/src/frontend/SharedContext.cpp +++ b/js/src/frontend/SharedContext.cpp @@ -24,7 +24,6 @@ SharedContext::SharedContext(JSContext* cx, Kind kind, Directives directives, SourceExtent extent, ImmutableScriptFlags immutableFlags) : cx_(cx), - kind_(kind), compilationInfo_(compilationInfo), thisBinding_(ThisBinding::Global), extent(extent), @@ -37,15 +36,15 @@ SharedContext::SharedContext(JSContext* cx, Kind kind, localStrict(false), hasExplicitUseStrict_(false), immutableFlags_(immutableFlags) { - if (kind_ == Kind::FunctionBox) { + if (kind == Kind::FunctionBox) { immutableFlags_.setFlag(ImmutableFlags::IsFunction); - } else if (kind_ == Kind::Module) { + } else if (kind == Kind::Module) { MOZ_ASSERT(!compilationInfo.options.nonSyntacticScope); immutableFlags_.setFlag(ImmutableFlags::IsModule); - } else if (kind_ == Kind::Eval) { + } else if (kind == Kind::Eval) { immutableFlags_.setFlag(ImmutableFlags::IsForEval); } else { - MOZ_ASSERT(kind_ == Kind::Global); + MOZ_ASSERT(kind == Kind::Global); } immutableFlags_.setFlag(ImmutableFlags::Strict, directives.strict()); diff --git a/js/src/frontend/SharedContext.h b/js/src/frontend/SharedContext.h index 2f4ff63e3634..79224b228c0d 100644 --- a/js/src/frontend/SharedContext.h +++ b/js/src/frontend/SharedContext.h @@ -110,8 +110,6 @@ class SharedContext { protected: enum class Kind : uint8_t { FunctionBox, Global, Eval, Module }; - Kind kind_; - CompilationInfo& compilationInfo_; ThisBinding thisBinding_; @@ -156,25 +154,29 @@ class SharedContext { // it. Otherwise nullptr. virtual Scope* compilationEnclosingScope() const = 0; - bool isFunctionBox() const { return kind_ == Kind::FunctionBox; } + bool isFunctionBox() const { + return immutableFlags_.hasFlag(ImmutableFlags::IsFunction); + } inline FunctionBox* asFunctionBox(); - bool isModuleContext() const { return kind_ == Kind::Module; } + bool isModuleContext() const { + return immutableFlags_.hasFlag(ImmutableFlags::IsModule); + } inline ModuleSharedContext* asModuleContext(); - bool isGlobalContext() const { return kind_ == Kind::Global; } + bool isGlobalContext() const { + return !(isFunctionBox() || isModuleContext() || isEvalContext()); + } inline GlobalSharedContext* asGlobalContext(); - bool isEvalContext() const { return kind_ == Kind::Eval; } + bool isEvalContext() const { + return immutableFlags_.hasFlag(ImmutableFlags::IsForEval); + } inline EvalSharedContext* asEvalContext(); bool isTopLevelContext() const { - switch (kind_) { - case Kind::Module: - case Kind::Global: - case Kind::Eval: - return true; - case Kind::FunctionBox: - break; + if (isModuleContext() || isEvalContext() || isGlobalContext()) { + return true; } - MOZ_ASSERT(kind_ == Kind::FunctionBox); + + MOZ_ASSERT(isFunctionBox()); return false; }