Bug 1466121 part 1 - Rename JSCompartment to JS::Compartment. r=luke
authorJan de Mooij <jdemooij@mozilla.com>
Thu, 07 Jun 2018 16:44:40 +0200
changeset 476028 b640dc9b89986c1886ef00402727da756d96f0ef
parent 476027 7ce486eac26634b275273540e596ebbac4c3da30
child 476029 e3b458961e04bf00b4eff6aa08ec2ad6d6ee13e4
push id9374
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:43:20 +0000
treeherdermozilla-beta@160e085dfb0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1466121
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1466121 part 1 - Rename JSCompartment to JS::Compartment. r=luke
devtools/shared/heapsnapshot/HeapSnapshot.cpp
devtools/shared/heapsnapshot/tests/gtest/DevTools.h
devtools/shared/heapsnapshot/tests/gtest/DoesCrossCompartmentBoundaries.cpp
devtools/shared/heapsnapshot/tests/gtest/DoesntCrossCompartmentBoundaries.cpp
dom/base/WindowDestroyedEvent.cpp
dom/base/nsContentUtils.cpp
dom/bindings/BindingUtils.cpp
dom/bindings/Codegen.py
dom/console/Console.h
dom/events/DOMEventTargetHelper.h
dom/media/webrtc/RTCCertificate.cpp
dom/media/webrtc/RTCCertificate.h
dom/promise/Promise.cpp
dom/promise/Promise.h
js/public/GCAPI.h
js/public/Realm.h
js/public/RootingAPI.h
js/public/TracingAPI.h
js/public/TypeDecls.h
js/public/UbiNode.h
js/rust/build.rs
js/rust/src/rust.rs
js/src/NamespaceImports.h
js/src/fuzz-tests/tests.cpp
js/src/gc/Cell.h
js/src/gc/GC.cpp
js/src/gc/GCRuntime.h
js/src/gc/PublicIterators.cpp
js/src/gc/PublicIterators.h
js/src/gc/RootMarking.cpp
js/src/gc/Tracer.cpp
js/src/gc/Zone.cpp
js/src/gc/Zone.h
js/src/jit-test/tests/debug/bug-876654.js
js/src/jit/CacheIR.h
js/src/jit/CacheIRCompiler.h
js/src/jit/IonCacheIRCompiler.cpp
js/src/jit/MacroAssembler.cpp
js/src/jit/MacroAssembler.h
js/src/jit/VMFunctions.cpp
js/src/jsapi-tests/testGCMarking.cpp
js/src/jsapi.cpp
js/src/jsapi.h
js/src/jsfriendapi.cpp
js/src/jsfriendapi.h
js/src/jspubtd.h
js/src/proxy/CrossCompartmentWrapper.cpp
js/src/vm/Debugger.cpp
js/src/vm/Debugger.h
js/src/vm/Iteration.cpp
js/src/vm/Iteration.h
js/src/vm/JSCompartment-inl.h
js/src/vm/JSCompartment.cpp
js/src/vm/JSCompartment.h
js/src/vm/JSContext-inl.h
js/src/vm/JSContext.h
js/src/vm/JSFunction.cpp
js/src/vm/JSFunction.h
js/src/vm/JSObject.h
js/src/vm/JSScript.h
js/src/vm/ObjectGroup.h
js/src/vm/Runtime.h
js/src/vm/Stack.cpp
js/src/vm/Stack.h
js/src/vm/Stopwatch.cpp
js/src/vm/Stopwatch.h
js/src/vm/TypeInference-inl.h
js/src/vm/TypeInference.cpp
js/src/vm/TypeInference.h
js/src/vm/UbiNode.cpp
js/src/wasm/WasmProcess.cpp
js/xpconnect/src/XPCComponents.cpp
js/xpconnect/src/XPCJSRuntime.cpp
js/xpconnect/src/XPCWrappedJS.cpp
js/xpconnect/src/XPCWrappedNativeScope.cpp
js/xpconnect/src/nsXPConnect.cpp
js/xpconnect/src/xpcprivate.h
js/xpconnect/src/xpcpublic.h
js/xpconnect/wrappers/AccessCheck.cpp
js/xpconnect/wrappers/AccessCheck.h
js/xpconnect/wrappers/WrapperFactory.cpp
js/xpconnect/wrappers/WrapperFactory.h
toolkit/components/perfmonitoring/nsPerformanceStats.h
--- a/devtools/shared/heapsnapshot/HeapSnapshot.cpp
+++ b/devtools/shared/heapsnapshot/HeapSnapshot.cpp
@@ -1064,17 +1064,17 @@ ShouldIncludeEdge(JS::CompartmentSet* co
   //
   // If the node does not belong to any compartment, we also serialize its outgoing
   // edges. This case is relevant for Shapes: they don't belong to a specific
   // compartment and contain edges to parent/kids Shapes we want to include. Note
   // that these Shapes may contain pointers into our target compartment (the
   // Shape's getter/setter JSObjects). However, we do not serialize nodes in other
   // compartments that are reachable from these non-compartment nodes.
 
-  JSCompartment* compartment = edge.referent.compartment();
+  JS::Compartment* compartment = edge.referent.compartment();
 
   if (!compartment || compartments->has(compartment)) {
     return true;
   }
 
   if (policy) {
     *policy = CoreDumpWriter::EXCLUDE_EDGES;
   }
--- a/devtools/shared/heapsnapshot/tests/gtest/DevTools.h
+++ b/devtools/shared/heapsnapshot/tests/gtest/DevTools.h
@@ -25,17 +25,17 @@ using namespace mozilla;
 using namespace mozilla::devtools;
 using namespace mozilla::dom;
 using namespace testing;
 
 // GTest fixture class that all of our tests derive from.
 struct DevTools : public ::testing::Test {
   bool                       _initialized;
   JSContext*                 cx;
-  JSCompartment*             compartment;
+  JS::Compartment*           compartment;
   JS::Zone*                  zone;
   JS::PersistentRootedObject global;
 
   DevTools()
     : _initialized(false),
       cx(nullptr)
   { }
 
@@ -125,17 +125,17 @@ struct DevTools : public ::testing::Test
   }
 
 
 // Fake JS::ubi::Node implementation
 class MOZ_STACK_CLASS FakeNode
 {
 public:
   JS::ubi::EdgeVector edges;
-  JSCompartment*      compartment;
+  JS::Compartment*    compartment;
   JS::Zone*           zone;
   size_t              size;
 
   explicit FakeNode()
     : edges(),
     compartment(nullptr),
     zone(nullptr),
     size(1)
@@ -159,17 +159,17 @@ class Concrete<FakeNode> : public Base
   Size size(mozilla::MallocSizeOf) const override {
     return get().size;
   }
 
   JS::Zone* zone() const override {
     return get().zone;
   }
 
-  JSCompartment* compartment() const override {
+  JS::Compartment* compartment() const override {
     return get().compartment;
   }
 
 protected:
   explicit Concrete(FakeNode* ptr) : Base(ptr) { }
   FakeNode& get() const { return *static_cast<FakeNode*>(ptr); }
 
 public:
--- a/devtools/shared/heapsnapshot/tests/gtest/DoesCrossCompartmentBoundaries.cpp
+++ b/devtools/shared/heapsnapshot/tests/gtest/DoesCrossCompartmentBoundaries.cpp
@@ -11,17 +11,17 @@ DEF_TEST(DoesCrossCompartmentBoundaries,
     // Create a new global to get a new compartment.
     JS::RealmOptions options;
     JS::RootedObject newGlobal(cx, JS_NewGlobalObject(cx,
                                                       getGlobalClass(),
                                                       nullptr,
                                                       JS::FireOnNewGlobalHook,
                                                       options));
     ASSERT_TRUE(newGlobal);
-    JSCompartment* newCompartment = nullptr;
+    JS::Compartment* newCompartment = nullptr;
     {
       JSAutoRealm ar(cx, newGlobal);
       ASSERT_TRUE(JS_InitStandardClasses(cx, newGlobal));
       newCompartment = js::GetContextCompartment(cx);
     }
     ASSERT_TRUE(newCompartment);
     ASSERT_NE(newCompartment, compartment);
 
--- a/devtools/shared/heapsnapshot/tests/gtest/DoesntCrossCompartmentBoundaries.cpp
+++ b/devtools/shared/heapsnapshot/tests/gtest/DoesntCrossCompartmentBoundaries.cpp
@@ -11,17 +11,17 @@ DEF_TEST(DoesntCrossCompartmentBoundarie
     // Create a new global to get a new compartment.
     JS::RealmOptions options;
     JS::RootedObject newGlobal(cx, JS_NewGlobalObject(cx,
                                                       getGlobalClass(),
                                                       nullptr,
                                                       JS::FireOnNewGlobalHook,
                                                       options));
     ASSERT_TRUE(newGlobal);
-    JSCompartment* newCompartment = nullptr;
+    JS::Compartment* newCompartment = nullptr;
     {
       JSAutoRealm ar(cx, newGlobal);
       ASSERT_TRUE(JS_InitStandardClasses(cx, newGlobal));
       newCompartment = js::GetContextCompartment(cx);
     }
     ASSERT_TRUE(newCompartment);
     ASSERT_NE(newCompartment, compartment);
 
--- a/dom/base/WindowDestroyedEvent.cpp
+++ b/dom/base/WindowDestroyedEvent.cpp
@@ -10,17 +10,17 @@
 #include "nsCOMPtr.h"
 
 namespace mozilla {
 
 // Try to match compartments that are not web content by matching compartments
 // with principals that are either the system principal or an expanded principal.
 // This may not return true for all non-web-content compartments.
 struct BrowserCompartmentMatcher : public js::CompartmentFilter {
-  bool match(JSCompartment* aC) const override
+  bool match(JS::Compartment* aC) const override
   {
     nsCOMPtr<nsIPrincipal> pc = nsJSPrincipals::get(JS_GetCompartmentPrincipals(aC));
     return nsContentUtils::IsSystemOrExpandedPrincipal(pc);
   }
 };
 
 WindowDestroyedEvent::WindowDestroyedEvent(nsGlobalWindowInner* aWindow,
                                            uint64_t aID, const char* aTopic)
@@ -106,17 +106,17 @@ WindowDestroyedEvent::Run()
           nsGlobalWindowOuter* outer = nsGlobalWindowOuter::FromSupports(window);
           currentInner = outer->GetCurrentInnerWindowInternal();
         }
         NS_ENSURE_TRUE(currentInner, NS_OK);
 
         AutoSafeJSContext cx;
         JS::Rooted<JSObject*> obj(cx, currentInner->FastGetGlobalJSObject());
         if (obj && !js::IsSystemRealm(js::GetNonCCWObjectRealm(obj))) {
-          JSCompartment* cpt = js::GetObjectCompartment(obj);
+          JS::Compartment* cpt = js::GetObjectCompartment(obj);
           nsCOMPtr<nsIPrincipal> pc = nsJSPrincipals::get(JS_GetCompartmentPrincipals(cpt));
 
           if (BasePrincipal::Cast(pc)->AddonPolicy()) {
             // We want to nuke all references to the add-on compartment.
             xpc::NukeAllWrappersForCompartment(cx, cpt,
                                                mIsInnerWindow ? js::DontNukeWindowReferences
                                                               : js::NukeWindowReferences);
           } else {
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -3141,18 +3141,18 @@ nsContentUtils::ObjectPrincipal(JSObject
   MOZ_ASSERT(NS_IsMainThread());
 
 #ifdef DEBUG
   JS::AssertObjectBelongsToCurrentThread(aObj);
 #endif
 
   // This is duplicated from nsScriptSecurityManager. We don't call through there
   // because the API unnecessarily requires a JSContext for historical reasons.
-  JSCompartment *compartment = js::GetObjectCompartment(aObj);
-  JSPrincipals *principals = JS_GetCompartmentPrincipals(compartment);
+  JS::Compartment* compartment = js::GetObjectCompartment(aObj);
+  JSPrincipals* principals = JS_GetCompartmentPrincipals(compartment);
   return nsJSPrincipals::get(principals);
 }
 
 // static
 nsresult
 nsContentUtils::NewURIWithDocumentCharset(nsIURI** aResult,
                                           const nsAString& aSpec,
                                           nsIDocument* aDocument,
--- a/dom/bindings/BindingUtils.cpp
+++ b/dom/bindings/BindingUtils.cpp
@@ -2276,18 +2276,18 @@ ReparentWrapper(JSContext* aCx, JS::Hand
   MOZ_ASSERT(js::GetGlobalForObjectCrossCompartment(oldParent) == oldParent);
 
   JS::Rooted<JSObject*> newParent(aCx,
                                   domClass->mGetAssociatedGlobal(aCx, aObj));
   MOZ_ASSERT(JS_IsGlobalObject(newParent));
 
   JSAutoRealm oldAr(aCx, oldParent);
 
-  JSCompartment* oldCompartment = js::GetObjectCompartment(oldParent);
-  JSCompartment* newCompartment = js::GetObjectCompartment(newParent);
+  JS::Compartment* oldCompartment = js::GetObjectCompartment(oldParent);
+  JS::Compartment* newCompartment = js::GetObjectCompartment(newParent);
   if (oldCompartment == newCompartment) {
     MOZ_ASSERT(oldParent == newParent);
     return;
   }
 
   nsISupports* native = UnwrapDOMObjectToISupports(aObj);
   if (!native) {
     return;
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -15045,17 +15045,17 @@ class CGJSImplMethod(CGJSImplMember):
                                 signature,
                                 descriptor.getExtendedAttributes(method),
                                 breakAfter=breakAfter,
                                 variadicIsSequence=True,
                                 passJSBitsAsNeeded=False)
 
     def getArgs(self, returnType, argList):
         if self.isConstructor:
-            # Skip the JSCompartment bits for constructors; it's handled
+            # Skip the JS::Compartment bits for constructors; it's handled
             # manually in getImpl.  But we do need our aGivenProto argument.  We
             # allow it to be omitted if the default proto is desired.
             return (CGNativeMember.getArgs(self, returnType, argList) +
                     [Argument("JS::Handle<JSObject*>", "aGivenProto", "nullptr")])
         return CGJSImplMember.getArgs(self, returnType, argList)
 
     def getImpl(self):
         args = self.getArgs(self.signature[0], self.signature[1])
--- a/dom/console/Console.h
+++ b/dom/console/Console.h
@@ -205,17 +205,17 @@ private:
                const Sequence<JS::Value>& aData, MethodName aMethodName,
                const nsAString& aMethodString);
 
   void
   StringMethodInternal(JSContext* aCx, const nsAString& aLabel,
                        const Sequence<JS::Value>& aData,
                        MethodName aMethodName, const nsAString& aMethodString);
 
-  // This method must receive aCx and aArguments in the same JSCompartment.
+  // This method must receive aCx and aArguments in the same JS::Compartment.
   void
   ProcessCallData(JSContext* aCx,
                   ConsoleCallData* aData,
                   const Sequence<JS::Value>& aArguments);
 
   void
   StoreCallData(ConsoleCallData* aData);
 
--- a/dom/events/DOMEventTargetHelper.h
+++ b/dom/events/DOMEventTargetHelper.h
@@ -15,17 +15,16 @@
 #include "nsIScriptContext.h"
 #include "nsIWeakReferenceUtils.h"
 #include "MainThreadUtils.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/EventListenerManager.h"
 #include "mozilla/LinkedList.h"
 #include "mozilla/dom/EventTarget.h"
 
-struct JSCompartment;
 class nsIDocument;
 
 namespace mozilla {
 
 class ErrorResult;
 
 namespace dom {
 class Event;
--- a/dom/media/webrtc/RTCCertificate.cpp
+++ b/dom/media/webrtc/RTCCertificate.cpp
@@ -255,17 +255,17 @@ ReadExpires(JSContext* aCx, const Object
     return EXPIRATION_MAX;
   }
   return static_cast<PRTime>(expiration.mExpires.Value() * PR_USEC_PER_MSEC);
 }
 
 already_AddRefed<Promise>
 RTCCertificate::GenerateCertificate(
     const GlobalObject& aGlobal, const ObjectOrString& aOptions,
-    ErrorResult& aRv, JSCompartment* aCompartment)
+    ErrorResult& aRv, JS::Compartment* aCompartment)
 {
   nsIGlobalObject* global = xpc::NativeGlobal(aGlobal.Get());
   RefPtr<Promise> p = Promise::Create(global, aRv);
   if (aRv.Failed()) {
     return nullptr;
   }
   Sequence<nsString> usages;
   if (!usages.AppendElement(NS_LITERAL_STRING("sign"), fallible)) {
--- a/dom/media/webrtc/RTCCertificate.h
+++ b/dom/media/webrtc/RTCCertificate.h
@@ -33,17 +33,17 @@ class RTCCertificate final : public nsIS
 {
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(RTCCertificate)
 
   // WebIDL method that implements RTCPeerConnection.generateCertificate.
   static already_AddRefed<Promise> GenerateCertificate(
       const GlobalObject& aGlobal, const ObjectOrString& aOptions,
-      ErrorResult& aRv, JSCompartment* aCompartment = nullptr);
+      ErrorResult& aRv, JS::Compartment* aCompartment = nullptr);
 
   explicit RTCCertificate(nsIGlobalObject* aGlobal);
   RTCCertificate(nsIGlobalObject* aGlobal, SECKEYPrivateKey* aPrivateKey,
                  CERTCertificate* aCertificate, SSLKEAType aAuthType,
                  PRTime aExpires);
 
   nsIGlobalObject* GetParentObject() const { return mGlobal; }
   virtual JSObject* WrapObject(JSContext* aCx,
--- a/dom/promise/Promise.cpp
+++ b/dom/promise/Promise.cpp
@@ -515,17 +515,17 @@ Promise::ReportRejectedPromise(JSContext
 }
 
 JSObject*
 Promise::GlobalJSObject() const
 {
   return mGlobal->GetGlobalJSObject();
 }
 
-JSCompartment*
+JS::Compartment*
 Promise::Compartment() const
 {
   return js::GetObjectCompartment(GlobalJSObject());
 }
 
 // A WorkerRunnable to resolve/reject the Promise on the worker thread.
 // Calling thread MUST hold PromiseWorkerProxy's mutex before creating this.
 class PromiseWorkerProxyRunnable : public WorkerRunnable
--- a/dom/promise/Promise.h
+++ b/dom/promise/Promise.h
@@ -145,17 +145,17 @@ public:
   {
     return mPromiseObj;
   }
 
   void AppendNativeHandler(PromiseNativeHandler* aRunnable);
 
   JSObject* GlobalJSObject() const;
 
-  JSCompartment* Compartment() const;
+  JS::Compartment* Compartment() const;
 
   // Create a dom::Promise from a given SpiderMonkey Promise object.
   // aPromiseObj MUST be in the compartment of aGlobal's global JS object.
   static already_AddRefed<Promise>
   CreateFromExisting(nsIGlobalObject* aGlobal,
                      JS::Handle<JSObject*> aPromiseObj);
 
   enum class PromiseState {
--- a/js/public/GCAPI.h
+++ b/js/public/GCAPI.h
@@ -314,17 +314,17 @@ typedef enum JSFinalizeStatus {
 
 typedef void
 (* JSFinalizeCallback)(JSFreeOp* fop, JSFinalizeStatus status, void* data);
 
 typedef void
 (* JSWeakPointerZonesCallback)(JSContext* cx, void* data);
 
 typedef void
-(* JSWeakPointerCompartmentCallback)(JSContext* cx, JSCompartment* comp, void* data);
+(* JSWeakPointerCompartmentCallback)(JSContext* cx, JS::Compartment* comp, void* data);
 
 /**
  * Finalizes external strings created by JS_NewExternalString. The finalizer
  * can be called off the main thread.
  */
 struct JSStringFinalizer {
     void (*finalize)(const JSStringFinalizer* fin, char16_t* chars);
 };
--- a/js/public/Realm.h
+++ b/js/public/Realm.h
@@ -44,35 +44,35 @@ struct GCPolicy<Realm*> : public NonGCPo
 extern JS_PUBLIC_API(Realm*)
 GetCurrentRealmOrNull(JSContext* cx);
 
 namespace shadow {
 
 class Realm
 {
   protected:
-    JSCompartment* compartment_;
+    JS::Compartment* compartment_;
 
-    explicit Realm(JSCompartment* comp)
+    explicit Realm(JS::Compartment* comp)
       : compartment_(comp)
     {}
 
   public:
-    JSCompartment* compartment() {
+    JS::Compartment* compartment() {
         return compartment_;
     }
     static shadow::Realm* get(JS::Realm* realm) {
         return reinterpret_cast<shadow::Realm*>(realm);
     }
 };
 
 }; // namespace shadow
 
 // Return the compartment that contains a given realm.
-inline JSCompartment*
+inline JS::Compartment*
 GetCompartmentForRealm(Realm* realm)
 {
     return shadow::Realm::get(realm)->compartment();
 }
 
 // Return an object's realm. All objects except cross-compartment wrappers are
 // created in a particular realm, which never changes. Returns null if obj is
 // a cross-compartment wrapper.
--- a/js/public/RootingAPI.h
+++ b/js/public/RootingAPI.h
@@ -1055,17 +1055,17 @@ namespace js {
  *   incomplete type.
  */
 inline JS::Realm*
 GetContextRealm(const JSContext* cx)
 {
     return JS::RootingContext::get(cx)->realm_;
 }
 
-inline JSCompartment*
+inline JS::Compartment*
 GetContextCompartment(const JSContext* cx)
 {
     if (JS::Realm* realm = GetContextRealm(cx))
         return GetCompartmentForRealm(realm);
     return nullptr;
 }
 
 inline JS::Zone*
--- a/js/public/TracingAPI.h
+++ b/js/public/TracingAPI.h
@@ -409,17 +409,17 @@ TraceEdge(JSTracer* trc, JS::TenuredHeap
 template <typename T>
 extern JS_PUBLIC_API(void)
 UnsafeTraceRoot(JSTracer* trc, T* edgep, const char* name);
 
 extern JS_PUBLIC_API(void)
 TraceChildren(JSTracer* trc, GCCellPtr thing);
 
 using ZoneSet = js::HashSet<Zone*, js::DefaultHasher<Zone*>, js::SystemAllocPolicy>;
-using CompartmentSet = js::HashSet<JSCompartment*, js::DefaultHasher<JSCompartment*>,
+using CompartmentSet = js::HashSet<JS::Compartment*, js::DefaultHasher<JS::Compartment*>,
                                    js::SystemAllocPolicy>;
 
 /**
  * Trace every value within |compartments| that is wrapped by a
  * cross-compartment wrapper from a compartment that is not an element of
  * |compartments|.
  */
 extern JS_PUBLIC_API(void)
--- a/js/public/TypeDecls.h
+++ b/js/public/TypeDecls.h
@@ -20,17 +20,16 @@
 #include <stddef.h>
 #include <stdint.h>
 
 #include "js-config.h"
 
 typedef uint8_t jsbytecode;
 
 class JSAtom;
-struct JSCompartment;
 struct JSContext;
 class JSFunction;
 class JSObject;
 struct JSRuntime;
 class JSScript;
 class JSString;
 struct JSFreeOp;
 
@@ -40,16 +39,18 @@ namespace JS {
 
 typedef unsigned char Latin1Char;
 
 class Symbol;
 #ifdef ENABLE_BIGINT
 class BigInt;
 #endif
 union Value;
+
+struct Compartment;
 class Realm;
 struct Runtime;
 struct Zone;
 
 template <typename T> class Handle;
 template <typename T> class MutableHandle;
 template <typename T> class Rooted;
 template <typename T> class PersistentRooted;
--- a/js/public/UbiNode.h
+++ b/js/public/UbiNode.h
@@ -592,20 +592,20 @@ class JS_PUBLIC_API(Base) {
     // in time and memory.
     virtual js::UniquePtr<EdgeRange> edges(JSContext* cx, bool wantNames) const = 0;
 
     // Return the Zone to which this node's referent belongs, or nullptr if the
     // referent is not of a type allocated in SpiderMonkey Zones.
     virtual JS::Zone* zone() const { return nullptr; }
 
     // Return the compartment for this node. Some ubi::Node referents are not
-    // associated with JSCompartments, such as JSStrings (which are associated
+    // associated with Compartments, such as JSStrings (which are associated
     // with Zones). When the referent is not associated with a compartment,
     // nullptr is returned.
-    virtual JSCompartment* compartment() const { return nullptr; }
+    virtual JS::Compartment* compartment() const { return nullptr; }
 
     // Return the realm for this node. Some ubi::Node referents are not
     // associated with Realms, such as JSStrings (which are associated
     // with Zones) or cross-compartment wrappers (which are associated with
     // compartments). When the referent is not associated with a realm,
     // nullptr is returned.
     virtual JS::Realm* realm() const { return nullptr; }
 
@@ -776,17 +776,17 @@ class Node {
     // value that is safe to expose to JavaScript code, return that value.
     // Otherwise return UndefinedValue(). JSStrings, JS::Symbols, and some (but
     // not all!) JSObjects can be exposed.
     JS::Value exposeToJS() const;
 
     CoarseType coarseType()         const { return base()->coarseType(); }
     const char16_t* typeName()      const { return base()->typeName(); }
     JS::Zone* zone()                const { return base()->zone(); }
-    JSCompartment* compartment()    const { return base()->compartment(); }
+    JS::Compartment* compartment()  const { return base()->compartment(); }
     JS::Realm* realm()              const { return base()->realm(); }
     const char* jsObjectClassName() const { return base()->jsObjectClassName(); }
     MOZ_MUST_USE bool jsObjectConstructorName(JSContext* cx, UniqueTwoByteChars& outName) const {
         return base()->jsObjectConstructorName(cx, outName);
     }
 
     const char* scriptFilename() const { return base()->scriptFilename(); }
 
@@ -983,17 +983,17 @@ class MOZ_STACK_CLASS JS_PUBLIC_API(Root
     JSContext* cx;
     EdgeVector edges;
     bool       wantNames;
 
     RootList(JSContext* cx, Maybe<AutoCheckCannotGC>& noGC, bool wantNames = false);
 
     // Find all GC roots.
     MOZ_MUST_USE bool init();
-    // Find only GC roots in the provided set of |JSCompartment|s. Note: it's
+    // Find only GC roots in the provided set of |JS::Compartment|s. Note: it's
     // important to take a CompartmentSet and not a RealmSet: objects in
     // same-compartment realms can reference each other directly, without going
     // through CCWs, so if we used a RealmSet here we would miss edges.
     MOZ_MUST_USE bool init(CompartmentSet& debuggees);
     // Find only GC roots in the given Debugger object's set of debuggee
     // compartments.
     MOZ_MUST_USE bool init(HandleObject debuggees);
 
@@ -1037,17 +1037,17 @@ class JS_PUBLIC_API(TracerConcrete) : pu
     Referent& get() const { return *static_cast<Referent*>(ptr); }
 };
 
 // For JS::TraceChildren-based types that have 'realm' and 'compartment'
 // methods.
 template<typename Referent>
 class JS_PUBLIC_API(TracerConcreteWithRealm) : public TracerConcrete<Referent> {
     typedef TracerConcrete<Referent> TracerBase;
-    JSCompartment* compartment() const override;
+    JS::Compartment* compartment() const override;
     JS::Realm* realm() const override;
 
   protected:
     explicit TracerConcreteWithRealm(Referent* ptr) : TracerBase(ptr) { }
 };
 
 // Define specializations for some commonly-used public JSAPI types.
 // These can use the generic templates above.
@@ -1107,17 +1107,17 @@ class JS_PUBLIC_API(Concrete<JSObject>) 
   protected:
     explicit Concrete(JSObject* ptr) : TracerConcrete<JSObject>(ptr) { }
 
   public:
     static void construct(void* storage, JSObject* ptr) {
         new (storage) Concrete(ptr);
     }
 
-    JSCompartment* compartment() const override;
+    JS::Compartment* compartment() const override;
     JS::Realm* realm() const override;
 
     const char* jsObjectClassName() const override;
     MOZ_MUST_USE bool jsObjectConstructorName(JSContext* cx, UniqueTwoByteChars& outName)
         const override;
     Size size(mozilla::MallocSizeOf mallocSizeOf) const override;
 
     bool hasAllocationStack() const override;
@@ -1148,17 +1148,17 @@ class JS_PUBLIC_API(Concrete<JSString>) 
 
 // The ubi::Node null pointer. Any attempt to operate on a null ubi::Node asserts.
 template<>
 class JS_PUBLIC_API(Concrete<void>) : public Base {
     const char16_t* typeName() const override;
     Size size(mozilla::MallocSizeOf mallocSizeOf) const override;
     js::UniquePtr<EdgeRange> edges(JSContext* cx, bool wantNames) const override;
     JS::Zone* zone() const override;
-    JSCompartment* compartment() const override;
+    JS::Compartment* compartment() const override;
     JS::Realm* realm() const override;
     CoarseType coarseType() const final;
 
     explicit Concrete(void* ptr) : Base(ptr) { }
 
   public:
     static void construct(void* storage, void* ptr) { new (storage) Concrete(ptr); }
 };
--- a/js/rust/build.rs
+++ b/js/rust/build.rs
@@ -169,17 +169,16 @@ const WHITELIST_TYPES: &'static [&'stati
     "JS::HandleString",
     "JS::HandleValue",
     "JS::HandleValueArray",
     "JS::IsAcceptableThis",
     "JSAutoRealm",
     "JSAutoStructuredCloneBuffer",
     "JSClass",
     "JSClassOps",
-    "JSCompartment",
     "JSContext",
     "JSErrNum",
     "JSErrorCallback",
     "JSErrorFormatString",
     "JSErrorReport",
     "JSExnType",
     "JSFlatString",
     "JSFunction",
@@ -204,16 +203,17 @@ const WHITELIST_TYPES: &'static [&'stati
     "JSScript",
     "JSType",
     "JSTypedMethodJitInfo",
     "JSValueTag",
     "JSValueType",
     "JSVersion",
     "JSWrapObjectCallbacks",
     "jsid",
+    "JS::Compartment",
     "JS::Latin1Char",
     "JS::detail::MaybeWrapped",
     "JS::MutableHandle",
     "JS::MutableHandleObject",
     "JS::MutableHandleValue",
     "JS::NativeImpl",
     "js::ObjectOps",
     "JS::ObjectOpResult",
--- a/js/rust/src/rust.rs
+++ b/js/rust/src/rust.rs
@@ -1049,17 +1049,17 @@ unsafe fn get_object_group(obj: *mut JSO
 }
 
 #[inline]
 pub unsafe fn get_object_class(obj: *mut JSObject) -> *const JSClass {
     (*get_object_group(obj)).clasp as *const _
 }
 
 #[inline]
-pub unsafe fn get_object_compartment(obj: *mut JSObject) -> *mut JSCompartment {
+pub unsafe fn get_object_compartment(obj: *mut JSObject) -> *mut JS::Compartment {
     let realm = (*get_object_group(obj)).realm as *const JS::shadow::Realm;
     (*realm).compartment_
 }
 
 #[inline]
 pub fn is_dom_class(class: &JSClass) -> bool {
     class.flags & JSCLASS_IS_DOMJSCLASS != 0
 }
--- a/js/src/NamespaceImports.h
+++ b/js/src/NamespaceImports.h
@@ -161,16 +161,17 @@ using JS::UndefinedHandleValue;
 using JS::TrueHandleValue;
 using JS::FalseHandleValue;
 
 using JS::HandleValueArray;
 
 using JS::ObjectOpResult;
 using JS::PropertyResult;
 
+using JS::Compartment;
 using JS::Realm;
 using JS::Zone;
 
 using JS::Symbol;
 using JS::SymbolCode;
 
 #ifdef ENABLE_BIGINT
 using JS::BigInt;
--- a/js/src/fuzz-tests/tests.cpp
+++ b/js/src/fuzz-tests/tests.cpp
@@ -16,17 +16,16 @@
 #ifdef LIBFUZZER
 #include "FuzzerDefs.h"
 #endif
 
 using namespace mozilla;
 
 JS::PersistentRootedObject gGlobal;
 JSContext* gCx = nullptr;
-JSCompartment* gOldCompartment = nullptr;
 
 static const JSClass*
 getGlobalClass()
 {
     static const JSClassOps cOps = {
         nullptr, nullptr, nullptr, nullptr,
         nullptr, nullptr, nullptr, nullptr,
         nullptr, nullptr,
--- a/js/src/gc/Cell.h
+++ b/js/src/gc/Cell.h
@@ -62,17 +62,17 @@ struct Cell
 
     inline JSRuntime* runtimeFromMainThread() const;
 
     // Note: Unrestricted access to the runtime of a GC thing from an arbitrary
     // thread can easily lead to races. Use this method very carefully.
     inline JSRuntime* runtimeFromAnyThread() const;
 
     // May be overridden by GC thing kinds that have a compartment pointer.
-    inline JSCompartment* maybeCompartment() const { return nullptr; }
+    inline JS::Compartment* maybeCompartment() const { return nullptr; }
 
     // The StoreBuffer used to record incoming pointers from the tenured heap.
     // This will return nullptr for a tenured cell.
     inline StoreBuffer* storeBuffer() const;
 
     inline JS::TraceKind getTraceKind() const;
 
     static MOZ_ALWAYS_INLINE bool needWriteBarrierPre(JS::Zone* zone);
--- a/js/src/gc/GC.cpp
+++ b/js/src/gc/GC.cpp
@@ -1862,17 +1862,17 @@ GCRuntime::removeWeakPointerCompartmentC
         if (p.op == callback) {
             updateWeakPointerCompartmentCallbacks.ref().erase(&p);
             break;
         }
     }
 }
 
 void
-GCRuntime::callWeakPointerCompartmentCallbacks(JSCompartment* comp) const
+GCRuntime::callWeakPointerCompartmentCallbacks(JS::Compartment* comp) const
 {
     JSContext* cx = rt->mainContextFromOwnThread();
     for (auto const& p : updateWeakPointerCompartmentCallbacks.ref())
         p.op(cx, comp, p.data);
 }
 
 JS::GCSliceCallback
 GCRuntime::setSliceCallback(JS::GCSliceCallback callback) {
@@ -2970,17 +2970,17 @@ GCRuntime::updateZonePointersToRelocated
 void
 GCRuntime::updateRuntimePointersToRelocatedCells(AutoTraceSession& session)
 {
     MOZ_ASSERT(!rt->isBeingDestroyed());
 
     gcstats::AutoPhase ap1(stats(), gcstats::PhaseKind::COMPACT_UPDATE);
     MovingTracer trc(rt);
 
-    JSCompartment::fixupCrossCompartmentWrappersAfterMovingGC(&trc);
+    Compartment::fixupCrossCompartmentWrappersAfterMovingGC(&trc);
 
     rt->geckoProfiler().fixupStringsMapAfterMovingGC();
 
     traceRuntimeForMajorGC(&trc, session);
 
     // Mark roots to update them.
     {
         gcstats::AutoPhase ap2(stats(), gcstats::PhaseKind::MARK_ROOTS);
@@ -3825,17 +3825,17 @@ Realm::destroy(FreeOp* fop)
     if (auto callback = rt->destroyRealmCallback)
         callback(fop, this);
     if (principals())
         JS_DropPrincipals(rt->mainContextFromOwnThread(), principals());
     fop->delete_(this);
 }
 
 void
-JSCompartment::destroy(FreeOp* fop)
+Compartment::destroy(FreeOp* fop)
 {
     JSRuntime* rt = fop->runtime();
     if (auto callback = rt->destroyCompartmentCallback)
         callback(fop, this);
     fop->delete_(this);
     rt->gc.stats().sweptCompartment();
 }
 
@@ -3857,21 +3857,21 @@ Zone::destroy(FreeOp* fop)
  * arbitrary compartment in the zone.
  */
 void
 Zone::sweepCompartments(FreeOp* fop, bool keepAtleastOne, bool destroyingRuntime)
 {
     MOZ_ASSERT(!compartments().empty());
     MOZ_ASSERT_IF(destroyingRuntime, !keepAtleastOne);
 
-    JSCompartment** read = compartments().begin();
-    JSCompartment** end = compartments().end();
-    JSCompartment** write = read;
+    Compartment** read = compartments().begin();
+    Compartment** end = compartments().end();
+    Compartment** write = read;
     while (read < end) {
-        JSCompartment* comp = *read++;
+        Compartment* comp = *read++;
 
         /*
          * Don't delete the last compartment and realm if keepAtleastOne is
          * still true, meaning all the other compartments were deleted.
          */
         bool keepAtleastOneRealm = read == end && keepAtleastOne;
         comp->sweepRealms(fop, keepAtleastOneRealm, destroyingRuntime);
 
@@ -3883,17 +3883,17 @@ Zone::sweepCompartments(FreeOp* fop, boo
         }
     }
     compartments().shrinkTo(write - compartments().begin());
     MOZ_ASSERT_IF(keepAtleastOne, !compartments().empty());
     MOZ_ASSERT_IF(destroyingRuntime, compartments().empty());
 }
 
 void
-JSCompartment::sweepRealms(FreeOp* fop, bool keepAtleastOne, bool destroyingRuntime)
+Compartment::sweepRealms(FreeOp* fop, bool keepAtleastOne, bool destroyingRuntime)
 {
     MOZ_ASSERT(!realms().empty());
     MOZ_ASSERT_IF(destroyingRuntime, !keepAtleastOne);
 
     Realm** read = realms().begin();
     Realm** end = realms().end();
     Realm** write = read;
     while (read < end) {
@@ -4118,64 +4118,64 @@ class CompartmentCheckTracer : public JS
   public:
     explicit CompartmentCheckTracer(JSRuntime* rt)
       : JS::CallbackTracer(rt), src(nullptr), zone(nullptr), compartment(nullptr)
     {}
 
     Cell* src;
     JS::TraceKind srcKind;
     Zone* zone;
-    JSCompartment* compartment;
+    Compartment* compartment;
 };
 
 namespace {
 struct IsDestComparatorFunctor {
     JS::GCCellPtr dst_;
     explicit IsDestComparatorFunctor(JS::GCCellPtr dst) : dst_(dst) {}
 
     template <typename T> bool operator()(T* t) { return (*t) == dst_.asCell(); }
 };
 } // namespace (anonymous)
 
 static bool
 InCrossCompartmentMap(JSObject* src, JS::GCCellPtr dst)
 {
-    JSCompartment* srccomp = src->compartment();
+    Compartment* srccomp = src->compartment();
 
     if (dst.is<JSObject>()) {
         Value key = ObjectValue(dst.as<JSObject>());
         if (WrapperMap::Ptr p = srccomp->lookupWrapper(key)) {
             if (*p->value().unsafeGet() == ObjectValue(*src))
                 return true;
         }
     }
 
     /*
      * If the cross-compartment edge is caused by the debugger, then we don't
      * know the right hashtable key, so we have to iterate.
      */
-    for (JSCompartment::WrapperEnum e(srccomp); !e.empty(); e.popFront()) {
+    for (Compartment::WrapperEnum e(srccomp); !e.empty(); e.popFront()) {
         if (e.front().mutableKey().applyToWrapped(IsDestComparatorFunctor(dst)) &&
             ToMarkable(e.front().value().unbarrieredGet()) == src)
         {
             return true;
         }
     }
 
     return false;
 }
 
 struct MaybeCompartmentFunctor {
-    template <typename T> JSCompartment* operator()(T* t) { return t->maybeCompartment(); }
+    template <typename T> JS::Compartment* operator()(T* t) { return t->maybeCompartment(); }
 };
 
 void
 CompartmentCheckTracer::onChild(const JS::GCCellPtr& thing)
 {
-    JSCompartment* comp = DispatchTyped(MaybeCompartmentFunctor(), thing);
+    Compartment* comp = DispatchTyped(MaybeCompartmentFunctor(), thing);
     if (comp && compartment) {
         MOZ_ASSERT(comp == compartment ||
                    (srcKind == JS::TraceKind::Object &&
                     InCrossCompartmentMap(static_cast<JSObject*>(src), thing)));
     } else {
         TenuredCell* tenured = TenuredCell::fromPointer(thing.asCell());
         Zone* thingZone = tenured->zoneFromAnyThread();
         MOZ_ASSERT(thingZone == zone || thingZone->isAtomsZone());
@@ -4520,29 +4520,29 @@ GCRuntime::markCompartments()
      * during a function like JS_TransplantObject, which iterates over all
      * compartments, live or dead, and operates on their objects. See bug 803376
      * for details on this problem. To avoid the problem, we try to avoid
      * allocation and read barriers during JS_TransplantObject and the like.
      */
 
     /* Propagate the maybeAlive flag via cross-compartment edges. */
 
-    Vector<JSCompartment*, 0, js::SystemAllocPolicy> workList;
+    Vector<Compartment*, 0, js::SystemAllocPolicy> workList;
 
     for (CompartmentsIter comp(rt); !comp.done(); comp.next()) {
         if (comp->gcState.maybeAlive) {
             if (!workList.append(comp))
                 return;
         }
     }
 
     while (!workList.empty()) {
-        JSCompartment* comp = workList.popCopy();
-        for (JSCompartment::NonStringWrapperEnum e(comp); !e.empty(); e.popFront()) {
-            JSCompartment* dest = e.front().mutableKey().compartment();
+        Compartment* comp = workList.popCopy();
+        for (Compartment::NonStringWrapperEnum e(comp); !e.empty(); e.popFront()) {
+            Compartment* dest = e.front().mutableKey().compartment();
             if (dest && !dest->gcState.maybeAlive) {
                 dest->gcState.maybeAlive = true;
                 if (!workList.append(dest))
                     return;
             }
         }
     }
 
@@ -4943,17 +4943,17 @@ static void
 DropStringWrappers(JSRuntime* rt)
 {
     /*
      * String "wrappers" are dropped on GC because their presence would require
      * us to sweep the wrappers in all compartments every time we sweep a
      * compartment group.
      */
     for (CompartmentsIter c(rt); !c.done(); c.next()) {
-        for (JSCompartment::StringWrapperEnum e(c); !e.empty(); e.popFront()) {
+        for (Compartment::StringWrapperEnum e(c); !e.empty(); e.popFront()) {
             MOZ_ASSERT(e.front().key().is<JSString*>());
             e.removeFront();
         }
     }
 }
 
 /*
  * Group zones that must be swept at the same time.
@@ -4992,17 +4992,17 @@ struct AddOutgoingEdgeFunctor {
             if (zone->isGCMarking())
                 finder_.addEdgeTo(zone);
         }
     }
 };
 } // namespace (anonymous)
 
 void
-JSCompartment::findOutgoingEdges(ZoneComponentFinder& finder)
+Compartment::findOutgoingEdges(ZoneComponentFinder& finder)
 {
     for (js::WrapperMap::Enum e(crossCompartmentWrappers); !e.empty(); e.popFront()) {
         CrossCompartmentKey& key = e.front().mutableKey();
         MOZ_ASSERT(!key.is<JSString*>());
         bool needsEdge = true;
         if (key.is<JSObject*>()) {
             TenuredCell& other = key.as<JSObject*>()->asTenured();
             needsEdge = !other.isMarkedBlack();
@@ -5094,17 +5094,17 @@ GCRuntime::groupZonesForSweeping(JS::gcr
 
     MOZ_ASSERT_IF(!isIncremental, !currentSweepGroup->nextGroup());
     for (ZonesIter zone(rt, WithAtoms); !zone.done(); zone.next())
         MOZ_ASSERT(zone->gcSweepGroupEdges().empty());
 #endif
 }
 
 static void
-ResetGrayList(JSCompartment* comp);
+ResetGrayList(Compartment* comp);
 
 void
 GCRuntime::getNextSweepGroup()
 {
     currentSweepGroup = currentSweepGroup->nextGroup();
     ++sweepGroupIndex;
     if (!currentSweepGroup) {
         abortSweepAfterCurrentGroup = false;
@@ -5144,17 +5144,17 @@ GCRuntime::getNextSweepGroup()
  *
  * This means that when marking things gray we must not allow marking to leave
  * the current compartment group, as that could result in things being marked
  * grey when they might subsequently be marked black.  To achieve this, when we
  * find a cross compartment pointer we don't mark the referent but add it to a
  * singly-linked list of incoming gray pointers that is stored with each
  * compartment.
  *
- * The list head is stored in JSCompartment::gcIncomingGrayPointers and contains
+ * The list head is stored in Compartment::gcIncomingGrayPointers and contains
  * cross compartment wrapper objects. The next pointer is stored in the second
  * extra slot of the cross compartment wrapper.
  *
  * The list is created during gray marking when one of the
  * MarkCrossCompartmentXXX functions is called for a pointer that leaves the
  * current compartent group.  This calls DelayCrossCompartmentGrayMarking to
  * push the referring object onto the list.
  *
@@ -5186,17 +5186,17 @@ AssertNotOnGrayList(JSObject* obj)
 #endif
 
 static void
 AssertNoWrappersInGrayList(JSRuntime* rt)
 {
 #ifdef DEBUG
     for (CompartmentsIter c(rt); !c.done(); c.next()) {
         MOZ_ASSERT(!c->gcIncomingGrayPointers);
-        for (JSCompartment::NonStringWrapperEnum e(c); !e.empty(); e.popFront())
+        for (Compartment::NonStringWrapperEnum e(c); !e.empty(); e.popFront())
             AssertNotOnGrayList(&e.front().value().unbarrieredGet().toObject());
     }
 #endif
 }
 
 static JSObject*
 CrossCompartmentPointerReferent(JSObject* obj)
 {
@@ -5223,17 +5223,17 @@ js::gc::DelayCrossCompartmentGrayMarking
     MOZ_ASSERT(IsGrayListObject(src));
     MOZ_ASSERT(src->isMarkedGray());
 
     AutoTouchingGrayThings tgt;
 
     /* Called from MarkCrossCompartmentXXX functions. */
     unsigned slot = ProxyObject::grayLinkReservedSlot(src);
     JSObject* dest = CrossCompartmentPointerReferent(src);
-    JSCompartment* comp = dest->compartment();
+    Compartment* comp = dest->compartment();
 
     if (GetProxyReservedSlot(src, slot).isUndefined()) {
         SetProxyReservedSlot(src, slot, ObjectOrNullValue(comp->gcIncomingGrayPointers));
         comp->gcIncomingGrayPointers = src;
     } else {
         MOZ_ASSERT(GetProxyReservedSlot(src, slot).isObjectOrNull());
     }
 
@@ -5307,17 +5307,17 @@ RemoveFromGrayList(JSObject* wrapper)
 
     unsigned slot = ProxyObject::grayLinkReservedSlot(wrapper);
     if (GetProxyReservedSlot(wrapper, slot).isUndefined())
         return false;  /* Not on our list. */
 
     JSObject* tail = GetProxyReservedSlot(wrapper, slot).toObjectOrNull();
     SetProxyReservedSlot(wrapper, slot, UndefinedValue());
 
-    JSCompartment* comp = CrossCompartmentPointerReferent(wrapper)->compartment();
+    Compartment* comp = CrossCompartmentPointerReferent(wrapper)->compartment();
     JSObject* obj = comp->gcIncomingGrayPointers;
     if (obj == wrapper) {
         comp->gcIncomingGrayPointers = tail;
         return true;
     }
 
     while (obj) {
         unsigned slot = ProxyObject::grayLinkReservedSlot(obj);
@@ -5328,17 +5328,17 @@ RemoveFromGrayList(JSObject* wrapper)
         }
         obj = next;
     }
 
     MOZ_CRASH("object not found in gray link list");
 }
 
 static void
-ResetGrayList(JSCompartment* comp)
+ResetGrayList(Compartment* comp)
 {
     JSObject* src = comp->gcIncomingGrayPointers;
     while (src)
         src = NextIncomingCrossCompartmentPointer(src, true);
     comp->gcIncomingGrayPointers = nullptr;
 }
 
 void
@@ -7992,19 +7992,19 @@ AutoPrepareForTracing::AutoPrepareForTra
 
 Realm*
 js::NewRealm(JSContext* cx, JSPrincipals* principals, const JS::RealmOptions& options)
 {
     JSRuntime* rt = cx->runtime();
     JS_AbortIfWrongThread(cx);
 
     UniquePtr<Zone> zoneHolder;
-    UniquePtr<JSCompartment> compHolder;
-
-    JSCompartment* comp = nullptr;
+    UniquePtr<Compartment> compHolder;
+
+    Compartment* comp = nullptr;
     Zone* zone = nullptr;
     JS::CompartmentSpecifier compSpec = options.creationOptions().compartmentSpecifier();
     switch (compSpec) {
       case JS::CompartmentSpecifier::NewCompartmentInSystemZone:
         // systemZone might be null here, in which case we'll make a zone and
         // set this field below.
         zone = rt->gc.systemZone;
         break;
@@ -8031,17 +8031,17 @@ js::NewRealm(JSContext* cx, JSPrincipals
             ReportOutOfMemory(cx);
             return nullptr;
         }
 
         zone = zoneHolder.get();
     }
 
     if (!comp) {
-        compHolder = cx->make_unique<JSCompartment>(zone);
+        compHolder = cx->make_unique<JS::Compartment>(zone);
         if (!compHolder || !compHolder->init(cx))
             return nullptr;
 
         comp = compHolder.get();
     }
 
     UniquePtr<Realm> realm(cx->new_<Realm>(comp, options));
     if (!realm || !realm->init(cx))
--- a/js/src/gc/GCRuntime.h
+++ b/js/src/gc/GCRuntime.h
@@ -641,17 +641,17 @@ class GCRuntime
     void finishMarkingValidation();
 
 #ifdef DEBUG
     void checkForCompartmentMismatches();
 #endif
 
     void callFinalizeCallbacks(FreeOp* fop, JSFinalizeStatus status) const;
     void callWeakPointerZonesCallbacks() const;
-    void callWeakPointerCompartmentCallbacks(JSCompartment* comp) const;
+    void callWeakPointerCompartmentCallbacks(JS::Compartment* comp) const;
 
   public:
     JSRuntime* const rt;
 
     /* Embedders can use this zone and group however they wish. */
     UnprotectedData<JS::Zone*> systemZone;
 
     // All zones in the runtime, except the atoms zone.
--- a/js/src/gc/PublicIterators.cpp
+++ b/js/src/gc/PublicIterators.cpp
@@ -152,17 +152,17 @@ JS::IterateRealms(JSContext* cx, void* d
     Rooted<Realm*> realm(cx);
     for (RealmsIter r(cx->runtime()); !r.done(); r.next()) {
         realm = r;
         (*realmCallback)(cx, data, realm);
     }
 }
 
 JS_PUBLIC_API(void)
-JS::IterateRealmsInCompartment(JSContext* cx, JSCompartment* compartment, void* data,
+JS::IterateRealmsInCompartment(JSContext* cx, JS::Compartment* compartment, void* data,
                                JS::IterateRealmCallback realmCallback)
 {
     AutoTraceSession session(cx->runtime());
 
     Rooted<Realm*> realm(cx);
     for (RealmsInCompartmentIter r(compartment); !r.done(); r.next()) {
         realm = r;
         (*realmCallback)(cx, data, realm);
--- a/js/src/gc/PublicIterators.h
+++ b/js/src/gc/PublicIterators.h
@@ -69,52 +69,52 @@ class ZonesIter
     }
 
     operator JS::Zone*() const { return get(); }
     JS::Zone* operator->() const { return get(); }
 };
 
 struct CompartmentsInZoneIter
 {
-    using ItemType = JSCompartment;
+    using ItemType = JS::Compartment;
 
     explicit CompartmentsInZoneIter(JS::Zone* zone) : zone(zone) {
         it = zone->compartments().begin();
     }
 
     bool done() const {
         MOZ_ASSERT(it);
         return it < zone->compartments().begin() ||
                it >= zone->compartments().end();
     }
     void next() {
         MOZ_ASSERT(!done());
         it++;
     }
 
-    JSCompartment* get() const {
+    JS::Compartment* get() const {
         MOZ_ASSERT(it);
         return *it;
     }
 
-    operator JSCompartment*() const { return get(); }
-    JSCompartment* operator->() const { return get(); }
+    operator JS::Compartment*() const { return get(); }
+    JS::Compartment* operator->() const { return get(); }
 
   private:
     JS::Zone* zone;
-    JSCompartment** it;
+    JS::Compartment** it;
 };
 
 class RealmsInCompartmentIter
 {
-    JSCompartment* comp;
+    JS::Compartment* comp;
     JS::Realm** it;
 
   public:
-    explicit RealmsInCompartmentIter(JSCompartment* comp)
+    explicit RealmsInCompartmentIter(JS::Compartment* comp)
       : comp(comp)
     {
         it = comp->realms().begin();
     }
 
     bool done() const {
         MOZ_ASSERT(it);
         return it < comp->realms().begin() ||
--- a/js/src/gc/RootMarking.cpp
+++ b/js/src/gc/RootMarking.cpp
@@ -271,17 +271,17 @@ js::gc::GCRuntime::traceRuntimeForMajorG
     // is gone, so we can simply skip traceRuntime here.
     if (rt->isBeingDestroyed())
         return;
 
     gcstats::AutoPhase ap(stats(), gcstats::PhaseKind::MARK_ROOTS);
     if (atomsZone->isCollecting())
         traceRuntimeAtoms(trc, session.lock());
     traceKeptAtoms(trc);
-    JSCompartment::traceIncomingCrossCompartmentEdgesForZoneGC(trc);
+    Compartment::traceIncomingCrossCompartmentEdgesForZoneGC(trc);
     traceRuntimeCommon(trc, MarkRuntime, session);
 }
 
 void
 js::gc::GCRuntime::traceRuntimeForMinorGC(JSTracer* trc, AutoTraceSession& session)
 {
     MOZ_ASSERT(!TlsContext.get()->suppressGC);
 
--- a/js/src/gc/Tracer.cpp
+++ b/js/src/gc/Tracer.cpp
@@ -162,17 +162,17 @@ struct TraceIncomingFunctor {
 
 JS_PUBLIC_API(void)
 JS::TraceIncomingCCWs(JSTracer* trc, const JS::CompartmentSet& compartments)
 {
     for (js::CompartmentsIter comp(trc->runtime()); !comp.done(); comp.next()) {
         if (compartments.has(comp))
             continue;
 
-        for (JSCompartment::WrapperEnum e(comp); !e.empty(); e.popFront()) {
+        for (Compartment::WrapperEnum e(comp); !e.empty(); e.popFront()) {
             mozilla::DebugOnly<const CrossCompartmentKey> prior = e.front().key();
             e.front().mutableKey().applyToWrapped(TraceIncomingFunctor(trc, compartments));
             MOZ_ASSERT(e.front().key() == prior);
         }
     }
 }
 
 
--- a/js/src/gc/Zone.cpp
+++ b/js/src/gc/Zone.cpp
@@ -387,17 +387,17 @@ Zone::addTypeDescrObject(JSContext* cx, 
         ReportOutOfMemory(cx);
         return false;
     }
 
     return true;
 }
 
 void
-Zone::deleteEmptyCompartment(JSCompartment* comp)
+Zone::deleteEmptyCompartment(JS::Compartment* comp)
 {
     MOZ_ASSERT(comp->zone() == this);
     MOZ_ASSERT(arenas.checkEmptyArenaLists());
 
     MOZ_ASSERT(compartments().length() == 1);
     MOZ_ASSERT(compartments()[0] == comp);
     MOZ_ASSERT(comp->realms().length() == 1);
 
--- a/js/src/gc/Zone.h
+++ b/js/src/gc/Zone.h
@@ -339,17 +339,17 @@ struct Zone : public JS::shadow::Zone,
     js::TypeZone types;
 
   private:
     /* Live weakmaps in this zone. */
     js::ZoneOrGCTaskData<mozilla::LinkedList<js::WeakMapBase>> gcWeakMapList_;
   public:
     mozilla::LinkedList<js::WeakMapBase>& gcWeakMapList() { return gcWeakMapList_.ref(); }
 
-    typedef js::Vector<JSCompartment*, 1, js::SystemAllocPolicy> CompartmentVector;
+    typedef js::Vector<JS::Compartment*, 1, js::SystemAllocPolicy> CompartmentVector;
 
   private:
     // The set of compartments in this zone.
     js::MainThreadOrGCTaskData<CompartmentVector> compartments_;
   public:
     CompartmentVector& compartments() { return compartments_.ref(); }
 
     // This zone's gray roots.
@@ -699,17 +699,17 @@ struct Zone : public JS::shadow::Zone,
     bool keepShapeTables() const {
         return keepShapeTables_;
     }
     void setKeepShapeTables(bool b) {
         keepShapeTables_ = b;
     }
 
     // Delete an empty compartment after its contents have been merged.
-    void deleteEmptyCompartment(JSCompartment* comp);
+    void deleteEmptyCompartment(JS::Compartment* comp);
 
     /*
      * This variation of calloc will call the large-allocation-failure callback
      * on OOM and retry the allocation.
      */
     template <typename T>
     T* pod_callocCanGC(size_t numElems) {
         T* p = pod_calloc<T>(numElems);
--- a/js/src/jit-test/tests/debug/bug-876654.js
+++ b/js/src/jit-test/tests/debug/bug-876654.js
@@ -1,11 +1,11 @@
 // |jit-test| 
 // Exercise finding a DebuggerSource cross compartment wrapper in
-// JSCompartment::findOutgoingEdges()
+// Compartment::findOutgoingEdges()
 
 let g = newGlobal();
 let dbg = new Debugger(g);
 dbg.onNewScript = function (script) {
   var text = script.source.text;
 }
 g.eval("function f() { function g() {} }");
 gczeal(9, 1)
--- a/js/src/jit/CacheIR.h
+++ b/js/src/jit/CacheIR.h
@@ -678,17 +678,17 @@ class MOZ_RAII CacheIRWriter : public JS
         writeOperandId(operand);
         writeInt32Immediate(expected);
         buffer_.writeByte(uint32_t(cond));
     }
     void guardMagicValue(ValOperandId val, JSWhyMagic magic) {
         writeOpWithOperandId(CacheOp::GuardMagicValue, val);
         buffer_.writeByte(uint32_t(magic));
     }
-    void guardCompartment(ObjOperandId obj, JSObject* global, JSCompartment* compartment) {
+    void guardCompartment(ObjOperandId obj, JSObject* global, JS::Compartment* compartment) {
         assertSameCompartment(global);
         writeOpWithOperandId(CacheOp::GuardCompartment, obj);
         // Add a reference to a global in the compartment to keep it alive.
         addStubField(uintptr_t(global), StubField::Type::JSObject);
         // Use RawWord, because compartments never move and it can't be GCed.
         addStubField(uintptr_t(compartment), StubField::Type::RawWord);
     }
     void guardNoDetachedTypedObjects() {
--- a/js/src/jit/CacheIRCompiler.h
+++ b/js/src/jit/CacheIRCompiler.h
@@ -722,19 +722,19 @@ class MOZ_RAII CacheIRCompiler
     JS::Symbol* symbolStubField(uint32_t offset) {
         MOZ_ASSERT(stubFieldPolicy_ == StubFieldPolicy::Constant);
         return (JS::Symbol*)readStubWord(offset, StubField::Type::Symbol);
     }
     ObjectGroup* groupStubField(uint32_t offset) {
         MOZ_ASSERT(stubFieldPolicy_ == StubFieldPolicy::Constant);
         return (ObjectGroup*)readStubWord(offset, StubField::Type::ObjectGroup);
     }
-    JSCompartment* compartmentStubField(uint32_t offset) {
+    JS::Compartment* compartmentStubField(uint32_t offset) {
         MOZ_ASSERT(stubFieldPolicy_ == StubFieldPolicy::Constant);
-        return (JSCompartment*)readStubWord(offset, StubField::Type::RawWord);
+        return (JS::Compartment*)readStubWord(offset, StubField::Type::RawWord);
     }
     const Class* classStubField(uintptr_t offset) {
         MOZ_ASSERT(stubFieldPolicy_ == StubFieldPolicy::Constant);
         return (const Class*)readStubWord(offset, StubField::Type::RawWord);
     }
     const void* proxyHandlerStubField(uintptr_t offset) {
         MOZ_ASSERT(stubFieldPolicy_ == StubFieldPolicy::Constant);
         return (const void*)readStubWord(offset, StubField::Type::RawWord);
--- a/js/src/jit/IonCacheIRCompiler.cpp
+++ b/js/src/jit/IonCacheIRCompiler.cpp
@@ -676,17 +676,17 @@ IonCacheIRCompiler::emitGuardProto()
     return true;
 }
 
 bool
 IonCacheIRCompiler::emitGuardCompartment()
 {
     Register obj = allocator.useRegister(masm, reader.objOperandId());
     JSObject* globalWrapper = objectStubField(reader.stubOffset());
-    JSCompartment* compartment = compartmentStubField(reader.stubOffset());
+    JS::Compartment* compartment = compartmentStubField(reader.stubOffset());
     AutoScratchRegister scratch(allocator, masm);
 
     FailurePath* failure;
     if (!addFailurePath(&failure))
         return false;
 
     // Verify that the global wrapper is still valid, as
     // it is pre-requisite for doing the compartment check.
--- a/js/src/jit/MacroAssembler.cpp
+++ b/js/src/jit/MacroAssembler.cpp
@@ -3278,17 +3278,17 @@ MacroAssembler::branchTestObjCompartment
     loadPtr(Address(obj, JSObject::offsetOfGroup()), scratch);
     loadPtr(Address(scratch, ObjectGroup::offsetOfRealm()), scratch);
     loadPtr(Address(scratch, Realm::offsetOfCompartment()), scratch);
     branchPtr(cond, compartment, scratch, label);
 }
 
 void
 MacroAssembler::branchTestObjCompartment(Condition cond, Register obj,
-                                         const JSCompartment* compartment, Register scratch,
+                                         const JS::Compartment* compartment, Register scratch,
                                          Label* label)
 {
     MOZ_ASSERT(obj != scratch);
     loadPtr(Address(obj, JSObject::offsetOfGroup()), scratch);
     loadPtr(Address(scratch, ObjectGroup::offsetOfRealm()), scratch);
     loadPtr(Address(scratch, Realm::offsetOfCompartment()), scratch);
     branchPtr(cond, scratch, ImmPtr(compartment), label);
 }
--- a/js/src/jit/MacroAssembler.h
+++ b/js/src/jit/MacroAssembler.h
@@ -1140,17 +1140,17 @@ class MacroAssembler : public MacroAssem
 
     // TODO: audit/fix callers to be Spectre safe.
     inline void branchTestObjShapeUnsafe(Condition cond, Register obj, Register shape, Label* label);
     inline void branchTestObjGroupUnsafe(Condition cond, Register obj, const ObjectGroup* group,
                                          Label* label);
 
     void branchTestObjCompartment(Condition cond, Register obj, const Address& compartment,
                                   Register scratch, Label* label);
-    void branchTestObjCompartment(Condition cond, Register obj, const JSCompartment* compartment,
+    void branchTestObjCompartment(Condition cond, Register obj, const JS::Compartment* compartment,
                                   Register scratch, Label* label);
     void branchIfObjGroupHasNoAddendum(Register obj, Register scratch, Label* label);
     void branchIfPretenuredGroup(const ObjectGroup* group, Register scratch, Label* label);
 
     void branchIfNonNativeObj(Register obj, Register scratch, Label* label);
 
     void branchIfInlineTypedObject(Register obj, Register scratch, Label* label);
 
--- a/js/src/jit/VMFunctions.cpp
+++ b/js/src/jit/VMFunctions.cpp
@@ -779,17 +779,17 @@ JSObject*
 WrapObjectPure(JSContext* cx, JSObject* obj)
 {
     // IC code calls this directly so we shouldn't GC.
     AutoUnsafeCallWithABI unsafe;
 
     MOZ_ASSERT(obj);
     MOZ_ASSERT(cx->compartment() != obj->compartment());
 
-    // From: JSCompartment::getNonWrapperObjectForCurrentCompartment
+    // From: Compartment::getNonWrapperObjectForCurrentCompartment
     // Note that if the object is same-compartment, but has been wrapped into a
     // different compartment, we need to unwrap it and return the bare same-
     // compartment object. Note again that windows are always wrapped by a
     // WindowProxy even when same-compartment so take care not to strip this
     // particular wrapper.
     obj = UncheckedUnwrap(obj, /* stopAtWindowProxy = */ true);
     if (cx->compartment() == obj->compartment()) {
         MOZ_ASSERT(!IsWindow(obj));
--- a/js/src/jsapi-tests/testGCMarking.cpp
+++ b/js/src/jsapi-tests/testGCMarking.cpp
@@ -131,20 +131,20 @@ BEGIN_TEST(testTracingIncomingCCWs)
     CHECK(trc.numberOfThingsTraced == 1);
     CHECK(trc.okay);
 
     return true;
 }
 END_TEST(testTracingIncomingCCWs)
 
 static size_t
-countWrappers(JSCompartment* comp)
+countWrappers(JS::Compartment* comp)
 {
     size_t count = 0;
-    for (JSCompartment::WrapperEnum e(comp); !e.empty(); e.popFront())
+    for (JS::Compartment::WrapperEnum e(comp); !e.empty(); e.popFront())
         ++count;
     return count;
 }
 
 BEGIN_TEST(testDeadNurseryCCW)
 {
 #ifdef JS_GC_ZEAL
     // Disable zeal modes because this test needs to control exactly when the GC happens.
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -727,23 +727,23 @@ JSAutoNullableRealm::JSAutoNullableRealm
 }
 
 JSAutoNullableRealm::~JSAutoNullableRealm()
 {
     cx_->leaveRealm(oldRealm_);
 }
 
 JS_PUBLIC_API(void)
-JS_SetCompartmentPrivate(JSCompartment* compartment, void* data)
+JS_SetCompartmentPrivate(JS::Compartment* compartment, void* data)
 {
     compartment->data = data;
 }
 
 JS_PUBLIC_API(void*)
-JS_GetCompartmentPrivate(JSCompartment* compartment)
+JS_GetCompartmentPrivate(JS::Compartment* compartment)
 {
     return compartment->data;
 }
 
 JS_PUBLIC_API(void)
 JS_MarkCrossZoneId(JSContext* cx, jsid id)
 {
     cx->markId(id);
@@ -872,17 +872,17 @@ JS_TransplantObject(JSContext* cx, Handl
     RootedValue origv(cx, ObjectValue(*origobj));
     RootedObject newIdentity(cx);
 
     // Don't allow a compacting GC to observe any intermediate state.
     AutoDisableCompactingGC nocgc(cx);
 
     AutoDisableProxyCheck adpc;
 
-    JSCompartment* destination = target->compartment();
+    JS::Compartment* destination = target->compartment();
 
     if (origobj->compartment() == destination) {
         // If the original object is in the same compartment as the
         // destination, then we know that we won't find a wrapper in the
         // destination's cross compartment map and that the same
         // object will continue to work.
         AutoRealmUnchecked ar(cx, origobj->realm());
         if (!JSObject::swap(cx, origobj, target))
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -304,25 +304,21 @@ typedef void
 
 struct JSWrapObjectCallbacks
 {
     JSWrapObjectCallback wrap;
     JSPreWrapCallback preWrap;
 };
 
 typedef void
-(* JSDestroyCompartmentCallback)(JSFreeOp* fop, JSCompartment* compartment);
+(* JSDestroyCompartmentCallback)(JSFreeOp* fop, JS::Compartment* compartment);
 
 typedef size_t
 (* JSSizeOfIncludingThisCompartmentCallback)(mozilla::MallocSizeOf mallocSizeOf,
-                                             JSCompartment* compartment);
-
-typedef void
-(* JSCompartmentNameCallback)(JSContext* cx, JSCompartment* compartment,
-                              char* buf, size_t bufsize);
+                                             JS::Compartment* compartment);
 
 /**
  * Callback used by memory reporting to ask the embedder how much memory an
  * external string is keeping alive.  The embedder is expected to return a value
  * that corresponds to the size of the allocation that will be released by the
  * JSStringFinalizer passed to JS_NewExternalString for this string.
  *
  * Implementations of this callback MUST NOT do anything that can cause GC.
@@ -992,20 +988,20 @@ JS_GetErrorInterceptorCallback(JSRuntime
 // Examine a value to determine if it is one of the built-in Error types.
 // If so, return the error type.
 extern JS_PUBLIC_API(mozilla::Maybe<JSExnType>)
 JS_GetErrorType(const JS::Value& val);
 
 #endif // defined(NIGHTLY_BUILD)
 
 extern JS_PUBLIC_API(void)
-JS_SetCompartmentPrivate(JSCompartment* compartment, void* data);
+JS_SetCompartmentPrivate(JS::Compartment* compartment, void* data);
 
 extern JS_PUBLIC_API(void*)
-JS_GetCompartmentPrivate(JSCompartment* compartment);
+JS_GetCompartmentPrivate(JS::Compartment* compartment);
 
 extern JS_PUBLIC_API(void)
 JS_SetZoneUserData(JS::Zone* zone, void* data);
 
 extern JS_PUBLIC_API(void*)
 JS_GetZoneUserData(JS::Zone* zone);
 
 extern JS_PUBLIC_API(bool)
@@ -1104,22 +1100,22 @@ using IterateRealmCallback = void (*)(JS
  */
 extern JS_PUBLIC_API(void)
 IterateRealms(JSContext* cx, void* data, IterateRealmCallback realmCallback);
 
 /**
  * Like IterateRealms, but only iterates realms in |compartment|.
  */
 extern JS_PUBLIC_API(void)
-IterateRealmsInCompartment(JSContext* cx, JSCompartment* compartment, void* data,
+IterateRealmsInCompartment(JSContext* cx, JS::Compartment* compartment, void* data,
                            IterateRealmCallback realmCallback);
 
 } // namespace JS
 
-typedef void (*JSIterateCompartmentCallback)(JSContext* cx, void* data, JSCompartment* compartment);
+typedef void (*JSIterateCompartmentCallback)(JSContext* cx, void* data, JS::Compartment* compartment);
 
 /**
  * This function calls |compartmentCallback| on every compartment. Beware that
  * there is no guarantee that the compartment will survive after the callback
  * returns. Also, barriers are disabled via the TraceSession.
  */
 extern JS_PUBLIC_API(void)
 JS_IterateCompartments(JSContext* cx, void* data,
@@ -1763,17 +1759,17 @@ class JS_PUBLIC_API(RealmCreationOptions
         traceGlobal_ = op;
         return *this;
     }
 
     JS::Zone* zone() const {
         MOZ_ASSERT(compSpec_ == CompartmentSpecifier::NewCompartmentInExistingZone);
         return zone_;
     }
-    JSCompartment* compartment() const {
+    JS::Compartment* compartment() const {
         MOZ_ASSERT(compSpec_ == CompartmentSpecifier::ExistingCompartment);
         return comp_;
     }
     CompartmentSpecifier compartmentSpecifier() const { return compSpec_; }
 
     // Set the compartment/zone to use for the realm. See CompartmentSpecifier above.
     RealmCreationOptions& setNewCompartmentInSystemZone();
     RealmCreationOptions& setNewCompartmentInExistingZone(JSObject* obj);
@@ -1832,17 +1828,17 @@ class JS_PUBLIC_API(RealmCreationOptions
         clampAndJitterTime_ = flag;
         return *this;
     }
 
   private:
     JSTraceOp traceGlobal_;
     CompartmentSpecifier compSpec_;
     union {
-        JSCompartment* comp_;
+        JS::Compartment* comp_;
         JS::Zone* zone_;
     };
     bool invisibleToDebugger_;
     bool mergeable_;
     bool preserveJitCode_;
     bool cloneSingletons_;
     bool sharedMemoryAndAtomics_;
     bool secureContext_;
--- a/js/src/jsfriendapi.cpp
+++ b/js/src/jsfriendapi.cpp
@@ -150,17 +150,17 @@ JS_NewObjectWithoutMetadata(JSContext* c
 
 JS_FRIEND_API(bool)
 JS::GetIsSecureContext(JS::Realm* realm)
 {
     return realm->creationOptions().secureContext();
 }
 
 JS_FRIEND_API(JSPrincipals*)
-JS_GetCompartmentPrincipals(JSCompartment* compartment)
+JS_GetCompartmentPrincipals(JS::Compartment* compartment)
 {
     // Note: for now we assume a single realm per compartment. This API will go
     // away after we remove the remaining callers. See bug 1465700.
     MOZ_RELEASE_ASSERT(compartment->realms().length() == 1);
 
     return compartment->realms()[0]->principals();
 }
 
@@ -342,17 +342,17 @@ js::ObjectClassName(JSContext* cx, Handl
 
 JS_FRIEND_API(JS::Zone*)
 js::GetRealmZone(JS::Realm* realm)
 {
     return realm->zone();
 }
 
 JS_FRIEND_API(bool)
-js::IsSystemCompartment(JSCompartment* comp)
+js::IsSystemCompartment(JS::Compartment* comp)
 {
     // Note: for now we assume a single realm per compartment. This API will
     // hopefully go away once Gecko supports same-compartment realms. Another
     // option is to return comp->zone()->isSystem here, but we'd have to make
     // sure that's equivalent.
     MOZ_RELEASE_ASSERT(comp->realms().length() == 1);
 
     return comp->realms()[0]->isSystem();
@@ -624,17 +624,17 @@ struct VisitGrayCallbackFunctor {
     }
 };
 } // namespace (anonymous)
 
 JS_FRIEND_API(void)
 js::VisitGrayWrapperTargets(Zone* zone, GCThingCallback callback, void* closure)
 {
     for (CompartmentsInZoneIter comp(zone); !comp.done(); comp.next()) {
-        for (JSCompartment::WrapperEnum e(comp); !e.empty(); e.popFront())
+        for (Compartment::WrapperEnum e(comp); !e.empty(); e.popFront())
             e.front().mutableKey().applyToWrapped(VisitGrayCallbackFunctor(callback, closure));
     }
 }
 
 JS_FRIEND_API(JSObject*)
 js::GetWeakmapKeyDelegate(JSObject* key)
 {
     if (JSWeakmapKeyDelegateOp op = key->getClass()->extWeakmapKeyDelegateOp())
--- a/js/src/jsfriendapi.h
+++ b/js/src/jsfriendapi.h
@@ -180,17 +180,17 @@ enum class JSUseCounter {
 
 typedef void
 (*JSSetUseCounterCallback)(JSObject* obj, JSUseCounter counter);
 
 extern JS_FRIEND_API(void)
 JS_SetSetUseCounterCallback(JSContext* cx, JSSetUseCounterCallback callback);
 
 extern JS_FRIEND_API(JSPrincipals*)
-JS_GetCompartmentPrincipals(JSCompartment* compartment);
+JS_GetCompartmentPrincipals(JS::Compartment* compartment);
 
 extern JS_FRIEND_API(JSPrincipals*)
 JS_GetScriptPrincipals(JSScript* script);
 
 namespace js {
 extern JS_FRIEND_API(JS::Realm*)
 GetScriptRealm(JSScript* script);
 } /* namespace js */
@@ -479,17 +479,17 @@ DumpHeap(JSContext* cx, FILE* fp, DumpHe
 JS_FRIEND_API(bool) obj_defineGetter(JSContext* cx, unsigned argc, JS::Value* vp);
 JS_FRIEND_API(bool) obj_defineSetter(JSContext* cx, unsigned argc, JS::Value* vp);
 #endif
 
 extern JS_FRIEND_API(bool)
 IsSystemRealm(JS::Realm* realm);
 
 extern JS_FRIEND_API(bool)
-IsSystemCompartment(JSCompartment* comp);
+IsSystemCompartment(JS::Compartment* comp);
 
 extern JS_FRIEND_API(bool)
 IsSystemZone(JS::Zone* zone);
 
 extern JS_FRIEND_API(bool)
 IsAtomsZone(JS::Zone* zone);
 
 struct WeakMapTracer
@@ -672,17 +672,17 @@ InheritanceProtoKeyForStandardClass(JSPr
 }
 
 JS_FRIEND_API(bool)
 IsFunctionObject(JSObject* obj);
 
 JS_FRIEND_API(bool)
 IsCrossCompartmentWrapper(JSObject* obj);
 
-static MOZ_ALWAYS_INLINE JSCompartment*
+static MOZ_ALWAYS_INLINE JS::Compartment*
 GetObjectCompartment(JSObject* obj)
 {
     JS::Realm* realm = reinterpret_cast<shadow::Object*>(obj)->group->realm;
     return JS::GetCompartmentForRealm(realm);
 }
 
 // CrossCompartmentWrappers are shared by all realms within the compartment, so
 // getting a wrapper's realm usually doesn't make sense.
@@ -1231,53 +1231,53 @@ typedef enum NukeReferencesFromTarget {
     NukeIncomingReferences,
 } NukeReferencesFromTarget;
 
 /*
  * These filters are designed to be ephemeral stack classes, and thus don't
  * do any rooting or holding of their members.
  */
 struct CompartmentFilter {
-    virtual bool match(JSCompartment* c) const = 0;
+    virtual bool match(JS::Compartment* c) const = 0;
 };
 
 struct AllCompartments : public CompartmentFilter {
-    virtual bool match(JSCompartment* c) const override { return true; }
+    virtual bool match(JS::Compartment* c) const override { return true; }
 };
 
 struct ContentCompartmentsOnly : public CompartmentFilter {
-    virtual bool match(JSCompartment* c) const override {
+    virtual bool match(JS::Compartment* c) const override {
         return !IsSystemCompartment(c);
     }
 };
 
 struct ChromeCompartmentsOnly : public CompartmentFilter {
-    virtual bool match(JSCompartment* c) const override {
+    virtual bool match(JS::Compartment* c) const override {
         return IsSystemCompartment(c);
     }
 };
 
 struct SingleCompartment : public CompartmentFilter {
-    JSCompartment* ours;
-    explicit SingleCompartment(JSCompartment* c) : ours(c) {}
-    virtual bool match(JSCompartment* c) const override { return c == ours; }
+    JS::Compartment* ours;
+    explicit SingleCompartment(JS::Compartment* c) : ours(c) {}
+    virtual bool match(JS::Compartment* c) const override { return c == ours; }
 };
 
 struct CompartmentsWithPrincipals : public CompartmentFilter {
     JSPrincipals* principals;
     explicit CompartmentsWithPrincipals(JSPrincipals* p) : principals(p) {}
-    virtual bool match(JSCompartment* c) const override {
+    virtual bool match(JS::Compartment* c) const override {
         return JS_GetCompartmentPrincipals(c) == principals;
     }
 };
 
 extern JS_FRIEND_API(bool)
 NukeCrossCompartmentWrappers(JSContext* cx,
                              const CompartmentFilter& sourceFilter,
-                             JSCompartment* target,
+                             JS::Compartment* target,
                              NukeReferencesToWindow nukeReferencesToWindow,
                              NukeReferencesFromTarget nukeReferencesFromTarget);
 
 /* Specify information about DOMProxy proxies in the DOM, for use by ICs. */
 
 /*
  * The DOMProxyShadowsCheck function will be called to check if the property for
  * id should be gotten from the prototype, or if there is an own property that
--- a/js/src/jspubtd.h
+++ b/js/src/jspubtd.h
@@ -81,17 +81,17 @@ class JSFlatString;
 
 template<typename T> struct JSConstScalarSpec;
 typedef JSConstScalarSpec<double> JSConstDoubleSpec;
 typedef JSConstScalarSpec<int32_t> JSConstIntegerSpec;
 
 namespace js {
 
 inline JS::Realm* GetContextRealm(const JSContext* cx);
-inline JSCompartment* GetContextCompartment(const JSContext* cx);
+inline JS::Compartment* GetContextCompartment(const JSContext* cx);
 inline JS::Zone* GetContextZone(const JSContext* cx);
 
 // Whether the current thread is permitted access to any part of the specified
 // runtime or zone.
 JS_FRIEND_API(bool)
 CurrentThreadCanAccessRuntime(const JSRuntime* rt);
 
 #ifdef DEBUG
--- a/js/src/proxy/CrossCompartmentWrapper.cpp
+++ b/js/src/proxy/CrossCompartmentWrapper.cpp
@@ -273,17 +273,17 @@ struct AutoCloseIterator
 
     void clear() { obj = nullptr; }
 
   private:
     Rooted<PropertyIteratorObject*> obj;
 };
 
 static JSObject*
-Reify(JSContext* cx, JSCompartment* origin, HandleObject objp)
+Reify(JSContext* cx, JS::Compartment* origin, HandleObject objp)
 {
     Rooted<PropertyIteratorObject*> iterObj(cx, &objp->as<PropertyIteratorObject>());
     NativeIterator* ni = iterObj->getNativeIterator();
 
     RootedObject obj(cx, ni->objectBeingIterated());
     {
         AutoCloseIterator close(cx, iterObj);
 
@@ -507,17 +507,17 @@ NukeRemovedCrossCompartmentWrapper(JSCon
     wrapper->as<ProxyObject>().nuke();
 
     MOZ_ASSERT(IsDeadProxyObject(wrapper));
 }
 
 JS_FRIEND_API(void)
 js::NukeCrossCompartmentWrapper(JSContext* cx, JSObject* wrapper)
 {
-    JSCompartment* comp = wrapper->compartment();
+    JS::Compartment* comp = wrapper->compartment();
     auto ptr = comp->lookupWrapper(Wrapper::wrappedObject(wrapper));
     if (ptr)
         comp->removeWrapper(ptr);
     NukeRemovedCrossCompartmentWrapper(cx, wrapper);
 }
 
 /*
  * NukeChromeCrossCompartmentWrappersForGlobal reaches into chrome and cuts
@@ -525,17 +525,17 @@ js::NukeCrossCompartmentWrapper(JSContex
  * obj's global.  The snag here is that we need to avoid cutting wrappers that
  * point to the window object on page navigation (inner window destruction)
  * and only do that on tab close (outer window destruction).  Thus the
  * option of how to handle the global object.
  */
 JS_FRIEND_API(bool)
 js::NukeCrossCompartmentWrappers(JSContext* cx,
                                  const CompartmentFilter& sourceFilter,
-                                 JSCompartment* target,
+                                 JS::Compartment* target,
                                  js::NukeReferencesToWindow nukeReferencesToWindow,
                                  js::NukeReferencesFromTarget nukeReferencesFromTarget)
 {
     CHECK_REQUEST(cx);
     JSRuntime* rt = cx->runtime();
 
     for (CompartmentsIter c(rt); !c.done(); c.next()) {
         if (!sourceFilter.match(c))
@@ -546,17 +546,17 @@ js::NukeCrossCompartmentWrappers(JSConte
         bool nukeAll = (nukeReferencesFromTarget == NukeAllReferences &&
                         target == c.get());
 
         // Iterate only the wrappers that have target compartment matched unless
         // |nukeAll| is true. The string wrappers that we're not interested in
         // won't be iterated, we can exclude them easily because they have
         // compartment nullptr. Use Maybe to avoid copying from conditionally
         // initializing NonStringWrapperEnum.
-        mozilla::Maybe<JSCompartment::NonStringWrapperEnum> e;
+        mozilla::Maybe<Compartment::NonStringWrapperEnum> e;
         if (MOZ_LIKELY(!nukeAll))
             e.emplace(c, target);
         else
             e.emplace(c);
         for (; !e->empty(); e->popFront()) {
             // Skip debugger references because NukeCrossCompartmentWrapper()
             // doesn't know how to nuke them yet, see bug 1084626 for more
             // information.
@@ -609,17 +609,17 @@ js::RemapWrapper(JSContext* cx, JSObject
     MOZ_ASSERT(wobj->is<CrossCompartmentWrapperObject>());
     MOZ_ASSERT(!newTarget->is<CrossCompartmentWrapperObject>());
     JSObject* origTarget = Wrapper::wrappedObject(wobj);
     MOZ_ASSERT(origTarget);
     MOZ_ASSERT(!JS_IsDeadWrapper(origTarget),
                "We don't want a dead proxy in the wrapper map");
     Value origv = ObjectValue(*origTarget);
     Realm* wrealm = wobj->realm();
-    JSCompartment* wcompartment = wobj->compartment();
+    JS::Compartment* wcompartment = wobj->compartment();
 
     AutoDisableProxyCheck adpc;
 
     // If we're mapping to a different target (as opposed to just recomputing
     // for the same target), we must not have an existing wrapper for the new
     // target, otherwise this will break.
     MOZ_ASSERT_IF(origTarget != newTarget,
                   !wcompartment->lookupWrapper(ObjectValue(*newTarget)));
@@ -706,17 +706,17 @@ js::RecomputeWrappers(JSContext* cx, con
             continue;
 
         if (!evictedNursery && c->hasNurseryAllocatedWrapperEntries(targetFilter)) {
             cx->runtime()->gc.evictNursery();
             evictedNursery = true;
         }
 
         // Iterate over the wrappers, filtering appropriately.
-        for (JSCompartment::NonStringWrapperEnum e(c, targetFilter); !e.empty(); e.popFront()) {
+        for (Compartment::NonStringWrapperEnum e(c, targetFilter); !e.empty(); e.popFront()) {
             // Filter out non-objects.
             CrossCompartmentKey& k = e.front().mutableKey();
             if (!k.is<JSObject*>())
                 continue;
 
             // Add it to the list.
             if (!toRecompute.append(WrapperValue(e)))
                 return false;
--- a/js/src/vm/Debugger.cpp
+++ b/js/src/vm/Debugger.cpp
@@ -2216,17 +2216,17 @@ Debugger::slowPathOnNewGlobalObject(JSCo
 /* static */ bool
 Debugger::slowPathOnLogAllocationSite(JSContext* cx, HandleObject obj, HandleSavedFrame frame,
                                       mozilla::TimeStamp when, GlobalObject::DebuggerVector& dbgs)
 {
     MOZ_ASSERT(!dbgs.empty());
     mozilla::DebugOnly<ReadBarriered<Debugger*>*> begin = dbgs.begin();
 
     // Root all the Debuggers while we're iterating over them;
-    // appendAllocationSite calls JSCompartment::wrap, and thus can GC.
+    // appendAllocationSite calls Compartment::wrap, and thus can GC.
     //
     // SpiderMonkey protocol is generally for the caller to prove that it has
     // rooted the stuff it's asking you to operate on (i.e. by passing a
     // Handle), but in this case, we're iterating over a global's list of
     // Debuggers, and globals only hold their Debuggers weakly.
     Rooted<GCVector<JSObject*>> activeDebuggers(cx, GCVector<JSObject*>(cx));
     for (auto dbgp = dbgs.begin(); dbgp < dbgs.end(); dbgp++) {
         if (!activeDebuggers.append((*dbgp)->object))
@@ -3271,17 +3271,17 @@ Debugger::findZoneEdges(Zone* zone, js::
                 Zone* debuggeeZone = e.front();
                 if (debuggeeZone->isGCMarking())
                     finder.addEdgeTo(debuggeeZone);
             }
         } else {
             /*
              * For debugger cross compartment wrappers, add edges in the
              * opposite direction to those already added by
-             * JSCompartment::findOutgoingEdges and above.  This ensure that
+             * Compartment::findOutgoingEdges and above.  This ensure that
              * debuggers and their debuggees are finalized in the same group.
              */
             if (dbg->debuggeeZones.has(zone) ||
                 dbg->scripts.hasKeyInZone(zone) ||
                 dbg->sources.hasKeyInZone(zone) ||
                 dbg->objects.hasKeyInZone(zone) ||
                 dbg->environments.hasKeyInZone(zone) ||
                 dbg->wasmInstanceScripts.hasKeyInZone(zone) ||
@@ -4867,17 +4867,17 @@ class MOZ_STACK_CLASS Debugger::ObjectQu
          * don't need to follow edges to or from this node, or (2) there does
          * exist some path from this non-debuggee node back to a node in our
          * debuggee compartments. However, if that were true, then the incoming
          * cross compartment edge back into a debuggee compartment is already
          * listed as an edge in the RootList we started traversal with, and
          * therefore we don't need to follow edges to or from this non-debuggee
          * node.
          */
-        JSCompartment* comp = referent.compartment();
+        JS::Compartment* comp = referent.compartment();
         if (comp && !debuggeeCompartments.has(comp)) {
             traversal.abandonReferent();
             return true;
         }
 
         /*
          * If the referent has an associated realm and it's not a debuggee
          * realm, skip it. Don't abandonReferent() here like above: realms
--- a/js/src/vm/Debugger.h
+++ b/js/src/vm/Debugger.h
@@ -122,17 +122,17 @@ class DebuggerWeakMap : private WeakMap<
     typedef HeapPtr<JSObject*> Value;
 
     typedef HashMap<JS::Zone*,
                     uintptr_t,
                     DefaultHasher<JS::Zone*>,
                     ZoneAllocPolicy> CountMap;
 
     CountMap zoneCounts;
-    JSCompartment* compartment;
+    JS::Compartment* compartment;
 
   public:
     typedef WeakMap<Key, Value, MovableCellHasher<Key>> Base;
 
     explicit DebuggerWeakMap(JSContext* cx)
         : Base(cx),
           zoneCounts(cx->zone()),
           compartment(cx->compartment())
@@ -985,17 +985,17 @@ class Debugger : private mozilla::Linked
 
     /*
      * Like cx->compartment()->wrap(cx, vp), but for the debugger realm.
      *
      * Preconditions: *vp is a value from a debuggee realm; cx is in the
      * debugger's compartment.
      *
      * If *vp is an object, this produces a (new or existing) Debugger.Object
-     * wrapper for it. Otherwise this is the same as JSCompartment::wrap.
+     * wrapper for it. Otherwise this is the same as Compartment::wrap.
      *
      * If *vp is a magic JS_OPTIMIZED_OUT value, this produces a plain object
      * of the form { optimizedOut: true }.
      *
      * If *vp is a magic JS_OPTIMIZED_ARGUMENTS value signifying missing
      * arguments, this produces a plain object of the form { missingArguments:
      * true }.
      *
@@ -1587,17 +1587,16 @@ class DebuggerObject : public NativeObje
 };
 
 class JSBreakpointSite;
 class WasmBreakpoint;
 class WasmBreakpointSite;
 
 class BreakpointSite {
     friend class Breakpoint;
-    friend struct ::JSCompartment;
     friend class ::JSScript;
     friend class Debugger;
 
   public:
     enum class Type { JS, Wasm };
 
   private:
     Type type_;
@@ -1650,17 +1649,16 @@ class BreakpointSite {
  * Debugger::hasAnyLiveHooks to check for rule 1.
  *
  * Nothing else causes a breakpoint to be retained, so if its script or
  * debugger is collected, the breakpoint is destroyed during GC sweep phase,
  * even if the debugger compartment isn't being GC'd. This is implemented in
  * Zone::sweepBreakpoints.
  */
 class Breakpoint {
-    friend struct ::JSCompartment;
     friend class Debugger;
     friend class BreakpointSite;
 
   public:
     Debugger * const debugger;
     BreakpointSite * const site;
   private:
     /* |handler| is marked unconditionally during minor GC. */
--- a/js/src/vm/Iteration.cpp
+++ b/js/src/vm/Iteration.cpp
@@ -622,26 +622,26 @@ CreatePropertyIterator(JSContext* cx, Ha
     RegisterEnumerator(realm, ni);
 
     return propIter;
 }
 
 /**
  * Initialize a sentinel NativeIterator whose purpose is only to act as the
  * start/end of the circular linked list of NativeIterators in
- * JSCompartment::enumerators.
+ * ObjectRealm::enumerators.
  */
 NativeIterator::NativeIterator()
 {
     // Do our best to enforce that nothing in |this| except the two fields set
     // below is ever observed.
     JS_POISON(static_cast<void*>(this), 0xCC, sizeof(*this), MemCheckKind::MakeUndefined);
 
     // These are the only two fields in sentinel NativeIterators that are
-    // examined, in JSCompartment::sweepNativeIterators.  Everything else is
+    // examined, in ObjectRealm::sweepNativeIterators.  Everything else is
     // only examined *if* it's a NativeIterator being traced by a
     // PropertyIteratorObject that owns it, and nothing owns this iterator.
     prev_ = next_ = this;
 }
 
 NativeIterator*
 NativeIterator::allocateSentinel(JSContext* maybecx)
 {
--- a/js/src/vm/Iteration.h
+++ b/js/src/vm/Iteration.h
@@ -86,17 +86,17 @@ struct NativeIterator
      * Despite being a constructor, THIS FUNCTION CAN REPORT ERRORS.  Users
      * MUST set |*hadError = false| on entry and consider |*hadError| on return
      * to mean this function failed.
      */
     NativeIterator(JSContext* cx, Handle<PropertyIteratorObject*> propIter,
                    Handle<JSObject*> objBeingIterated, const AutoIdVector& props,
                    uint32_t numGuards, uint32_t guardKey, bool* hadError);
 
-    /** Initialize a |JSCompartment::enumerators| sentinel. */
+    /** Initialize an |ObjectRealm::enumerators| sentinel. */
     NativeIterator();
 
     JSObject* objectBeingIterated() const {
         return objectBeingIterated_;
     }
 
     void changeObjectBeingIterated(JSObject& obj) {
         objectBeingIterated_ = &obj;
--- a/js/src/vm/JSCompartment-inl.h
+++ b/js/src/vm/JSCompartment-inl.h
@@ -83,17 +83,17 @@ js::AutoAtomsZone::~AutoAtomsZone()
     cx_->leaveAtomsZone(origin_, lock_);
 }
 
 js::AutoRealmUnchecked::AutoRealmUnchecked(JSContext* cx, JS::Realm* target)
   : AutoRealm(cx, target)
 {}
 
 inline bool
-JSCompartment::wrap(JSContext* cx, JS::MutableHandleValue vp)
+JS::Compartment::wrap(JSContext* cx, JS::MutableHandleValue vp)
 {
     /* Only GC things have to be wrapped or copied. */
     if (!vp.isGCThing())
         return true;
 
     /*
      * Symbols are GC things, but never need to be wrapped or copied because
      * they are always allocated in the atoms zone. They still need to be
--- a/js/src/vm/JSCompartment.cpp
+++ b/js/src/vm/JSCompartment.cpp
@@ -36,31 +36,31 @@
 #include "vm/UnboxedObject-inl.h"
 
 using namespace js;
 using namespace js::gc;
 using namespace js::jit;
 
 using mozilla::PodArrayZero;
 
-JSCompartment::JSCompartment(Zone* zone)
+Compartment::Compartment(Zone* zone)
   : zone_(zone),
     runtime_(zone->runtimeFromAnyThread())
 {}
 
 ObjectRealm::ObjectRealm(JS::Zone* zone)
   : innerViews(zone)
 {}
 
 ObjectRealm::~ObjectRealm()
 {
     MOZ_ASSERT(enumerators == iteratorSentinel_.get());
 }
 
-Realm::Realm(JSCompartment* comp, const JS::RealmOptions& options)
+Realm::Realm(Compartment* comp, const JS::RealmOptions& options)
   : JS::shadow::Realm(comp),
     zone_(comp->zone()),
     runtime_(comp->runtimeFromMainThread()),
     creationOptions_(options.creationOptions()),
     behaviors_(options.behaviors()),
     global_(nullptr),
     objects_(zone_),
     randomKeyGenerator_(runtime_->forkRandomKeyGenerator()),
@@ -89,17 +89,17 @@ Realm::~Realm()
         objectGroups_.unboxedLayouts.clear();
 #endif
 
     MOZ_ASSERT(runtime_->numRealms > 0);
     runtime_->numRealms--;
 }
 
 bool
-JSCompartment::init(JSContext* cx)
+Compartment::init(JSContext* cx)
 {
     if (!crossCompartmentWrappers.init(0)) {
         ReportOutOfMemory(cx);
         return false;
     }
 
     return true;
 }
@@ -210,17 +210,17 @@ js::DtoaCache::checkCacheAfterMovingGC()
 
 namespace {
 struct CheckGCThingAfterMovingGCFunctor {
     template <class T> void operator()(T* t) { CheckGCThingAfterMovingGC(*t); }
 };
 } // namespace (anonymous)
 
 void
-JSCompartment::checkWrapperMapAfterMovingGC()
+Compartment::checkWrapperMapAfterMovingGC()
 {
     /*
      * Assert that the postbarriers have worked and that nothing is left in
      * wrapperMap that points into the nursery, and that the hash table entries
      * are discoverable.
      */
     for (WrapperMap::Enum e(crossCompartmentWrappers); !e.empty(); e.popFront()) {
         e.front().mutableKey().applyToWrapped(CheckGCThingAfterMovingGCFunctor());
@@ -229,18 +229,18 @@ JSCompartment::checkWrapperMapAfterMovin
         WrapperMap::Ptr ptr = crossCompartmentWrappers.lookup(e.front().key());
         MOZ_RELEASE_ASSERT(ptr.found() && &*ptr == &e.front());
     }
 }
 
 #endif // JSGC_HASH_TABLE_CHECKS
 
 bool
-JSCompartment::putWrapper(JSContext* cx, const CrossCompartmentKey& wrapped,
-                          const js::Value& wrapper)
+Compartment::putWrapper(JSContext* cx, const CrossCompartmentKey& wrapped,
+                        const js::Value& wrapper)
 {
     MOZ_ASSERT(wrapped.is<JSString*>() == wrapper.isString());
     MOZ_ASSERT_IF(!wrapped.is<JSString*>(), wrapper.isObject());
 
     if (!crossCompartmentWrappers.put(wrapped, wrapper)) {
         ReportOutOfMemory(cx);
         return false;
     }
@@ -291,17 +291,17 @@ CopyStringPure(JSContext* cx, JSString* 
     ScopedJSFreePtr<char16_t> copiedChars;
     if (!str->asRope().copyTwoByteCharsZ(cx, copiedChars))
         return nullptr;
 
     return NewStringDontDeflate<CanGC>(cx, copiedChars.forget(), len);
 }
 
 bool
-JSCompartment::wrap(JSContext* cx, MutableHandleString strp)
+Compartment::wrap(JSContext* cx, MutableHandleString strp)
 {
     MOZ_ASSERT(cx->compartment() == this);
 
     /* If the string is already in this compartment, we are done. */
     JSString* str = strp;
     if (str->zoneFromAnyThread() == zone())
         return true;
 
@@ -329,33 +329,33 @@ JSCompartment::wrap(JSContext* cx, Mutab
         return false;
 
     strp.set(copy);
     return true;
 }
 
 #ifdef ENABLE_BIGINT
 bool
-JSCompartment::wrap(JSContext* cx, MutableHandleBigInt bi)
+Compartment::wrap(JSContext* cx, MutableHandleBigInt bi)
 {
     MOZ_ASSERT(cx->compartment() == this);
 
     if (bi->zone() == cx->zone())
         return true;
 
     BigInt* copy = BigInt::copy(cx, bi);
     if (!copy)
         return false;
     bi.set(copy);
     return true;
 }
 #endif
 
 bool
-JSCompartment::getNonWrapperObjectForCurrentCompartment(JSContext* cx, MutableHandleObject obj)
+Compartment::getNonWrapperObjectForCurrentCompartment(JSContext* cx, MutableHandleObject obj)
 {
     // Ensure that we have entered a compartment.
     MOZ_ASSERT(cx->global());
 
     // If we have a cross-compartment wrapper, make sure that the cx isn't
     // associated with the self-hosting global. We don't want to create
     // wrappers for objects in other runtimes, which may be the case for the
     // self-hosting global.
@@ -397,17 +397,17 @@ JSCompartment::getNonWrapperObjectForCur
             return false;
     }
     MOZ_ASSERT(!IsWindow(obj));
 
     return true;
 }
 
 bool
-JSCompartment::getOrCreateWrapper(JSContext* cx, HandleObject existing, MutableHandleObject obj)
+Compartment::getOrCreateWrapper(JSContext* cx, HandleObject existing, MutableHandleObject obj)
 {
     // If we already have a wrapper for this value, use it.
     RootedValue key(cx, ObjectValue(*obj));
     if (WrapperMap::Ptr p = crossCompartmentWrappers.lookup(CrossCompartmentKey(key))) {
         obj.set(&p->value().get().toObject());
         MOZ_ASSERT(obj->is<CrossCompartmentWrapperObject>());
         return true;
     }
@@ -437,17 +437,17 @@ JSCompartment::getOrCreateWrapper(JSCont
         return false;
     }
 
     obj.set(wrapper);
     return true;
 }
 
 bool
-JSCompartment::wrap(JSContext* cx, MutableHandleObject obj)
+Compartment::wrap(JSContext* cx, MutableHandleObject obj)
 {
     MOZ_ASSERT(cx->compartment() == this);
 
     if (!obj)
         return true;
 
     AutoDisableProxyCheck adpc;
 
@@ -468,17 +468,17 @@ JSCompartment::wrap(JSContext* cx, Mutab
     }
 
     // Ensure that the wrapper is also exposed.
     ExposeObjectToActiveJS(obj);
     return true;
 }
 
 bool
-JSCompartment::rewrap(JSContext* cx, MutableHandleObject obj, HandleObject existingArg)
+Compartment::rewrap(JSContext* cx, MutableHandleObject obj, HandleObject existingArg)
 {
     MOZ_ASSERT(cx->compartment() == this);
     MOZ_ASSERT(obj);
     MOZ_ASSERT(existingArg);
     MOZ_ASSERT(existingArg->compartment() == cx->compartment());
     MOZ_ASSERT(IsDeadProxyObject(existingArg));
 
     AutoDisableProxyCheck adpc;
@@ -504,17 +504,17 @@ JSCompartment::rewrap(JSContext* cx, Mut
     // not need to create or return an existing wrapper.
     if (obj->compartment() == this)
         return true;
 
     return getOrCreateWrapper(cx, existing, obj);
 }
 
 bool
-JSCompartment::wrap(JSContext* cx, MutableHandle<PropertyDescriptor> desc)
+Compartment::wrap(JSContext* cx, MutableHandle<PropertyDescriptor> desc)
 {
     if (!wrap(cx, desc.object()))
         return false;
 
     if (desc.hasGetterObject()) {
         if (!wrap(cx, desc.getterObject()))
             return false;
     }
@@ -522,17 +522,17 @@ JSCompartment::wrap(JSContext* cx, Mutab
         if (!wrap(cx, desc.setterObject()))
             return false;
     }
 
     return wrap(cx, desc.value());
 }
 
 bool
-JSCompartment::wrap(JSContext* cx, MutableHandle<GCVector<Value>> vec)
+Compartment::wrap(JSContext* cx, MutableHandle<GCVector<Value>> vec)
 {
     for (size_t i = 0; i < vec.length(); ++i) {
         if (!wrap(cx, vec[i]))
             return false;
     }
     return true;
 }
 
@@ -607,17 +607,17 @@ Realm::addToVarNames(JSContext* cx, JS::
     if (varNames_.put(name))
         return true;
 
     ReportOutOfMemory(cx);
     return false;
 }
 
 void
-JSCompartment::traceOutgoingCrossCompartmentWrappers(JSTracer* trc)
+Compartment::traceOutgoingCrossCompartmentWrappers(JSTracer* trc)
 {
     MOZ_ASSERT(JS::CurrentThreadIsHeapMajorCollecting());
     MOZ_ASSERT(!zone()->isCollectingFromAnyThread() || trc->runtime()->gc.isHeapCompacting());
 
     for (NonStringWrapperEnum e(this); !e.empty(); e.popFront()) {
         if (e.front().key().is<JSObject*>()) {
             Value v = e.front().value().unbarrieredGet();
             ProxyObject* wrapper = &v.toObject().as<ProxyObject>();
@@ -627,17 +627,17 @@ JSCompartment::traceOutgoingCrossCompart
              * point into the compartment being collected, so we should mark it.
              */
             ProxyObject::traceEdgeToTarget(trc, wrapper);
         }
     }
 }
 
 /* static */ void
-JSCompartment::traceIncomingCrossCompartmentEdgesForZoneGC(JSTracer* trc)
+Compartment::traceIncomingCrossCompartmentEdgesForZoneGC(JSTracer* trc)
 {
     gcstats::AutoPhase ap(trc->runtime()->gc.stats(), gcstats::PhaseKind::MARK_CCWS);
     MOZ_ASSERT(JS::CurrentThreadIsHeapMajorCollecting());
     for (CompartmentsIter c(trc->runtime()); !c.done(); c.next()) {
         if (!c->zone()->isCollecting())
             c->traceOutgoingCrossCompartmentWrappers(trc);
     }
     Debugger::traceIncomingCrossCompartmentEdges(trc);
@@ -762,17 +762,17 @@ void
 Realm::sweepAfterMinorGC()
 {
     globalWriteBarriered = 0;
     dtoaCache.purge();
     objects_.sweepAfterMinorGC();
 }
 
 void
-JSCompartment::sweepAfterMinorGC(JSTracer* trc)
+Compartment::sweepAfterMinorGC(JSTracer* trc)
 {
     crossCompartmentWrappers.sweepAfterMinorGC(trc);
 
     for (RealmsInCompartmentIter r(this); !r.done(); r.next())
         r->sweepAfterMinorGC();
 }
 
 void
@@ -846,17 +846,17 @@ Realm::sweepObjectRealm()
 }
 
 /*
  * Remove dead wrappers from the table. We must sweep all compartments, since
  * string entries in the crossCompartmentWrappers table are not marked during
  * markCrossCompartmentWrappers.
  */
 void
-JSCompartment::sweepCrossCompartmentWrappers()
+Compartment::sweepCrossCompartmentWrappers()
 {
     crossCompartmentWrappers.sweep();
 }
 
 void
 Realm::sweepVarNames()
 {
     varNames_.sweep();
@@ -897,17 +897,17 @@ Realm::sweepTemplateObjects()
     if (unmappedArgumentsTemplate_ && IsAboutToBeFinalized(&unmappedArgumentsTemplate_))
         unmappedArgumentsTemplate_.set(nullptr);
 
     if (iterResultTemplate_ && IsAboutToBeFinalized(&iterResultTemplate_))
         iterResultTemplate_.set(nullptr);
 }
 
 /* static */ void
-JSCompartment::fixupCrossCompartmentWrappersAfterMovingGC(JSTracer* trc)
+Compartment::fixupCrossCompartmentWrappersAfterMovingGC(JSTracer* trc)
 {
     MOZ_ASSERT(trc->runtime()->gc.isHeapCompacting());
 
     for (CompartmentsIter comp(trc->runtime()); !comp.done(); comp.next()) {
         // Sweep the wrapper map to update keys (wrapped values) in other
         // compartments that may have been moved.
         comp->sweepCrossCompartmentWrappers();
         // Trace the wrappers in the map to update their cross-compartment edges
@@ -921,17 +921,17 @@ Realm::fixupAfterMovingGC()
 {
     purge();
     fixupGlobal();
     objectGroups_.fixupTablesAfterMovingGC();
     fixupScriptMapsAfterMovingGC();
 }
 
 void
-JSCompartment::fixupAfterMovingGC()
+Compartment::fixupAfterMovingGC()
 {
     MOZ_ASSERT(zone()->isGCCompacting());
 
     for (RealmsInCompartmentIter r(this); !r.done(); r.next())
         r->fixupAfterMovingGC();
 
     // Sweep the wrapper map to update values (wrapper objects) in this
     // compartment that may have been moved.
@@ -1305,20 +1305,20 @@ Realm::clearBreakpointsIn(FreeOp* fop, j
 {
     for (auto script = zone()->cellIter<JSScript>(); !script.done(); script.next()) {
         if (script->realm() == this && script->hasAnyBreakpointsOrStepMode())
             script->clearBreakpointsIn(fop, dbg, handler);
     }
 }
 
 void
-JSCompartment::addSizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf,
-                                      size_t* compartmentObjects,
-                                      size_t* crossCompartmentWrappersTables,
-                                      size_t* compartmentsPrivateData)
+Compartment::addSizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf,
+                                    size_t* compartmentObjects,
+                                    size_t* crossCompartmentWrappersTables,
+                                    size_t* compartmentsPrivateData)
 {
     *compartmentObjects += mallocSizeOf(this);
     *crossCompartmentWrappersTables += crossCompartmentWrappers.sizeOfExcludingThis(mallocSizeOf);
 
     if (auto callback = runtime_->sizeOfIncludingThisCompartmentCallback)
         *compartmentsPrivateData += callback(mallocSizeOf, this);
 }
 
--- a/js/src/vm/JSCompartment.h
+++ b/js/src/vm/JSCompartment.h
@@ -183,21 +183,21 @@ class CrossCompartmentKey
             ReturnType match(JSObject*& obj) { return ReturnType(); }
             ReturnType match(JSString*& str) { return ReturnType(); }
             ReturnType match(DebuggerAndScript& tpl) { return f_(&mozilla::Get<0>(tpl)); }
             ReturnType match(DebuggerAndObject& tpl) { return f_(&mozilla::Get<0>(tpl)); }
         } matcher(f);
         return wrapped.match(matcher);
     }
 
-    JSCompartment* compartment() {
+    JS::Compartment* compartment() {
         struct GetCompartmentFunctor {
-            JSCompartment* operator()(JSObject** tp) const { return (*tp)->compartment(); }
-            JSCompartment* operator()(JSScript** tp) const { return (*tp)->compartment(); }
-            JSCompartment* operator()(JSString** tp) const { return nullptr; }
+            JS::Compartment* operator()(JSObject** tp) const { return (*tp)->compartment(); }
+            JS::Compartment* operator()(JSScript** tp) const { return (*tp)->compartment(); }
+            JS::Compartment* operator()(JSString** tp) const { return nullptr; }
         };
         return applyToWrapped(GetCompartmentFunctor());
     }
 
     struct Hasher : public DefaultHasher<CrossCompartmentKey>
     {
         struct HashFunctor {
             HashNumber match(JSObject* obj) { return DefaultHasher<JSObject*>::hash(obj); }
@@ -245,19 +245,19 @@ class CrossCompartmentKey
 class WrapperMap
 {
     static const size_t InitialInnerMapSize = 4;
 
     using InnerMap = NurseryAwareHashMap<CrossCompartmentKey,
                                          JS::Value,
                                          CrossCompartmentKey::Hasher,
                                          SystemAllocPolicy>;
-    using OuterMap = GCHashMap<JSCompartment*,
+    using OuterMap = GCHashMap<JS::Compartment*,
                                InnerMap,
-                               DefaultHasher<JSCompartment*>,
+                               DefaultHasher<JS::Compartment*>,
                                SystemAllocPolicy>;
 
     OuterMap map;
 
   public:
     class Enum
     {
       public:
@@ -269,17 +269,17 @@ class WrapperMap
       private:
         Enum(const Enum&) = delete;
         void operator=(const Enum&) = delete;
 
         void goToNext() {
             if (outer.isNothing())
                 return;
             for (; !outer->empty(); outer->popFront()) {
-                JSCompartment* c = outer->front().key();
+                JS::Compartment* c = outer->front().key();
                 // Need to skip string at first, because the filter may not be
                 // happy with a nullptr.
                 if (!c && skipStrings)
                     continue;
                 if (filter && !filter->match(c))
                     continue;
                 InnerMap& m = outer->front().value();
                 if (!m.empty()) {
@@ -305,17 +305,17 @@ class WrapperMap
         }
 
         Enum(WrapperMap& m, const CompartmentFilter& f, SkipStrings s = WithStrings) :
                 filter(&f), skipStrings(s) {
             outer.emplace(m.map);
             goToNext();
         }
 
-        Enum(WrapperMap& m, JSCompartment* target) {
+        Enum(WrapperMap& m, JS::Compartment* target) {
             // Leave the outer map as nothing and only iterate the inner map we
             // find here.
             auto p = m.map.lookup(target);
             if (p)
                 inner.emplace(p->value());
         }
 
         bool empty() const {
@@ -377,17 +377,17 @@ class WrapperMap
     }
 
     void remove(Ptr p) {
         if (p)
             p.map->remove(p);
     }
 
     MOZ_MUST_USE bool put(const CrossCompartmentKey& k, const JS::Value& v) {
-        JSCompartment* c = const_cast<CrossCompartmentKey&>(k).compartment();
+        JS::Compartment* c = const_cast<CrossCompartmentKey&>(k).compartment();
         MOZ_ASSERT(k.is<JSString*>() == !c);
         auto p = map.lookupForAdd(c);
         if (!p) {
             InnerMap m;
             if (!m.init(InitialInnerMapSize) || !map.add(p, c, std::move(m)))
                 return false;
         }
         return p->value().put(k, v);
@@ -403,17 +403,17 @@ class WrapperMap
         size_t size = map.sizeOfIncludingThis(mallocSizeOf);
         for (OuterMap::Enum e(map); !e.empty(); e.popFront())
             size += e.front().value().sizeOfIncludingThis(mallocSizeOf);
         return size;
     }
 
     bool hasNurseryAllocatedWrapperEntries(const CompartmentFilter& f) {
         for (OuterMap::Enum e(map); !e.empty(); e.popFront()) {
-            JSCompartment* c = e.front().key();
+            JS::Compartment* c = e.front().key();
             if (c && !f.match(c))
                 continue;
             InnerMap& m = e.front().value();
             if (m.hasNurseryEntries())
                 return true;
         }
         return false;
     }
@@ -545,17 +545,17 @@ struct IteratorHashPolicy
 } /* namespace js */
 
 namespace js {
 class DebugEnvironments;
 class ObjectWeakMap;
 class WeakMapBase;
 } // namespace js
 
-struct JSCompartment
+struct JS::Compartment
 {
   private:
     JS::Zone*                    zone_;
     JSRuntime*                   runtime_;
 
     js::WrapperMap crossCompartmentWrappers;
 
     using RealmVector = js::Vector<JS::Realm*, 1, js::SystemAllocPolicy>;
@@ -622,17 +622,17 @@ struct JSCompartment
     void checkWrapperMapAfterMovingGC();
 #endif
 
   private:
     bool getNonWrapperObjectForCurrentCompartment(JSContext* cx, js::MutableHandleObject obj);
     bool getOrCreateWrapper(JSContext* cx, js::HandleObject existing, js::MutableHandleObject obj);
 
   public:
-    explicit JSCompartment(JS::Zone* zone);
+    explicit Compartment(JS::Zone* zone);
 
     MOZ_MUST_USE bool init(JSContext* cx);
     void destroy(js::FreeOp* fop);
 
     MOZ_MUST_USE inline bool wrap(JSContext* cx, JS::MutableHandleValue vp);
 
     MOZ_MUST_USE bool wrap(JSContext* cx, js::MutableHandleString strp);
 #ifdef ENABLE_BIGINT
@@ -658,27 +658,39 @@ struct JSCompartment
         crossCompartmentWrappers.remove(p);
     }
 
     bool hasNurseryAllocatedWrapperEntries(const js::CompartmentFilter& f) {
         return crossCompartmentWrappers.hasNurseryAllocatedWrapperEntries(f);
     }
 
     struct WrapperEnum : public js::WrapperMap::Enum {
-        explicit WrapperEnum(JSCompartment* c) : js::WrapperMap::Enum(c->crossCompartmentWrappers) {}
+        explicit WrapperEnum(JS::Compartment* c)
+          : js::WrapperMap::Enum(c->crossCompartmentWrappers)
+        {}
     };
 
     struct NonStringWrapperEnum : public js::WrapperMap::Enum {
-        explicit NonStringWrapperEnum(JSCompartment* c) : js::WrapperMap::Enum(c->crossCompartmentWrappers, WithoutStrings) {}
-        explicit NonStringWrapperEnum(JSCompartment* c, const js::CompartmentFilter& f) : js::WrapperMap::Enum(c->crossCompartmentWrappers, f, WithoutStrings) {}
-        explicit NonStringWrapperEnum(JSCompartment* c, JSCompartment* target) : js::WrapperMap::Enum(c->crossCompartmentWrappers, target) { MOZ_ASSERT(target); }
+        explicit NonStringWrapperEnum(JS::Compartment* c)
+          : js::WrapperMap::Enum(c->crossCompartmentWrappers, WithoutStrings)
+        {}
+        explicit NonStringWrapperEnum(JS::Compartment* c, const js::CompartmentFilter& f)
+          : js::WrapperMap::Enum(c->crossCompartmentWrappers, f, WithoutStrings)
+        {}
+        explicit NonStringWrapperEnum(JS::Compartment* c, JS::Compartment* target)
+          : js::WrapperMap::Enum(c->crossCompartmentWrappers, target)
+        {
+            MOZ_ASSERT(target);
+        }
     };
 
     struct StringWrapperEnum : public js::WrapperMap::Enum {
-        explicit StringWrapperEnum(JSCompartment* c) : js::WrapperMap::Enum(c->crossCompartmentWrappers, nullptr) {}
+        explicit StringWrapperEnum(JS::Compartment* c)
+          : js::WrapperMap::Enum(c->crossCompartmentWrappers, nullptr)
+        {}
     };
 
     /*
      * These methods mark pointers that cross compartment boundaries. They are
      * called in per-zone GCs to prevent the wrappers' outgoing edges from
      * dangling (full GCs naturally follow pointers across compartments) and
      * when compacting to update cross-compartment pointers.
      */
@@ -833,17 +845,17 @@ class JS::Realm : public JS::shadow::Rea
     //     code.
     //
     // This field only accounts for (1), to keep the JIT code as simple as
     // possible.
     //
     // An important invariant is that the JIT can only switch to a different
     // realm within the same compartment, so whenever that happens there must
     // always be a same-compartment realm with enterRealmDepthIgnoringJit_ > 0.
-    // This lets us set JSCompartment::hasEnteredRealm without walking the
+    // This lets us set Compartment::hasEnteredRealm without walking the
     // stack.
     unsigned enterRealmDepthIgnoringJit_ = 0;
 
     enum {
         IsDebuggee = 1 << 0,
         DebuggerObservesAllExecution = 1 << 1,
         DebuggerObservesAsmJS = 1 << 2,
         DebuggerObservesCoverage = 1 << 3,
@@ -907,17 +919,17 @@ class JS::Realm : public JS::shadow::Rea
 
   private:
     void updateDebuggerObservesFlag(unsigned flag);
 
     Realm(const Realm&) = delete;
     void operator=(const Realm&) = delete;
 
   public:
-    Realm(JSCompartment* comp, const JS::RealmOptions& options);
+    Realm(JS::Compartment* comp, const JS::RealmOptions& options);
     ~Realm();
 
     MOZ_MUST_USE bool init(JSContext* cx);
     void destroy(js::FreeOp* fop);
     void clearTables();
 
     void addSizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf,
                                 size_t* tiAllocationSiteTables,
--- a/js/src/vm/JSContext-inl.h
+++ b/js/src/vm/JSContext-inl.h
@@ -17,44 +17,44 @@
 #include "vm/Iteration.h"
 #include "vm/JSCompartment.h"
 #include "vm/SymbolType.h"
 
 namespace js {
 
 class CompartmentChecker
 {
-    JSCompartment* compartment;
+    JS::Compartment* compartment;
 
   public:
     explicit CompartmentChecker(JSContext* cx)
       : compartment(cx->compartment())
     {
     }
 
     /*
      * Set a breakpoint here (break js::CompartmentChecker::fail) to debug
      * compartment mismatches.
      */
-    static void fail(JSCompartment* c1, JSCompartment* c2) {
+    static void fail(JS::Compartment* c1, JS::Compartment* c2) {
         printf("*** Compartment mismatch %p vs. %p\n", (void*) c1, (void*) c2);
         MOZ_CRASH();
     }
 
     static void fail(JS::Zone* z1, JS::Zone* z2) {
         printf("*** Zone mismatch %p vs. %p\n", (void*) z1, (void*) z2);
         MOZ_CRASH();
     }
 
-    static void check(JSCompartment* c1, JSCompartment* c2) {
+    static void check(JS::Compartment* c1, JS::Compartment* c2) {
         if (c1 != c2)
             fail(c1, c2);
     }
 
-    void check(JSCompartment* c) {
+    void check(JS::Compartment* c) {
         if (c && c != compartment)
             fail(compartment, c);
     }
 
     void checkZone(JS::Zone* z) {
         if (compartment && z != compartment->zone())
             fail(compartment->zone(), z);
     }
--- a/js/src/vm/JSContext.h
+++ b/js/src/vm/JSContext.h
@@ -222,17 +222,17 @@ struct JSContext : public JS::RootingCon
     void setHelperThread(js::HelperThread* helperThread);
     js::HelperThread* helperThread() const { return helperThread_; }
 
     bool isNurseryAllocSuppressed() const {
         return nurserySuppressions_;
     }
 
     // Threads may freely access any data in their realm, compartment and zone.
-    JSCompartment* compartment() const {
+    JS::Compartment* compartment() const {
         return realm_ ? JS::GetCompartmentForRealm(realm_) : nullptr;
     }
 
     JS::Realm* realm() const {
         return realm_;
     }
 
 #ifdef DEBUG
--- a/js/src/vm/JSFunction.cpp
+++ b/js/src/vm/JSFunction.cpp
@@ -2097,17 +2097,17 @@ js::NewFunctionWithProto(JSContext* cx, 
     if (allocKind == AllocKind::FUNCTION_EXTENDED)
         fun->initializeExtended();
     fun->initAtom(atom);
 
     return fun;
 }
 
 bool
-js::CanReuseScriptForClone(JSCompartment* compartment, HandleFunction fun,
+js::CanReuseScriptForClone(JS::Compartment* compartment, HandleFunction fun,
                            HandleObject newParent)
 {
     MOZ_ASSERT(fun->isInterpreted());
 
     if (compartment != fun->compartment() ||
         fun->isSingleton() ||
         ObjectGroup::useSingletonForClone(fun))
     {
--- a/js/src/vm/JSFunction.h
+++ b/js/src/vm/JSFunction.h
@@ -926,17 +926,17 @@ class FunctionExtended : public JSFuncti
   private:
     friend class JSFunction;
 
     /* Reserved slots available for storage by particular native functions. */
     GCPtrValue extendedSlots[NUM_EXTENDED_SLOTS];
 };
 
 extern bool
-CanReuseScriptForClone(JSCompartment* compartment, HandleFunction fun, HandleObject newParent);
+CanReuseScriptForClone(JS::Compartment* compartment, HandleFunction fun, HandleObject newParent);
 
 extern JSFunction*
 CloneFunctionReuseScript(JSContext* cx, HandleFunction fun, HandleObject parent,
                          gc::AllocKind kind = gc::AllocKind::FUNCTION,
                          NewObjectKind newKindArg = GenericObject,
                          HandleObject proto = nullptr);
 
 // Functions whose scripts are cloned are always given singleton types.
--- a/js/src/vm/JSObject.h
+++ b/js/src/vm/JSObject.h
@@ -155,18 +155,18 @@ class JSObject : public js::gc::Cell
     /*
      * Whether the object's group has not been constructed yet. If an object
      * might have a lazy group, use getGroup() below, otherwise group().
      */
     bool hasLazyGroup() const {
         return group_->lazy();
     }
 
-    JSCompartment* compartment() const { return group_->compartment(); }
-    JSCompartment* maybeCompartment() const { return compartment(); }
+    JS::Compartment* compartment() const { return group_->compartment(); }
+    JS::Compartment* maybeCompartment() const { return compartment(); }
     JS::Realm* realm() const { return group_->realm(); }
 
     inline js::Shape* maybeShape() const;
     inline js::Shape* ensureShape(JSContext* cx);
 
     enum GenerateShape {
         GENERATE_NONE,
         GENERATE_SHAPE
@@ -1323,17 +1323,17 @@ SpeciesConstructor(JSContext* cx, Handle
                    bool (*isDefaultSpecies)(JSContext*, JSFunction*));
 
 extern bool
 GetObjectFromIncumbentGlobal(JSContext* cx, MutableHandleObject obj);
 
 
 #ifdef DEBUG
 inline bool
-IsObjectValueInCompartment(const Value& v, JSCompartment* comp)
+IsObjectValueInCompartment(const Value& v, JS::Compartment* comp)
 {
     if (!v.isObject())
         return true;
     return v.toObject().compartment() == comp;
 }
 #endif
 
 }  /* namespace js */
--- a/js/src/vm/JSScript.h
+++ b/js/src/vm/JSScript.h
@@ -1119,20 +1119,20 @@ class JSScript : public js::gc::TenuredC
         bool uninlineable_ : 1;
 
         // Idempotent cache has triggered invalidation.
         bool invalidatedIdempotentCache_ : 1;
 
         // Lexical check did fail and bail out.
         bool failedLexicalCheck_ : 1;
 
-        // Script has an entry in JSCompartment::scriptCountsMap.
+        // Script has an entry in Realm::scriptCountsMap.
         bool hasScriptCounts_ : 1;
 
-        // Script has an entry in JSCompartment::debugScriptMap.
+        // Script has an entry in Realm::debugScriptMap.
         bool hasDebugScript_ : 1;
 
         // Freeze constraints for stack type sets have been generated.
         bool hasFreezeConstraints_ : 1;
 
         /* See comments below. */
         bool argsHasVarBinding_ : 1;
         bool needsArgsAnalysis_ : 1;
@@ -1245,18 +1245,18 @@ class JSScript : public js::gc::TenuredC
   private:
     // Assert that jump targets are within the code array of the script.
     void assertValidJumpTargets() const;
 #endif
 
   public:
     inline JSPrincipals* principals();
 
-    JSCompartment* compartment() const { return JS::GetCompartmentForRealm(realm_); }
-    JSCompartment* maybeCompartment() const { return compartment(); }
+    JS::Compartment* compartment() const { return JS::GetCompartmentForRealm(realm_); }
+    JS::Compartment* maybeCompartment() const { return compartment(); }
     JS::Realm* realm() const { return realm_; }
 
     js::SharedScriptData* scriptData() {
         return scriptData_;
     }
 
     // Script bytecode is immutable after creation.
     jsbytecode* code() const {
--- a/js/src/vm/ObjectGroup.h
+++ b/js/src/vm/ObjectGroup.h
@@ -228,18 +228,18 @@ class ObjectGroup : public gc::TenuredCe
     }
 
     bool lazy() const {
         bool res = flagsDontCheckGeneration() & OBJECT_FLAG_LAZY_SINGLETON;
         MOZ_ASSERT_IF(res, singleton());
         return res;
     }
 
-    JSCompartment* compartment() const { return JS::GetCompartmentForRealm(realm_); }
-    JSCompartment* maybeCompartment() const { return compartment(); }
+    JS::Compartment* compartment() const { return JS::GetCompartmentForRealm(realm_); }
+    JS::Compartment* maybeCompartment() const { return compartment(); }
     JS::Realm* realm() const { return realm_; }
 
   public:
     // Kinds of addendums which can be attached to ObjectGroups.
     enum AddendumKind {
         Addendum_None,
 
         // When used by interpreted function, the addendum stores the
--- a/js/src/vm/Runtime.h
+++ b/js/src/vm/Runtime.h
@@ -918,17 +918,17 @@ struct JSRuntime : public js::MallocProv
     friend class JS::AutoEnterCycleCollection;
 
   private:
     js::MainThreadData<js::RuntimeCaches> caches_;
   public:
     js::RuntimeCaches& caches() { return caches_.ref(); }
 
     // List of all the live wasm::Instances in the runtime. Equal to the union
-    // of all instances registered in all JSCompartments. Accessed from watchdog
+    // of all instances registered in all JS::Realms. Accessed from watchdog
     // threads for purposes of wasm::InterruptRunningCode().
     js::ExclusiveData<js::wasm::InstanceVector> wasmInstances;
 
     // The implementation-defined abstract operation HostResolveImportedModule.
     js::MainThreadData<JS::ModuleResolveHook> moduleResolveHook;
 
     // A hook that implements the abstract operations
     // HostGetImportMetaProperties and HostFinalizeImportMeta.
--- a/js/src/vm/Stack.cpp
+++ b/js/src/vm/Stack.cpp
@@ -926,17 +926,17 @@ FrameIter::rawFramePtr() const
         if (isJSJit())
             return jsJitFrame().fp();
         MOZ_ASSERT(isWasm());
         return nullptr;
     }
     MOZ_CRASH("Unexpected state");
 }
 
-JSCompartment*
+JS::Compartment*
 FrameIter::compartment() const
 {
     switch (data_.state_) {
       case DONE:
         break;
       case INTERP:
       case JIT:
         return data_.activations_->compartment();
--- a/js/src/vm/Stack.h
+++ b/js/src/vm/Stack.h
@@ -72,17 +72,17 @@ class Instance;
 // VM stack layout
 //
 // A JSRuntime's stack consists of a linked list of activations. Every activation
 // contains a number of scripted frames that are either running in the interpreter
 // (InterpreterActivation) or JIT code (JitActivation). The frames inside a single
 // activation are contiguous: whenever C++ calls back into JS, a new activation is
 // pushed.
 //
-// Every activation is tied to a single JSContext and JSCompartment. This means we
+// Every activation is tied to a single JSContext and JS::Compartment. This means we
 // can reconstruct a given context's stack by skipping activations belonging to other
 // contexts. This happens whenever an embedding enters the JS engine on cx1 and
 // then, from a native called by the JS engine, reenters the VM on cx2.
 
 // Interpreter frames (InterpreterFrame)
 //
 // Each interpreter script activation (global or function code) is given a
 // fixed-size header (js::InterpreterFrame). The frame contains bookkeeping
@@ -1378,17 +1378,17 @@ static_assert(sizeof(LiveSavedFrameCache
 /*****************************************************************************/
 
 class InterpreterActivation;
 
 namespace jit {
     class JitActivation;
 } // namespace jit
 
-// This class is separate from Activation, because it calls JSCompartment::wrap()
+// This class is separate from Activation, because it calls Compartment::wrap()
 // which can GC and walk the stack. It's not safe to do that within the
 // JitActivation constructor.
 class MOZ_RAII ActivationEntryMonitor
 {
     JSContext* cx_;
 
     // The entry point monitor that was set on cx_->runtime() when this
     // ActivationEntryMonitor was created.
@@ -1406,17 +1406,17 @@ class MOZ_RAII ActivationEntryMonitor
     ActivationEntryMonitor(JSContext* cx, jit::CalleeToken entryToken);
     inline ~ActivationEntryMonitor();
 };
 
 class Activation
 {
   protected:
     JSContext* cx_;
-    JSCompartment* compartment_;
+    JS::Compartment* compartment_;
     Activation* prev_;
     Activation* prevProfiling_;
 
     // Counter incremented by JS::HideScriptedCaller and decremented by
     // JS::UnhideScriptedCaller. If > 0 for the top activation,
     // DescribeScriptedCaller will return null instead of querying that
     // activation, which should prompt the caller to consult embedding-specific
     // data structures instead.
@@ -1446,17 +1446,17 @@ class Activation
 
     inline Activation(JSContext* cx, Kind kind);
     inline ~Activation();
 
   public:
     JSContext* cx() const {
         return cx_;
     }
-    JSCompartment* compartment() const {
+    JS::Compartment* compartment() const {
         return compartment_;
     }
     Activation* prev() const {
         return prev_;
     }
     Activation* prevProfiling() const { return prevProfiling_; }
     inline Activation* mostRecentProfiling();
 
@@ -2047,17 +2047,17 @@ class FrameIter
 
     // -------------------------------------------------------
     // The following functions can only be called when !done()
     // -------------------------------------------------------
 
     FrameIter& operator++();
 
     JS::Realm* realm() const;
-    JSCompartment* compartment() const;
+    JS::Compartment* compartment() const;
     Activation* activation() const { return data_.activations_.activation(); }
 
     bool isInterp() const {
         MOZ_ASSERT(!done());
         return data_.state_ == INTERP;
     }
     bool isJSJit() const {
         MOZ_ASSERT(!done());
--- a/js/src/vm/Stopwatch.cpp
+++ b/js/src/vm/Stopwatch.cpp
@@ -231,17 +231,17 @@ AutoStopwatch::AutoStopwatch(JSContext* 
   , iteration_(0)
   , isMonitoringJank_(false)
   , isMonitoringCPOW_(false)
   , cyclesStart_(0)
   , CPOWTimeStart_(0)
 {
     MOZ_GUARD_OBJECT_NOTIFIER_INIT;
 
-    JSCompartment* compartment = cx_->compartment();
+    JS::Compartment* compartment = cx_->compartment();
     if (MOZ_UNLIKELY(compartment->gcState.scheduledForDestruction))
         return;
 
     JSRuntime* runtime = cx_->runtime();
     iteration_ = runtime->performanceMonitoring().iteration();
 
     const PerformanceGroupVector* groups = cx_->realm()->performanceMonitoring.getGroups(cx);
     if (!groups) {
@@ -270,17 +270,17 @@ AutoStopwatch::AutoStopwatch(JSContext* 
 
 AutoStopwatch::~AutoStopwatch()
 {
     if (groups_.length() == 0) {
         // We are not in charge of monitoring anything.
         return;
     }
 
-    JSCompartment* compartment = cx_->compartment();
+    JS::Compartment* compartment = cx_->compartment();
     if (MOZ_UNLIKELY(compartment->gcState.scheduledForDestruction))
         return;
 
     JSRuntime* runtime = cx_->runtime();
     if (MOZ_UNLIKELY(iteration_ != runtime->performanceMonitoring().iteration())) {
         // We have entered a nested event loop at some point.
         // Any information we may have is obsolete.
         return;
--- a/js/src/vm/Stopwatch.h
+++ b/js/src/vm/Stopwatch.h
@@ -23,18 +23,18 @@ namespace js {
  * A container for performance groups.
  *
  * Performance monitoring deals with the execution duration of code
  * that belongs to components, for a notion of components defined by
  * the embedding.  Typically, in a web browser, a component may be a
  * webpage and/or a frame and/or a module and/or an add-on and/or a
  * sandbox and/or a process etc.
  *
- * A PerformanceGroupHolder is owned y a JSCompartment and maps that
- * compartment to all the components to which it belongs.
+ * A PerformanceGroupHolder is owned by a JS::Realm and maps that realm
+ * to all the components to which it belongs.
  */
 struct PerformanceGroupHolder {
 
     /**
      * Get the groups to which this compartment belongs.
      *
      * Pre-condition: Execution must have entered the compartment.
      *
@@ -190,17 +190,17 @@ struct PerformanceMonitoring {
         stopwatchStartClosure = closure;
     }
     void setStopwatchCommitCallback(js::StopwatchCommitCallback cb, void* closure) {
         stopwatchCommitCallback = cb;
         stopwatchCommitClosure = closure;
     }
 
     /**
-     * Callback called to associate a JSCompartment to the set of
+     * Callback called to associate a JS::Realm to the set of
      * `PerformanceGroup`s that represent the components to which
      * it belongs.
      */
     void setGetGroupsCallback(js::GetGroupsCallback cb, void* closure) {
         getGroupsCallback = cb;
         getGroupsClosure = closure;
     }
 
--- a/js/src/vm/TypeInference-inl.h
+++ b/js/src/vm/TypeInference-inl.h
@@ -113,17 +113,17 @@ TypeSet::ObjectKey::group()
 inline JSObject*
 TypeSet::ObjectKey::singleton()
 {
     JSObject* res = singletonNoBarrier();
     JSObject::readBarrier(res);
     return res;
 }
 
-inline JSCompartment*
+inline JS::Compartment*
 TypeSet::ObjectKey::maybeCompartment()
 {
     if (isSingleton())
         return singletonNoBarrier()->compartment();
 
     return groupNoBarrier()->compartment();
 }
 
@@ -931,17 +931,17 @@ TypeSet::Type::trace(JSTracer* trc)
         *this = TypeSet::ObjectType(obj);
     } else if (isGroupUnchecked()) {
         ObjectGroup* group = groupNoBarrier();
         TraceManuallyBarrieredEdge(trc, &group, "TypeSet::Group");
         *this = TypeSet::ObjectType(group);
     }
 }
 
-inline JSCompartment*
+inline JS::Compartment*
 TypeSet::Type::maybeCompartment()
 {
     if (isSingletonUnchecked())
         return singletonNoBarrier()->compartment();
 
     if (isGroupUnchecked())
         return groupNoBarrier()->compartment();
 
--- a/js/src/vm/TypeInference.cpp
+++ b/js/src/vm/TypeInference.cpp
@@ -515,17 +515,17 @@ TypeSet::addTypesToConstraint(JSContext*
     for (unsigned i = 0; i < types.length(); i++)
         constraint->newType(cx, this, types[i]);
 
     return true;
 }
 
 #ifdef DEBUG
 static inline bool
-CompartmentsMatch(JSCompartment* a, JSCompartment* b)
+CompartmentsMatch(Compartment* a, Compartment* b)
 {
     return !a || !b || a == b;
 }
 #endif
 
 bool
 ConstraintTypeSet::addConstraint(JSContext* cx, TypeConstraint* constraint, bool callExisting)
 {
@@ -555,29 +555,29 @@ ConstraintTypeSet::addConstraint(JSConte
 
 void
 TypeSet::clearObjects()
 {
     setBaseObjectCount(0);
     objectSet = nullptr;
 }
 
-JSCompartment*
+Compartment*
 TypeSet::maybeCompartment()
 {
     if (unknownObject())
         return nullptr;
 
     unsigned objectCount = getObjectCount();
     for (unsigned i = 0; i < objectCount; i++) {
         ObjectKey* key = getObject(i);
         if (!key)
             continue;
 
-        JSCompartment* comp = key->maybeCompartment();
+        Compartment* comp = key->maybeCompartment();
         if (comp)
             return comp;
     }
 
     return nullptr;
 }
 
 void
@@ -1242,17 +1242,17 @@ class TypeCompilerConstraint : public Ty
 
     bool sweep(TypeZone& zone, TypeConstraint** res) override {
         if (data.shouldSweep() || compilation.shouldSweep(zone))
             return false;
         *res = zone.typeLifoAlloc().new_<TypeCompilerConstraint<T> >(compilation, data);
         return true;
     }
 
-    JSCompartment* maybeCompartment() override {
+    Compartment* maybeCompartment() override {
         return data.maybeCompartment();
     }
 };
 
 template <typename T>
 bool
 CompilerConstraintInstance<T>::generateTypeConstraint(JSContext* cx, RecompileInfo recompileInfo)
 {
@@ -1449,17 +1449,17 @@ class TypeConstraintFreezeStack : public
 
     bool sweep(TypeZone& zone, TypeConstraint** res) override {
         if (IsAboutToBeFinalizedUnbarriered(&script_))
             return false;
         *res = zone.typeLifoAlloc().new_<TypeConstraintFreezeStack>(script_);
         return true;
     }
 
-    JSCompartment* maybeCompartment() override {
+    Compartment* maybeCompartment() override {
         return script_->compartment();
     }
 };
 
 } /* anonymous namespace */
 
 bool
 js::FinishCompilation(JSContext* cx, HandleScript script, CompilerConstraintList* constraints,
@@ -1636,17 +1636,17 @@ class ConstraintDataFreeze
     {
         return expected
                ? property.maybeTypes()->isSubset(expected)
                : property.maybeTypes()->empty();
     }
 
     bool shouldSweep() { return false; }
 
-    JSCompartment* maybeCompartment() { return nullptr; }
+    Compartment* maybeCompartment() { return nullptr; }
 };
 
 } /* anonymous namespace */
 
 void
 HeapTypeSetKey::freeze(CompilerConstraintList* constraints)
 {
     LifoAlloc* alloc = constraints->alloc();
@@ -1842,17 +1842,17 @@ class ConstraintDataFreezeObjectFlags
     bool constraintHolds(const AutoSweepObjectGroup& sweep, JSContext* cx,
                          const HeapTypeSetKey& property, TemporaryTypeSet* expected)
     {
         return !invalidateOnNewObjectState(sweep, property.object()->maybeGroup());
     }
 
     bool shouldSweep() { return false; }
 
-    JSCompartment* maybeCompartment() { return nullptr; }
+    Compartment* maybeCompartment() { return nullptr; }
 };
 
 } /* anonymous namespace */
 
 bool
 TypeSet::ObjectKey::hasFlags(CompilerConstraintList* constraints, ObjectGroupFlags flags)
 {
     MOZ_ASSERT(flags);
@@ -1959,17 +1959,17 @@ class ConstraintDataFreezeObjectForTyped
         return !invalidateOnNewObjectState(sweep, property.object()->maybeGroup());
     }
 
     bool shouldSweep() {
         // Note: |viewData| is only used for equality testing.
         return IsAboutToBeFinalizedUnbarriered(&obj);
     }
 
-    JSCompartment* maybeCompartment() {
+    Compartment* maybeCompartment() {
         return obj->compartment();
     }
 };
 
 // Constraint which triggers recompilation if an unboxed object in some group
 // is converted to a native object.
 class ConstraintDataFreezeObjectForUnboxedConvertedToNative
 {
@@ -1988,17 +1988,17 @@ class ConstraintDataFreezeObjectForUnbox
     bool constraintHolds(const AutoSweepObjectGroup& sweep, JSContext* cx,
                          const HeapTypeSetKey& property, TemporaryTypeSet* expected)
     {
         return !invalidateOnNewObjectState(sweep, property.object()->maybeGroup());
     }
 
     bool shouldSweep() { return false; }
 
-    JSCompartment* maybeCompartment() { return nullptr; }
+    Compartment* maybeCompartment() { return nullptr; }
 };
 
 } /* anonymous namespace */
 
 void
 TypeSet::ObjectKey::watchStateChangeForTypedArrayData(CompilerConstraintList* constraints)
 {
     TypedArrayObject& tarray = singleton()->as<TypedArrayObject>();
@@ -2077,17 +2077,17 @@ class ConstraintDataFreezePropertyState
     bool constraintHolds(const AutoSweepObjectGroup& sweep, JSContext* cx,
                          const HeapTypeSetKey& property, TemporaryTypeSet* expected)
     {
         return !invalidateOnNewPropertyState(property.maybeTypes());
     }
 
     bool shouldSweep() { return false; }
 
-    JSCompartment* maybeCompartment() { return nullptr; }
+    Compartment* maybeCompartment() { return nullptr; }
 };
 
 } /* anonymous namespace */
 
 bool
 HeapTypeSetKey::nonData(CompilerConstraintList* constraints)
 {
     if (maybeTypes() && maybeTypes()->nonDataProperty())
@@ -2133,17 +2133,17 @@ class ConstraintDataConstantProperty
     bool constraintHolds(const AutoSweepObjectGroup& sweep, JSContext* cx,
                          const HeapTypeSetKey& property, TemporaryTypeSet* expected)
     {
         return !invalidateOnNewPropertyState(property.maybeTypes());
     }
 
     bool shouldSweep() { return false; }
 
-    JSCompartment* maybeCompartment() { return nullptr; }
+    Compartment* maybeCompartment() { return nullptr; }
 };
 
 } /* anonymous namespace */
 
 bool
 HeapTypeSetKey::constant(CompilerConstraintList* constraints, Value* valOut)
 {
     if (nonData(constraints))
@@ -2195,17 +2195,17 @@ class ConstraintDataInert
     bool constraintHolds(const AutoSweepObjectGroup& sweep, JSContext* cx,
                          const HeapTypeSetKey& property, TemporaryTypeSet* expected)
     {
         return true;
     }
 
     bool shouldSweep() { return false; }
 
-    JSCompartment* maybeCompartment() { return nullptr; }
+    Compartment* maybeCompartment() { return nullptr; }
 };
 
 bool
 HeapTypeSetKey::couldBeConstant(CompilerConstraintList* constraints)
 {
     // Only singleton object properties can be marked as constants.
     if (!object()->isSingleton())
         return false;
@@ -2617,17 +2617,17 @@ js::ReportMagicWordFailure(uintptr_t act
 {
     MOZ_CRASH_UNSAFE_PRINTF("Got 0x%" PRIxPTR " expected magic word 0x%" PRIxPTR
                             " flags 0x%" PRIxPTR " objectSet 0x%" PRIxPTR,
                             actual, expected, flags, objectSet);
 }
 #endif
 
 void
-js::PrintTypes(JSContext* cx, JSCompartment* comp, bool force)
+js::PrintTypes(JSContext* cx, Compartment* comp, bool force)
 {
 #ifdef DEBUG
     gc::AutoSuppressGC suppressGC(cx);
     JSAutoRequest request(cx);
 
     Zone* zone = comp->zone();
     AutoEnterAnalysis enter(nullptr, zone);
 
@@ -3205,17 +3205,17 @@ class TypeConstraintClearDefiniteGetterS
 
     bool sweep(TypeZone& zone, TypeConstraint** res) override {
         if (IsAboutToBeFinalizedUnbarriered(&group))
             return false;
         *res = zone.typeLifoAlloc().new_<TypeConstraintClearDefiniteGetterSetter>(group);
         return true;
     }
 
-    JSCompartment* maybeCompartment() override {
+    Compartment* maybeCompartment() override {
         return group->compartment();
     }
 };
 
 bool
 js::AddClearDefiniteGetterSetterForPrototypeChain(JSContext* cx, ObjectGroup* group, HandleId id)
 {
     /*
@@ -3265,17 +3265,17 @@ class TypeConstraintClearDefiniteSingle 
 
     bool sweep(TypeZone& zone, TypeConstraint** res) override {
         if (IsAboutToBeFinalizedUnbarriered(&group))
             return false;
         *res = zone.typeLifoAlloc().new_<TypeConstraintClearDefiniteSingle>(group);
         return true;
     }
 
-    JSCompartment* maybeCompartment() override {
+    Compartment* maybeCompartment() override {
         return group->compartment();
     }
 };
 
 bool
 js::AddClearDefiniteFunctionUsesInScript(JSContext* cx, ObjectGroup* group,
                                          JSScript* script, JSScript* calleeScript)
 {
@@ -4236,26 +4236,26 @@ ConstraintTypeSet::trace(Zone* zone, JST
         for (unsigned i = 0; i < capacity; i++) {
             ObjectKey* key = objectSet[i];
             if (!key)
                 continue;
             if (key->isGroup())
                 CheckGCThingAfterMovingGC(key->groupNoBarrier());
             else
                 CheckGCThingAfterMovingGC(key->singletonNoBarrier());
-            JSCompartment* compartment = key->maybeCompartment();
+            Compartment* compartment = key->maybeCompartment();
             MOZ_ASSERT_IF(compartment, compartment->zone() == zone);
         }
     } else if (objectCount == 1) {
         ObjectKey* key = (ObjectKey*) objectSet;
         if (key->isGroup())
             CheckGCThingAfterMovingGC(key->groupNoBarrier());
         else
             CheckGCThingAfterMovingGC(key->singletonNoBarrier());
-        JSCompartment* compartment = key->maybeCompartment();
+        Compartment* compartment = key->maybeCompartment();
         MOZ_ASSERT_IF(compartment, compartment->zone() == zone);
     }
 #endif
 }
 
 static inline void
 AssertGCStateForSweep(Zone* zone)
 {
--- a/js/src/vm/TypeInference.h
+++ b/js/src/vm/TypeInference.h
@@ -278,17 +278,17 @@ class TypeSet
         bool hasStableClassAndProto(CompilerConstraintList* constraints);
         void watchStateChangeForTypedArrayData(CompilerConstraintList* constraints);
         void watchStateChangeForUnboxedConvertedToNative(CompilerConstraintList* constraints);
         HeapTypeSetKey property(jsid id);
         void ensureTrackedProperty(JSContext* cx, jsid id);
 
         ObjectGroup* maybeGroup();
 
-        JSCompartment* maybeCompartment();
+        JS::Compartment* maybeCompartment();
     } JS_HAZ_GC_POINTER;
 
     // Information about a single concrete type. We pack this into one word,
     // where small values are particular primitive or other singleton types and
     // larger values are either specific JS objects or object groups.
     class Type
     {
         friend class TypeSet;
@@ -364,17 +364,17 @@ class TypeSet
             return isObjectUnchecked() && !(data & 1);
         }
 
         inline ObjectGroup* group() const;
         inline ObjectGroup* groupNoBarrier() const;
 
         inline void trace(JSTracer* trc);
 
-        JSCompartment* maybeCompartment();
+        JS::Compartment* maybeCompartment();
 
         bool operator == (Type o) const { return data == o.data; }
         bool operator != (Type o) const { return data != o.data; }
     } JS_HAZ_GC_POINTER;
 
     static inline Type UndefinedType() { return Type(JSVAL_TYPE_UNDEFINED); }
     static inline Type NullType()      { return Type(JSVAL_TYPE_NULL); }
     static inline Type BooleanType()   { return Type(JSVAL_TYPE_BOOLEAN); }
@@ -533,17 +533,17 @@ class TypeSet
     bool cloneIntoUninitialized(LifoAlloc* alloc, TemporaryTypeSet* result) const;
 
     // Create a new TemporaryTypeSet where undefined and/or null has been filtered out.
     TemporaryTypeSet* filter(LifoAlloc* alloc, bool filterUndefined, bool filterNull) const;
     // Create a new TemporaryTypeSet where the type has been set to object.
     TemporaryTypeSet* cloneObjectsOnly(LifoAlloc* alloc);
     TemporaryTypeSet* cloneWithoutObjects(LifoAlloc* alloc);
 
-    JSCompartment* maybeCompartment();
+    JS::Compartment* maybeCompartment();
 
     // Trigger a read barrier on all the contents of a type set.
     static void readBarrier(const TypeSet* types);
 
   protected:
     uint32_t baseObjectCount() const {
         return (flags & TYPE_FLAG_OBJECT_COUNT_MASK) >> TYPE_FLAG_OBJECT_COUNT_SHIFT;
     }
@@ -644,17 +644,17 @@ class TypeConstraint
 
     /*
      * If the data this constraint refers to is still live, copy it into the
      * zone's new allocator. Type constraints only hold weak references.
      */
     virtual bool sweep(TypeZone& zone, TypeConstraint** res) = 0;
 
     /* The associated compartment, if any. */
-    virtual JSCompartment* maybeCompartment() = 0;
+    virtual JS::Compartment* maybeCompartment() = 0;
 };
 
 // If there is an OOM while sweeping types, the type information is deoptimized
 // so that it stays correct (i.e. overapproximates the possible types in the
 // zone), but constraints might not have been triggered on the deoptimization
 // or even copied over completely. In this case, destroy all JIT code and new
 // script information in the zone, the only things whose correctness depends on
 // the type constraints.
@@ -1496,17 +1496,17 @@ inline const char * InferSpewColor(TypeC
 inline const char * InferSpewColor(TypeSet* types) { return nullptr; }
 
 #define InferSpew(channel, ...) do {} while (0)
 
 #endif
 
 // Prints type information for a context if spew is enabled or force is set.
 void
-PrintTypes(JSContext* cx, JSCompartment* comp, bool force);
+PrintTypes(JSContext* cx, JS::Compartment* comp, bool force);
 
 } /* namespace js */
 
 // JS::ubi::Nodes can point to object groups; they're js::gc::Cell instances
 // with no associated compartment.
 namespace JS {
 namespace ubi {
 
--- a/js/src/vm/UbiNode.cpp
+++ b/js/src/vm/UbiNode.cpp
@@ -155,17 +155,17 @@ StackFrame::functionDisplayNameLength()
 {
     return functionDisplayName().length();
 }
 
 // All operations on null ubi::Nodes crash.
 CoarseType Concrete<void>::coarseType() const      { MOZ_CRASH("null ubi::Node"); }
 const char16_t* Concrete<void>::typeName() const   { MOZ_CRASH("null ubi::Node"); }
 JS::Zone* Concrete<void>::zone() const             { MOZ_CRASH("null ubi::Node"); }
-JSCompartment* Concrete<void>::compartment() const { MOZ_CRASH("null ubi::Node"); }
+JS::Compartment* Concrete<void>::compartment() const { MOZ_CRASH("null ubi::Node"); }
 JS::Realm* Concrete<void>::realm() const           { MOZ_CRASH("null ubi::Node"); }
 
 UniquePtr<EdgeRange>
 Concrete<void>::edges(JSContext*, bool) const {
     MOZ_CRASH("null ubi::Node");
 }
 
 Node::Size
@@ -352,31 +352,31 @@ template UniquePtr<EdgeRange> TracerConc
 template UniquePtr<EdgeRange> TracerConcrete<js::Scope>::edges(JSContext* cx, bool wantNames) const;
 template UniquePtr<EdgeRange> TracerConcrete<JS::Symbol>::edges(JSContext* cx, bool wantNames) const;
 #ifdef ENABLE_BIGINT
 template UniquePtr<EdgeRange> TracerConcrete<BigInt>::edges(JSContext* cx, bool wantNames) const;
 #endif
 template UniquePtr<EdgeRange> TracerConcrete<JSString>::edges(JSContext* cx, bool wantNames) const;
 
 template<typename Referent>
-JSCompartment*
+JS::Compartment*
 TracerConcreteWithRealm<Referent>::compartment() const
 {
     return TracerBase::get().compartment();
 }
 
 template<typename Referent>
 Realm*
 TracerConcreteWithRealm<Referent>::realm() const
 {
     return TracerBase::get().realm();
 }
 
 template Realm* TracerConcreteWithRealm<JSScript>::realm() const;
-template JSCompartment* TracerConcreteWithRealm<JSScript>::compartment() const;
+template JS::Compartment* TracerConcreteWithRealm<JSScript>::compartment() const;
 
 bool
 Concrete<JSObject>::hasAllocationStack() const
 {
     return !!js::Debugger::getObjectAllocationSite(get());
 }
 
 StackFrame
@@ -411,17 +411,17 @@ Concrete<JSObject>::jsObjectConstructorN
     mozilla::Range<char16_t> chars(outName.get(), size);
     if (!JS_CopyStringChars(cx, chars, name))
         return false;
 
     outName[len] = '\0';
     return true;
 }
 
-JSCompartment*
+JS::Compartment*
 Concrete<JSObject>::compartment() const
 {
     return Concrete::get().compartment();
 }
 
 Realm*
 Concrete<JSObject>::realm() const
 {
@@ -484,17 +484,17 @@ RootList::init(CompartmentSet& debuggees
         return false;
     TraceIncomingCCWs(&tracer, debuggees);
     if (!tracer.okay)
         return false;
 
     for (EdgeVector::Range r = allRootEdges.all(); !r.empty(); r.popFront()) {
         Edge& edge = r.front();
 
-        JSCompartment* compartment = edge.referent.compartment();
+        JS::Compartment* compartment = edge.referent.compartment();
         if (compartment && !debuggees.has(compartment))
             continue;
 
         Zone* zone = edge.referent.zone();
         if (zone && !debuggeeZones.has(zone))
             continue;
 
         if (!edges.append(std::move(edge)))
--- a/js/src/wasm/WasmProcess.cpp
+++ b/js/src/wasm/WasmProcess.cpp
@@ -30,17 +30,17 @@ using namespace wasm;
 
 using mozilla::BinarySearchIf;
 
 // Per-process map from values of program-counter (pc) to CodeSegments.
 //
 // Whenever a new CodeSegment is ready to use, it has to be registered so that
 // we can have fast lookups from pc to CodeSegments in numerous places. Since
 // wasm compilation may be tiered, and the second tier doesn't have access to
-// any JSContext/JSCompartment/etc lying around, we have to use a process-wide
+// any JSContext/JS::Compartment/etc lying around, we have to use a process-wide
 // map instead.
 
 typedef Vector<const CodeSegment*, 0, SystemAllocPolicy> CodeSegmentVector;
 
 Atomic<bool> wasm::CodeExists(false);
 
 class ProcessCodeSegmentMap
 {
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -2602,19 +2602,19 @@ nsXPCComponents_Utils::PermitCPOWsInScop
     CompartmentPrivate::Get(scopeObj)->allowCPOWs = true;
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsXPCComponents_Utils::RecomputeWrappers(HandleValue vobj, JSContext* cx)
 {
     // Determine the compartment of the given object, if any.
-    JSCompartment* c = vobj.isObject()
-                       ? js::GetObjectCompartment(js::UncheckedUnwrap(&vobj.toObject()))
-                       : nullptr;
+    JS::Compartment* c = vobj.isObject()
+                         ? js::GetObjectCompartment(js::UncheckedUnwrap(&vobj.toObject()))
+                         : nullptr;
 
     // If no compartment was given, recompute all.
     if (!c)
         js::RecomputeWrappers(cx, js::AllCompartments(), js::AllCompartments());
     // Otherwise, recompute wrappers for the given compartment.
     else
         js::RecomputeWrappers(cx, js::SingleCompartment(c), js::AllCompartments()) &&
         js::RecomputeWrappers(cx, js::AllCompartments(), js::SingleCompartment(c));
@@ -2625,17 +2625,17 @@ nsXPCComponents_Utils::RecomputeWrappers
 NS_IMETHODIMP
 nsXPCComponents_Utils::SetWantXrays(HandleValue vscope, JSContext* cx)
 {
     if (!vscope.isObject())
         return NS_ERROR_INVALID_ARG;
     JSObject* scopeObj = js::UncheckedUnwrap(&vscope.toObject());
     MOZ_DIAGNOSTIC_ASSERT(!mozJSComponentLoader::Get()->IsLoaderGlobal(scopeObj),
                           "Don't call Cu.setWantXrays() in a JSM that shares its global");
-    JSCompartment* compartment = js::GetObjectCompartment(scopeObj);
+    JS::Compartment* compartment = js::GetObjectCompartment(scopeObj);
     CompartmentPrivate::Get(scopeObj)->wantXrays = true;
     bool ok = js::RecomputeWrappers(cx, js::SingleCompartment(compartment),
                                     js::AllCompartments());
     NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);
     return NS_OK;
 }
 
 NS_IMETHODIMP
--- a/js/xpconnect/src/XPCJSRuntime.cpp
+++ b/js/xpconnect/src/XPCJSRuntime.cpp
@@ -166,17 +166,17 @@ public:
 public:
   bool mContinuation;
   bool mActive;
   bool mPurge;
 };
 
 namespace xpc {
 
-CompartmentPrivate::CompartmentPrivate(JSCompartment* c)
+CompartmentPrivate::CompartmentPrivate(JS::Compartment* c)
     : wantXrays(false)
     , allowWaivers(true)
     , isWebExtensionContentScript(false)
     , allowCPOWs(false)
     , isContentXBLCompartment(false)
     , isAddonCompartment(false)
     , universalXPConnectEnabled(false)
     , forcePermissiveCOWs(false)
@@ -430,17 +430,17 @@ Scriptability::SetDocShellAllowsScript(b
 /* static */
 Scriptability&
 Scriptability::Get(JSObject* aScope)
 {
     return RealmPrivate::Get(aScope)->scriptability;
 }
 
 bool
-IsContentXBLCompartment(JSCompartment* compartment)
+IsContentXBLCompartment(JS::Compartment* compartment)
 {
     // We always eagerly create compartment privates for content XBL compartments.
     CompartmentPrivate* priv = CompartmentPrivate::Get(compartment);
     return priv && priv->isContentXBLCompartment;
 }
 
 bool
 IsContentXBLScope(JS::Realm* realm)
@@ -450,37 +450,37 @@ IsContentXBLScope(JS::Realm* realm)
 
 bool
 IsInContentXBLScope(JSObject* obj)
 {
     return IsContentXBLCompartment(js::GetObjectCompartment(obj));
 }
 
 bool
-IsUniversalXPConnectEnabled(JSCompartment* compartment)
+IsUniversalXPConnectEnabled(JS::Compartment* compartment)
 {
     CompartmentPrivate* priv = CompartmentPrivate::Get(compartment);
     if (!priv)
         return false;
     return priv->universalXPConnectEnabled;
 }
 
 bool
 IsUniversalXPConnectEnabled(JSContext* cx)
 {
-    JSCompartment* compartment = js::GetContextCompartment(cx);
+    JS::Compartment* compartment = js::GetContextCompartment(cx);
     if (!compartment)
         return false;
     return IsUniversalXPConnectEnabled(compartment);
 }
 
 bool
 EnableUniversalXPConnect(JSContext* cx)
 {
-    JSCompartment* compartment = js::GetContextCompartment(cx);
+    JS::Compartment* compartment = js::GetContextCompartment(cx);
     if (!compartment)
         return true;
     // Never set universalXPConnectEnabled on a chrome compartment - it confuses
     // the security wrapping code.
     if (AccessCheck::isChrome(compartment))
         return true;
     CompartmentPrivate* priv = CompartmentPrivate::Get(compartment);
     if (!priv)
@@ -554,17 +554,17 @@ CurrentWindowOrNull(JSContext* cx)
 // Nukes all wrappers into or out of the given compartment, and prevents new
 // wrappers from being created. Additionally marks the compartment as
 // unscriptable after wrappers have been nuked.
 //
 // Note: This should *only* be called for browser or extension compartments.
 // Wrappers between web compartments must never be cut in web-observable
 // ways.
 void
-NukeAllWrappersForCompartment(JSContext* cx, JSCompartment* compartment,
+NukeAllWrappersForCompartment(JSContext* cx, JS::Compartment* compartment,
                               js::NukeReferencesToWindow nukeReferencesToWindow)
 {
     // First, nuke all wrappers into or out of the target compartment. Once
     // the compartment is marked as nuked, WrapperFactory will refuse to
     // create new live wrappers for it, in either direction. This means that
     // we need to be sure that we don't have any existing cross-compartment
     // wrappers which may be replaced with dead wrappers during unrelated
     // wrapper recomputation *before* we set that bit.
@@ -582,29 +582,29 @@ NukeAllWrappersForCompartment(JSContext*
         xpc::RealmPrivate::Get(realm)->scriptability.Block();
     };
     JS::IterateRealmsInCompartment(cx, compartment, nullptr, blockScriptability);
 }
 
 } // namespace xpc
 
 static void
-CompartmentDestroyedCallback(JSFreeOp* fop, JSCompartment* compartment)
+CompartmentDestroyedCallback(JSFreeOp* fop, JS::Compartment* compartment)
 {
     // NB - This callback may be called in JS_DestroyContext, which happens
     // after the XPCJSRuntime has been torn down.
 
     // Get the current compartment private into an AutoPtr (which will do the
     // cleanup for us), and null out the private (which may already be null).
     nsAutoPtr<CompartmentPrivate> priv(CompartmentPrivate::Get(compartment));
     JS_SetCompartmentPrivate(compartment, nullptr);
 }
 
 static size_t
-CompartmentSizeOfIncludingThisCallback(MallocSizeOf mallocSizeOf, JSCompartment* compartment)
+CompartmentSizeOfIncludingThisCallback(MallocSizeOf mallocSizeOf, JS::Compartment* compartment)
 {
     CompartmentPrivate* priv = CompartmentPrivate::Get(compartment);
     return priv ? priv->SizeOfIncludingThis(mallocSizeOf) : 0;
 }
 
 /*
  * Return true if there exists a non-system inner window which is a current
  * inner window and whose reflector is gray.  We don't merge system
@@ -874,17 +874,17 @@ XPCJSRuntime::WeakPointerZonesCallback(J
     XPCJSRuntime* self = static_cast<XPCJSRuntime*>(data);
 
     self->mWrappedJSMap->UpdateWeakPointersAfterGC();
 
     XPCWrappedNativeScope::UpdateWeakPointersInAllScopesAfterGC();
 }
 
 /* static */ void
-XPCJSRuntime::WeakPointerCompartmentCallback(JSContext* cx, JSCompartment* comp, void* data)
+XPCJSRuntime::WeakPointerCompartmentCallback(JSContext* cx, JS::Compartment* comp, void* data)
 {
     // Called immediately after the ZoneGroup weak pointer callback, but only
     // once for each compartment that is being swept.
     CompartmentPrivate* xpcComp = CompartmentPrivate::Get(comp);
     if (xpcComp)
         xpcComp->UpdateWeakPointersAfterGC();
 }
 
@@ -1348,17 +1348,17 @@ ReportZoneStats(const JS::ZoneStats& zSt
         "Address-independent cell identities.");
 
     ZRREPORT_BYTES(pathPrefix + NS_LITERAL_CSTRING("shape-tables"),
         zStats.shapeTables,
         "Tables storing shape information.");
 
     ZRREPORT_BYTES(pathPrefix + NS_LITERAL_CSTRING("compartments/compartment-objects"),
         zStats.compartmentObjects,
-        "The JSCompartment objects in this zone.");
+        "The JS::Compartment objects in this zone.");
 
     ZRREPORT_BYTES(pathPrefix + NS_LITERAL_CSTRING("compartments/cross-compartment-wrapper-tables"),
         zStats.crossCompartmentWrappersTables,
         "The cross-compartment wrapper tables.");
 
     ZRREPORT_BYTES(pathPrefix + NS_LITERAL_CSTRING("compartments/private-data"),
         zStats.compartmentsPrivateData,
         "Extra data attached to each compartment by XPConnect, including "
--- a/js/xpconnect/src/XPCWrappedJS.cpp
+++ b/js/xpconnect/src/XPCWrappedJS.cpp
@@ -433,34 +433,34 @@ nsXPCWrappedJS::~nsXPCWrappedJS()
 void
 XPCJSRuntime::RemoveWrappedJS(nsXPCWrappedJS* wrapper)
 {
     AssertInvalidWrappedJSNotInTable(wrapper);
     if (!wrapper->IsValid())
         return;
 
     // It is possible for the same JS XPCOM implementation object to be wrapped
-    // with a different interface in multiple JSCompartments. In this case, the
+    // with a different interface in multiple JS::Compartments. In this case, the
     // wrapper chain will contain references to multiple compartments. While we
     // always store single-compartment chains in the per-compartment wrapped-js
     // table, chains in the multi-compartment wrapped-js table may contain
     // single-compartment chains, if they have ever contained a wrapper in a
     // different compartment. Since removal requires a lookup anyway, we just do
     // the remove on both tables unconditionally.
     MOZ_ASSERT_IF(wrapper->IsMultiCompartment(),
                   !xpc::CompartmentPrivate::Get(wrapper->GetJSObjectPreserveColor())->
                       GetWrappedJSMap()->HasWrapper(wrapper));
     GetMultiCompartmentWrappedJSMap()->Remove(wrapper);
     xpc::CompartmentPrivate::Get(wrapper->GetJSObjectPreserveColor())->GetWrappedJSMap()->
         Remove(wrapper);
 }
 
 #ifdef DEBUG
 static void
-NotHasWrapperAssertionCallback(JSContext* cx, void* data, JSCompartment* comp)
+NotHasWrapperAssertionCallback(JSContext* cx, void* data, JS::Compartment* comp)
 {
     auto wrapper = static_cast<nsXPCWrappedJS*>(data);
     auto xpcComp = xpc::CompartmentPrivate::Get(comp);
     MOZ_ASSERT_IF(xpcComp, !xpcComp->GetWrappedJSMap()->HasWrapper(wrapper));
 }
 #endif
 
 void
@@ -539,17 +539,17 @@ nsXPCWrappedJS::Unlink()
         }
     }
 }
 
 bool
 nsXPCWrappedJS::IsMultiCompartment() const
 {
     MOZ_ASSERT(IsRootWrapper());
-    JSCompartment* compartment = Compartment();
+    JS::Compartment* compartment = Compartment();
     nsXPCWrappedJS* next = mNext;
     while (next) {
         if (next->Compartment() != compartment)
             return true;
         next = next->mNext;
     }
     return false;
 }
--- a/js/xpconnect/src/XPCWrappedNativeScope.cpp
+++ b/js/xpconnect/src/XPCWrappedNativeScope.cpp
@@ -75,17 +75,17 @@ XPCWrappedNativeScope::XPCWrappedNativeS
 
         mNext = gScopes;
         gScopes = this;
     }
 
     MOZ_COUNT_CTOR(XPCWrappedNativeScope);
 
     // Create the compartment private.
-    JSCompartment* c = js::GetObjectCompartment(aGlobal);
+    JS::Compartment* c = js::GetObjectCompartment(aGlobal);
     MOZ_ASSERT(!JS_GetCompartmentPrivate(c));
     CompartmentPrivate* priv = new CompartmentPrivate(c);
     JS_SetCompartmentPrivate(c, priv);
 
     // Attach ourselves to the realm private.
     Realm* realm = JS::GetObjectRealmOrNull(aGlobal);
     RealmPrivate* realmPriv = new RealmPrivate(realm);
     realmPriv->scope = this;
@@ -400,23 +400,23 @@ XPCWrappedNativeScope::UpdateWeakPointer
             *scopep = cur->mNext;
             cur->mNext = gDyingScopes;
             gDyingScopes = cur;
         }
     }
 }
 
 static inline void
-AssertSameCompartment(DebugOnly<JSCompartment*>& comp, JSObject* obj)
+AssertSameCompartment(DebugOnly<JS::Compartment*>& comp, JSObject* obj)
 {
     MOZ_ASSERT_IF(obj, js::GetObjectCompartment(obj) == comp);
 }
 
 static inline void
-AssertSameCompartment(DebugOnly<JSCompartment*>& comp, const JS::ObjectPtr& obj)
+AssertSameCompartment(DebugOnly<JS::Compartment*>& comp, const JS::ObjectPtr& obj)
 {
 #ifdef DEBUG
     AssertSameCompartment(comp, obj.unbarrieredGet());
 #endif
 }
 
 void
 XPCWrappedNativeScope::UpdateWeakPointersAfterGC()
@@ -434,17 +434,17 @@ XPCWrappedNativeScope::UpdateWeakPointer
     if (!mGlobalJSObject) {
         JSContext* cx = dom::danger::GetJSContext();
         mContentXBLScope.finalize(cx);
         GetWrappedNativeMap()->Clear();
         mWrappedNativeProtoMap->Clear();
         return;
     }
 
-    DebugOnly<JSCompartment*> comp =
+    DebugOnly<JS::Compartment*> comp =
         js::GetObjectCompartment(mGlobalJSObject.unbarrieredGet());
 
 #ifdef DEBUG
     // These are traced, so no updates are necessary.
     if (mContentXBLScope) {
         JSObject* prev = mContentXBLScope.unbarrieredGet();
         mContentXBLScope.updateWeakPointerAfterGC();
         MOZ_ASSERT(prev == mContentXBLScope.unbarrieredGet());
--- a/js/xpconnect/src/nsXPConnect.cpp
+++ b/js/xpconnect/src/nsXPConnect.cpp
@@ -1169,17 +1169,17 @@ namespace mozilla {
 namespace dom {
 
 bool
 IsChromeOrXBL(JSContext* cx, JSObject* /* unused */)
 {
     MOZ_ASSERT(NS_IsMainThread());
     JS::Realm* realm = JS::GetCurrentRealmOrNull(cx);
     MOZ_ASSERT(realm);
-    JSCompartment* c = JS::GetCompartmentForRealm(realm);
+    JS::Compartment* c = JS::GetCompartmentForRealm(realm);
 
     // For remote XUL, we run XBL in the XUL scope. Given that we care about
     // compat and not security for remote XUL, we just always claim to be XBL.
     //
     // Note that, for performance, we don't check AllowXULXBLForPrincipal here,
     // and instead rely on the fact that AllowContentXBLScope() only returns false in
     // remote XUL situations.
     return AccessCheck::isChrome(c) || IsContentXBLCompartment(c) || !AllowContentXBLScope(realm);
--- a/js/xpconnect/src/xpcprivate.h
+++ b/js/xpconnect/src/xpcprivate.h
@@ -555,17 +555,17 @@ public:
     static void GCSliceCallback(JSContext* cx,
                                 JS::GCProgress progress,
                                 const JS::GCDescription& desc);
     static void DoCycleCollectionCallback(JSContext* cx);
     static void FinalizeCallback(JSFreeOp* fop,
                                  JSFinalizeStatus status,
                                  void* data);
     static void WeakPointerZonesCallback(JSContext* cx, void* data);
-    static void WeakPointerCompartmentCallback(JSContext* cx, JSCompartment* comp, void* data);
+    static void WeakPointerCompartmentCallback(JSContext* cx, JS::Compartment* comp, void* data);
 
     inline void AddVariantRoot(XPCTraceableVariant* variant);
     inline void AddWrappedJSRoot(nsXPCWrappedJS* wrappedJS);
 
     void DebugDump(int16_t depth);
 
     bool GCIsRunning() const {return mGCIsRunning;}
 
@@ -832,17 +832,17 @@ public:
         return mGlobalJSObject;
     }
 
     JSObject*
     GetGlobalJSObjectPreserveColor() const {return mGlobalJSObject.unbarrieredGet();}
 
     nsIPrincipal*
     GetPrincipal() const {
-        JSCompartment* c = js::GetObjectCompartment(mGlobalJSObject);
+        JS::Compartment* c = js::GetObjectCompartment(mGlobalJSObject);
         return nsJSPrincipals::get(JS_GetCompartmentPrincipals(c));
     }
 
     JSObject*
     GetExpandoChain(JS::HandleObject target);
 
     JSObject*
     DetachExpandoChain(JS::HandleObject target);
@@ -914,17 +914,17 @@ public:
     // must be same-compartment with the global upon entering, and the scope
     // object is wrapped into the compartment of the global.
     JSObject* EnsureContentXBLScope(JSContext* cx);
 
     XPCWrappedNativeScope(JSContext* cx, JS::HandleObject aGlobal);
 
     nsAutoPtr<JSObject2JSObjectMap> mWaiverWrapperMap;
 
-    JSCompartment* Compartment() const { return js::GetObjectCompartment(mGlobalJSObject); }
+    JS::Compartment* Compartment() const { return js::GetObjectCompartment(mGlobalJSObject); }
 
     bool IsContentXBLScope() { return xpc::IsContentXBLCompartment(Compartment()); }
     bool AllowContentXBLScope();
     bool UseContentXBLScope() { return mUseContentXBLScope; }
     void ClearContentXBLScope() { mContentXBLScope = nullptr; }
 
 protected:
     virtual ~XPCWrappedNativeScope();
@@ -1865,17 +1865,17 @@ protected:
                    nsXPCWrappedJS* root,
                    nsresult* rv);
 
     bool CanSkip();
     void Destroy();
     void Unlink();
 
 private:
-    JSCompartment* Compartment() const {
+    JS::Compartment* Compartment() const {
         return js::GetObjectCompartment(mJSObj.unbarrieredGet());
     }
 
     JS::Heap<JSObject*> mJSObj;
     RefPtr<nsXPCWrappedJSClass> mClass;
     nsXPCWrappedJS* mRoot;    // If mRoot != this, it is an owning pointer.
     nsXPCWrappedJS* mNext;
     nsCOMPtr<nsISupports> mOuter;    // only set in root
@@ -2829,30 +2829,30 @@ bool ReportWrapperDenial(JSContext* cx, 
 // information needed to select the right security policy for cross-compartment
 // wrappers.
 class CompartmentPrivate
 {
     CompartmentPrivate() = delete;
     CompartmentPrivate(const CompartmentPrivate&) = delete;
 
 public:
-    explicit CompartmentPrivate(JSCompartment* c);
+    explicit CompartmentPrivate(JS::Compartment* c);
 
     ~CompartmentPrivate();
 
-    static CompartmentPrivate* Get(JSCompartment* compartment)
+    static CompartmentPrivate* Get(JS::Compartment* compartment)
     {
         MOZ_ASSERT(compartment);
         void* priv = JS_GetCompartmentPrivate(compartment);
         return static_cast<CompartmentPrivate*>(priv);
     }
 
     static CompartmentPrivate* Get(JSObject* object)
     {
-        JSCompartment* compartment = js::GetObjectCompartment(object);
+        JS::Compartment* compartment = js::GetObjectCompartment(object);
         return Get(compartment);
     }
 
     // Controls whether this compartment gets Xrays to same-origin. This behavior
     // is deprecated, but is still the default for sandboxes for compatibity
     // reasons.
     bool wantXrays;
 
@@ -2912,17 +2912,17 @@ public:
     void SystemIsBeingShutDown();
 
     size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf);
 
 private:
     JSObject2WrappedJSMap* mWrappedJSMap;
 };
 
-bool IsUniversalXPConnectEnabled(JSCompartment* compartment);
+bool IsUniversalXPConnectEnabled(JS::Compartment* compartment);
 bool IsUniversalXPConnectEnabled(JSContext* cx);
 bool EnableUniversalXPConnect(JSContext* cx);
 
 inline void
 CrashIfNotInAutomation()
 {
     MOZ_RELEASE_ASSERT(IsInAutomation());
 }
--- a/js/xpconnect/src/xpcpublic.h
+++ b/js/xpconnect/src/xpcpublic.h
@@ -74,17 +74,17 @@ private:
 };
 
 JSObject*
 TransplantObject(JSContext* cx, JS::HandleObject origobj, JS::HandleObject target);
 
 JSObject*
 TransplantObjectRetainingXrayExpandos(JSContext* cx, JS::HandleObject origobj, JS::HandleObject target);
 
-bool IsContentXBLCompartment(JSCompartment* compartment);
+bool IsContentXBLCompartment(JS::Compartment* compartment);
 bool IsContentXBLScope(JS::Realm* realm);
 bool IsInContentXBLScope(JSObject* obj);
 
 // Return a raw XBL scope object corresponding to contentScope, which must
 // be an object whose global is a DOM window.
 //
 // The return value is not wrapped into cx->compartment, so be sure to enter
 // its compartment before doing anything meaningful.
@@ -376,20 +376,20 @@ bool StringToJsval(JSContext* cx, mozill
 {
     if (str.IsNull()) {
         rval.setNull();
         return true;
     }
     return NonVoidStringToJsval(cx, str, rval);
 }
 
-nsIPrincipal* GetCompartmentPrincipal(JSCompartment* compartment);
+nsIPrincipal* GetCompartmentPrincipal(JS::Compartment* compartment);
 nsIPrincipal* GetRealmPrincipal(JS::Realm* realm);
 
-void NukeAllWrappersForCompartment(JSContext* cx, JSCompartment* compartment,
+void NukeAllWrappersForCompartment(JSContext* cx, JS::Compartment* compartment,
                                    js::NukeReferencesToWindow nukeReferencesToWindow = js::NukeWindowReferences);
 
 void SetLocationForGlobal(JSObject* global, const nsACString& location);
 void SetLocationForGlobal(JSObject* global, nsIURI* locationURI);
 
 // ReportJSRuntimeExplicitTreeStats will expect this in the |extra| member
 // of JS::ZoneStats.
 class ZoneStatsExtras {
--- a/js/xpconnect/wrappers/AccessCheck.cpp
+++ b/js/xpconnect/wrappers/AccessCheck.cpp
@@ -26,17 +26,17 @@
 
 using namespace mozilla;
 using namespace JS;
 using namespace js;
 
 namespace xpc {
 
 nsIPrincipal*
-GetCompartmentPrincipal(JSCompartment* compartment)
+GetCompartmentPrincipal(JS::Compartment* compartment)
 {
     return nsJSPrincipals::get(JS_GetCompartmentPrincipals(compartment));
 }
 
 nsIPrincipal*
 GetRealmPrincipal(JS::Realm* realm)
 {
     return nsJSPrincipals::get(JS::GetRealmPrincipals(realm));
@@ -45,42 +45,42 @@ GetRealmPrincipal(JS::Realm* realm)
 nsIPrincipal*
 GetObjectPrincipal(JSObject* obj)
 {
     return GetCompartmentPrincipal(js::GetObjectCompartment(obj));
 }
 
 // Does the principal of compartment a subsume the principal of compartment b?
 bool
-AccessCheck::subsumes(JSCompartment* a, JSCompartment* b)
+AccessCheck::subsumes(JS::Compartment* a, JS::Compartment* b)
 {
     nsIPrincipal* aprin = GetCompartmentPrincipal(a);
     nsIPrincipal* bprin = GetCompartmentPrincipal(b);
     return BasePrincipal::Cast(aprin)->FastSubsumes(bprin);
 }
 
 bool
 AccessCheck::subsumes(JSObject* a, JSObject* b)
 {
     return subsumes(js::GetObjectCompartment(a), js::GetObjectCompartment(b));
 }
 
 // Same as above, but considering document.domain.
 bool
-AccessCheck::subsumesConsideringDomain(JSCompartment* a, JSCompartment* b)
+AccessCheck::subsumesConsideringDomain(JS::Compartment* a, JS::Compartment* b)
 {
     MOZ_ASSERT(OriginAttributes::IsRestrictOpenerAccessForFPI());
     nsIPrincipal* aprin = GetCompartmentPrincipal(a);
     nsIPrincipal* bprin = GetCompartmentPrincipal(b);
     return BasePrincipal::Cast(aprin)->FastSubsumesConsideringDomain(bprin);
 }
 
 bool
-AccessCheck::subsumesConsideringDomainIgnoringFPD(JSCompartment* a,
-                                                  JSCompartment* b)
+AccessCheck::subsumesConsideringDomainIgnoringFPD(JS::Compartment* a,
+                                                  JS::Compartment* b)
 {
     MOZ_ASSERT(!OriginAttributes::IsRestrictOpenerAccessForFPI());
     nsIPrincipal* aprin = GetCompartmentPrincipal(a);
     nsIPrincipal* bprin = GetCompartmentPrincipal(b);
     return BasePrincipal::Cast(aprin)->FastSubsumesConsideringDomainIgnoringFPD(bprin);
 }
 
 // Does the compartment of the wrapper subsumes the compartment of the wrappee?
@@ -89,30 +89,30 @@ AccessCheck::wrapperSubsumes(JSObject* w
 {
     MOZ_ASSERT(js::IsWrapper(wrapper));
     JSObject* wrapped = js::UncheckedUnwrap(wrapper);
     return AccessCheck::subsumes(js::GetObjectCompartment(wrapper),
                                  js::GetObjectCompartment(wrapped));
 }
 
 bool
-AccessCheck::isChrome(JSCompartment* compartment)
+AccessCheck::isChrome(JS::Compartment* compartment)
 {
     nsIPrincipal* principal = GetCompartmentPrincipal(compartment);
     return nsXPConnect::SystemPrincipal() == principal;
 }
 
 bool
 AccessCheck::isChrome(JSObject* obj)
 {
     return isChrome(js::GetObjectCompartment(obj));
 }
 
 nsIPrincipal*
-AccessCheck::getPrincipal(JSCompartment* compartment)
+AccessCheck::getPrincipal(JS::Compartment* compartment)
 {
     return GetCompartmentPrincipal(compartment);
 }
 
 // Hardcoded policy for cross origin property access. See the HTML5 Spec.
 static bool
 IsPermitted(CrossOriginObjectType type, JSFlatString* prop, bool set)
 {
--- a/js/xpconnect/wrappers/AccessCheck.h
+++ b/js/xpconnect/wrappers/AccessCheck.h
@@ -12,25 +12,25 @@
 #include "nsString.h"
 
 class nsIPrincipal;
 
 namespace xpc {
 
 class AccessCheck {
   public:
-    static bool subsumes(JSCompartment* a, JSCompartment* b);
+    static bool subsumes(JS::Compartment* a, JS::Compartment* b);
     static bool subsumes(JSObject* a, JSObject* b);
     static bool wrapperSubsumes(JSObject* wrapper);
-    static bool subsumesConsideringDomain(JSCompartment* a, JSCompartment* b);
-    static bool subsumesConsideringDomainIgnoringFPD(JSCompartment* a,
-                                                     JSCompartment* b);
-    static bool isChrome(JSCompartment* compartment);
+    static bool subsumesConsideringDomain(JS::Compartment* a, JS::Compartment* b);
+    static bool subsumesConsideringDomainIgnoringFPD(JS::Compartment* a,
+                                                     JS::Compartment* b);
+    static bool isChrome(JS::Compartment* compartment);
     static bool isChrome(JSObject* obj);
-    static nsIPrincipal* getPrincipal(JSCompartment* compartment);
+    static nsIPrincipal* getPrincipal(JS::Compartment* compartment);
     static bool isCrossOriginAccessPermitted(JSContext* cx, JS::HandleObject obj,
                                              JS::HandleId id, js::Wrapper::Action act);
     static bool checkPassToPrivilegedCode(JSContext* cx, JS::HandleObject wrapper,
                                           JS::HandleValue value);
     static bool checkPassToPrivilegedCode(JSContext* cx, JS::HandleObject wrapper,
                                           const JS::CallArgs& args);
     // Called to report the correct sort of exception when our policy denies and
     // should throw.  The accessType argument should be one of "access",
--- a/js/xpconnect/wrappers/WrapperFactory.cpp
+++ b/js/xpconnect/wrappers/WrapperFactory.cpp
@@ -100,17 +100,17 @@ WrapperFactory::WaiveXray(JSContext* cx,
     if (!waiver) {
         waiver = CreateXrayWaiver(cx, obj);
     }
     MOZ_ASSERT(JS::ObjectIsNotGray(waiver));
     return waiver;
 }
 
 /* static */ bool
-WrapperFactory::AllowWaiver(JSCompartment* target, JSCompartment* origin)
+WrapperFactory::AllowWaiver(JS::Compartment* target, JS::Compartment* origin)
 {
     return CompartmentPrivate::Get(target)->allowWaivers &&
            AccessCheck::subsumes(target, origin);
 }
 
 /* static */ bool
 WrapperFactory::AllowWaiver(JSObject* wrapper) {
     MOZ_ASSERT(js::IsCrossCompartmentWrapper(wrapper));
@@ -132,18 +132,18 @@ ShouldWaiveXray(JSContext* cx, JSObject*
     // that the caller explicitly created a waiver. Preserve it so that things
     // like WaiveXrayAndWrap work.
     if (!(flags & Wrapper::CROSS_COMPARTMENT))
         return true;
 
     // Otherwise, this is a case of explicitly passing a wrapper across a
     // compartment boundary. In that case, we only want to preserve waivers
     // in transactions between same-origin compartments.
-    JSCompartment* oldCompartment = js::GetObjectCompartment(originalObj);
-    JSCompartment* newCompartment = js::GetContextCompartment(cx);
+    JS::Compartment* oldCompartment = js::GetObjectCompartment(originalObj);
+    JS::Compartment* newCompartment = js::GetContextCompartment(cx);
     bool sameOrigin = false;
     if (OriginAttributes::IsRestrictOpenerAccessForFPI()) {
         sameOrigin =
             AccessCheck::subsumesConsideringDomain(oldCompartment, newCompartment) &&
             AccessCheck::subsumesConsideringDomain(newCompartment, oldCompartment);
     } else {
         sameOrigin =
             AccessCheck::subsumesConsideringDomainIgnoringFPD(oldCompartment, newCompartment) &&
@@ -187,18 +187,18 @@ WrapperFactory::PrepareForWrapping(JSCon
     }
 
     // If we've somehow gotten to this point after either the source or target
     // compartment has been nuked, return a DeadObjectProxy to prevent further
     // access.
     // However, we always need to provide live wrappers for ScriptSourceObjects,
     // since they're used for cross-compartment cloned scripts, and need to
     // remain accessible even after the original compartment has been nuked.
-    JSCompartment* origin = js::GetObjectCompartment(obj);
-    JSCompartment* target = js::GetObjectCompartment(scope);
+    JS::Compartment* origin = js::GetObjectCompartment(obj);
+    JS::Compartment* target = js::GetObjectCompartment(scope);
     if (!JS_IsScriptSourceObject(obj) &&
         (CompartmentPrivate::Get(origin)->wasNuked ||
          CompartmentPrivate::Get(target)->wasNuked)) {
         NS_WARNING("Trying to create a wrapper into or out of a nuked compartment");
 
         retObj.set(JS_NewDeadWrapper(cx));
         return;
     }
@@ -347,17 +347,17 @@ WrapperFactory::PrepareForWrapping(JSCon
     newwn->SetSet(unionSet.forget());
 
     retObj.set(waive ? WaiveXray(cx, obj) : obj);
 }
 
 #ifdef DEBUG
 static void
 DEBUG_CheckUnwrapSafety(HandleObject obj, const js::Wrapper* handler,
-                        JSCompartment* origin, JSCompartment* target)
+                        JS::Compartment* origin, JS::Compartment* target)
 {
     if (!JS_IsScriptSourceObject(obj) &&
         (CompartmentPrivate::Get(origin)->wasNuked || CompartmentPrivate::Get(target)->wasNuked)) {
         // If either compartment has already been nuked, we should have returned
         // a dead wrapper from our prewrap callback, and this function should
         // not be called.
         MOZ_ASSERT_UNREACHABLE("CheckUnwrapSafety called for a dead wrapper");
     } else if (AccessCheck::isChrome(target) || xpc::IsUniversalXPConnectEnabled(target)) {
@@ -432,18 +432,18 @@ WrapperFactory::Rewrap(JSContext* cx, Ha
     MOZ_ASSERT(!IsWrapper(obj) ||
                GetProxyHandler(obj) == &XrayWaiver ||
                js::IsWindowProxy(obj),
                "wrapped object passed to rewrap");
     MOZ_ASSERT(!js::IsWindow(obj));
     MOZ_ASSERT(dom::IsJSAPIActive());
 
     // Compute the information we need to select the right wrapper.
-    JSCompartment* origin = js::GetObjectCompartment(obj);
-    JSCompartment* target = js::GetContextCompartment(cx);
+    JS::Compartment* origin = js::GetObjectCompartment(obj);
+    JS::Compartment* target = js::GetContextCompartment(cx);
     bool originIsChrome = AccessCheck::isChrome(origin);
     bool targetIsChrome = AccessCheck::isChrome(target);
     bool originSubsumesTarget = OriginAttributes::IsRestrictOpenerAccessForFPI() ?
                                   AccessCheck::subsumesConsideringDomain(origin, target) :
                                   AccessCheck::subsumesConsideringDomainIgnoringFPD(origin, target);
     bool targetSubsumesOrigin = OriginAttributes::IsRestrictOpenerAccessForFPI() ?
                                   AccessCheck::subsumesConsideringDomain(target, origin) :
                                   AccessCheck::subsumesConsideringDomainIgnoringFPD(target, origin);
@@ -584,18 +584,18 @@ WrapperFactory::WaiveXrayAndWrap(JSConte
     // Even though waivers have no effect on access by scopes that don't subsume
     // the underlying object, good defense-in-depth dictates that we should avoid
     // handing out waivers to callers that can't use them. The transitive waiving
     // machinery unconditionally calls WaiveXrayAndWrap on return values from
     // waived functions, even though the return value might be not be same-origin
     // with the function. So if we find ourselves trying to create a waiver for
     // |cx|, we should check whether the caller has any business with waivers
     // to things in |obj|'s compartment.
-    JSCompartment* target = js::GetContextCompartment(cx);
-    JSCompartment* origin = js::GetObjectCompartment(obj);
+    JS::Compartment* target = js::GetContextCompartment(cx);
+    JS::Compartment* origin = js::GetObjectCompartment(obj);
     obj = AllowWaiver(target, origin) ? WaiveXray(cx, obj) : obj;
     if (!obj)
         return false;
 
     if (!JS_WrapObject(cx, &obj))
         return false;
     argObj.set(obj);
     return true;
--- a/js/xpconnect/wrappers/WrapperFactory.h
+++ b/js/xpconnect/wrappers/WrapperFactory.h
@@ -34,17 +34,17 @@ class WrapperFactory {
     static bool IsCOW(JSObject* wrapper);
 
     static JSObject* GetXrayWaiver(JS::HandleObject obj);
     static JSObject* CreateXrayWaiver(JSContext* cx, JS::HandleObject obj);
     static JSObject* WaiveXray(JSContext* cx, JSObject* obj);
 
     // Computes whether we should allow the creation of an Xray waiver from
     // |target| to |origin|.
-    static bool AllowWaiver(JSCompartment* target, JSCompartment* origin);
+    static bool AllowWaiver(JS::Compartment* target, JS::Compartment* origin);
 
     // Convenience method for the above, operating on a wrapper.
     static bool AllowWaiver(JSObject* wrapper);
 
     // Prepare a given object for wrapping in a new compartment.
     static void PrepareForWrapping(JSContext* cx,
                                    JS::HandleObject scope,
                                    JS::HandleObject obj,
--- a/toolkit/components/perfmonitoring/nsPerformanceStats.h
+++ b/toolkit/components/perfmonitoring/nsPerformanceStats.h
@@ -192,17 +192,17 @@ protected:
    * Sets of all performance groups, indexed by several keys.
    *
    * These sets do not keep the performance groups alive. Rather, a
    * performance group is inserted in the relevant sets upon
    * construction and removed from the sets upon destruction or when
    * we Dispose() of the service.
    *
    * A `nsPerformanceGroup` is typically kept alive (as a
-   * `js::PerformanceGroup`) by the JSCompartment to which it is
+   * `js::PerformanceGroup`) by the JS::Compartment to which it is
    * associated. It may also temporarily be kept alive by the JS
    * stack, in particular in case of nested event loops.
    */
 
   /**
    * Set of performance groups associated to windows, indexed by outer
    * window id. Each item is shared by all the compartments that
    * belong to the window.