diff --git a/js/src/proxy/CrossCompartmentWrapper.cpp b/js/src/proxy/CrossCompartmentWrapper.cpp index 94d4cdcd2673..035ae0f467a9 100644 --- a/js/src/proxy/CrossCompartmentWrapper.cpp +++ b/js/src/proxy/CrossCompartmentWrapper.cpp @@ -678,13 +678,12 @@ js::RemapAllWrappersForObject(JSContext* cx, JSObject* oldTargetArg, RootedObject newTarget(cx, newTargetArg); AutoWrapperVector toTransplant(cx); - if (!toTransplant.reserve(cx->runtime()->numCompartments)) - return false; for (CompartmentsIter c(cx->runtime()); !c.done(); c.next()) { if (WrapperMap::Ptr wp = c->lookupWrapper(origv)) { // We found a wrapper. Remember and root it. - toTransplant.infallibleAppend(WrapperValue(wp)); + if (!toTransplant.append(WrapperValue(wp))) + return false; } } diff --git a/js/src/vm/JSCompartment.cpp b/js/src/vm/JSCompartment.cpp index 53cb42cb48e0..2cb05c8765a2 100644 --- a/js/src/vm/JSCompartment.cpp +++ b/js/src/vm/JSCompartment.cpp @@ -44,9 +44,7 @@ using mozilla::PodArrayZero; JSCompartment::JSCompartment(Zone* zone) : zone_(zone), runtime_(zone->runtimeFromAnyThread()) -{ - runtime_->numCompartments++; -} +{} ObjectRealm::ObjectRealm(JS::Zone* zone) : innerViews(zone) @@ -69,6 +67,8 @@ Realm::Realm(JS::Zone* zone, const JS::RealmOptions& options) { MOZ_ASSERT_IF(creationOptions_.mergeable(), creationOptions_.invisibleToDebugger()); + + runtime_->numRealms++; } Realm::~Realm() @@ -84,11 +84,9 @@ Realm::~Realm() if (!runtime_->gc.shutdownCollectedEverything()) objectGroups_.unboxedLayouts.clear(); #endif -} -JSCompartment::~JSCompartment() -{ - runtime_->numCompartments--; + MOZ_ASSERT(runtime_->numRealms > 0); + runtime_->numRealms--; } bool diff --git a/js/src/vm/JSCompartment.h b/js/src/vm/JSCompartment.h index 0b5e36c7b385..857ebc91f7d9 100644 --- a/js/src/vm/JSCompartment.h +++ b/js/src/vm/JSCompartment.h @@ -618,7 +618,6 @@ struct JSCompartment protected: explicit JSCompartment(JS::Zone* zone); - ~JSCompartment(); MOZ_MUST_USE bool init(JSContext* cx); diff --git a/js/src/vm/MemoryMetrics.cpp b/js/src/vm/MemoryMetrics.cpp index a314e12e817b..56c5fde2bfee 100644 --- a/js/src/vm/MemoryMetrics.cpp +++ b/js/src/vm/MemoryMetrics.cpp @@ -762,7 +762,7 @@ CollectRuntimeStatsHelper(JSContext* cx, RuntimeStats* rtStats, ObjectPrivateVis bool anonymize, IterateCellCallback statsCellCallback) { JSRuntime* rt = cx->runtime(); - if (!rtStats->realmStatsVector.reserve(rt->numCompartments)) + if (!rtStats->realmStatsVector.reserve(rt->numRealms)) return false; size_t totalZones = rt->gc.zones().length() + 1; // + 1 for the atoms zone. diff --git a/js/src/vm/Runtime.cpp b/js/src/vm/Runtime.cpp index 430ad91088ad..ae8beb139bff 100644 --- a/js/src/vm/Runtime.cpp +++ b/js/src/vm/Runtime.cpp @@ -133,7 +133,7 @@ JSRuntime::JSRuntime(JSRuntime* parentRuntime) activeThreadHasScriptDataAccess(false), #endif numActiveHelperThreadZones(0), - numCompartments(0), + numRealms(0), localeCallbacks(nullptr), defaultLocale(nullptr), profilingScripts(false), diff --git a/js/src/vm/Runtime.h b/js/src/vm/Runtime.h index 59ecc7182353..fec75795bc93 100644 --- a/js/src/vm/Runtime.h +++ b/js/src/vm/Runtime.h @@ -511,10 +511,10 @@ struct JSRuntime : public js::MallocProvider } #endif - // How many compartments there are across all zones. This number includes - // off thread context compartments, so it isn't necessarily equal to the - // number of compartments visited by CompartmentsIter. - js::MainThreadData numCompartments; + // How many realms there are across all zones. This number includes + // off-thread context realms, so it isn't necessarily equal to the + // number of realms visited by RealmsIter. + js::MainThreadData numRealms; /* Locale-specific callbacks for string conversion. */ js::MainThreadData localeCallbacks;