зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1612447, part 4 - Use UniquePtr for XPCMaps. r=bzbarsky
The main advantage here is that it documents who really owns the maps. Differential Revision: https://phabricator.services.mozilla.com/D61330 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
3fb9c6fefb
Коммит
f058acf8e8
|
@ -200,14 +200,13 @@ CompartmentPrivate::CompartmentPrivate(
|
|||
isUAWidgetCompartment(false),
|
||||
hasExclusiveExpandos(false),
|
||||
wasShutdown(false),
|
||||
mWrappedJSMap(new JSObject2WrappedJSMap()),
|
||||
mWrappedJSMap(mozilla::MakeUnique<JSObject2WrappedJSMap>()),
|
||||
mScope(std::move(scope)) {
|
||||
MOZ_COUNT_CTOR(xpc::CompartmentPrivate);
|
||||
}
|
||||
|
||||
CompartmentPrivate::~CompartmentPrivate() {
|
||||
MOZ_COUNT_DTOR(xpc::CompartmentPrivate);
|
||||
delete mWrappedJSMap;
|
||||
}
|
||||
|
||||
void CompartmentPrivate::SystemIsBeingShutDown() {
|
||||
|
@ -1085,16 +1084,12 @@ void XPCJSRuntime::Shutdown(JSContext* cx) {
|
|||
|
||||
// Clean up and destroy maps. Any remaining entries in mWrappedJSMap will be
|
||||
// cleaned up by the weak pointer callbacks.
|
||||
delete mIID2NativeInterfaceMap;
|
||||
mIID2NativeInterfaceMap = nullptr;
|
||||
|
||||
delete mClassInfo2NativeSetMap;
|
||||
mClassInfo2NativeSetMap = nullptr;
|
||||
|
||||
delete mNativeSetMap;
|
||||
mNativeSetMap = nullptr;
|
||||
|
||||
delete mDyingWrappedNativeProtoMap;
|
||||
mDyingWrappedNativeProtoMap = nullptr;
|
||||
|
||||
// Prevent ~LinkedList assertion failures if we leaked things.
|
||||
|
@ -1105,7 +1100,6 @@ void XPCJSRuntime::Shutdown(JSContext* cx) {
|
|||
|
||||
XPCJSRuntime::~XPCJSRuntime() {
|
||||
MOZ_COUNT_DTOR_INHERITED(XPCJSRuntime, CycleCollectedJSRuntime);
|
||||
delete mWrappedJSMap;
|
||||
}
|
||||
|
||||
// If |*anonymizeID| is non-zero and this is a user realm, the name will
|
||||
|
@ -2913,12 +2907,13 @@ static const JSWrapObjectCallbacks WrapObjectCallbacks = {
|
|||
|
||||
XPCJSRuntime::XPCJSRuntime(JSContext* aCx)
|
||||
: CycleCollectedJSRuntime(aCx),
|
||||
mWrappedJSMap(new JSObject2WrappedJSMap()),
|
||||
mIID2NativeInterfaceMap(new IID2NativeInterfaceMap()),
|
||||
mClassInfo2NativeSetMap(new ClassInfo2NativeSetMap()),
|
||||
mNativeSetMap(new NativeSetMap()),
|
||||
mWrappedJSMap(mozilla::MakeUnique<JSObject2WrappedJSMap>()),
|
||||
mIID2NativeInterfaceMap(mozilla::MakeUnique<IID2NativeInterfaceMap>()),
|
||||
mClassInfo2NativeSetMap(mozilla::MakeUnique<ClassInfo2NativeSetMap>()),
|
||||
mNativeSetMap(mozilla::MakeUnique<NativeSetMap>()),
|
||||
mWrappedNativeScopes(),
|
||||
mDyingWrappedNativeProtoMap(new XPCWrappedNativeProtoMap()),
|
||||
mDyingWrappedNativeProtoMap(
|
||||
mozilla::MakeUnique<XPCWrappedNativeProtoMap>()),
|
||||
mGCIsRunning(false),
|
||||
mNativesToReleaseArray(),
|
||||
mDoingFinalization(false),
|
||||
|
@ -3149,7 +3144,7 @@ void XPCJSRuntime::DebugDump(int16_t depth) {
|
|||
XPC_LOG_INDENT();
|
||||
|
||||
// iterate wrappers...
|
||||
XPC_LOG_ALWAYS(("mWrappedJSMap @ %p with %d wrappers(s)", mWrappedJSMap,
|
||||
XPC_LOG_ALWAYS(("mWrappedJSMap @ %p with %d wrappers(s)", mWrappedJSMap.get(),
|
||||
mWrappedJSMap->Count()));
|
||||
if (depth && mWrappedJSMap->Count()) {
|
||||
XPC_LOG_INDENT();
|
||||
|
@ -3158,12 +3153,14 @@ void XPCJSRuntime::DebugDump(int16_t depth) {
|
|||
}
|
||||
|
||||
XPC_LOG_ALWAYS(("mIID2NativeInterfaceMap @ %p with %d interface(s)",
|
||||
mIID2NativeInterfaceMap, mIID2NativeInterfaceMap->Count()));
|
||||
mIID2NativeInterfaceMap.get(),
|
||||
mIID2NativeInterfaceMap->Count()));
|
||||
|
||||
XPC_LOG_ALWAYS(("mClassInfo2NativeSetMap @ %p with %d sets(s)",
|
||||
mClassInfo2NativeSetMap, mClassInfo2NativeSetMap->Count()));
|
||||
mClassInfo2NativeSetMap.get(),
|
||||
mClassInfo2NativeSetMap->Count()));
|
||||
|
||||
XPC_LOG_ALWAYS(("mNativeSetMap @ %p with %d sets(s)", mNativeSetMap,
|
||||
XPC_LOG_ALWAYS(("mNativeSetMap @ %p with %d sets(s)", mNativeSetMap.get(),
|
||||
mNativeSetMap->Count()));
|
||||
|
||||
// iterate sets...
|
||||
|
|
|
@ -63,8 +63,9 @@ static bool RemoteXULForbidsXBLScope(HandleObject aFirstGlobal) {
|
|||
|
||||
XPCWrappedNativeScope::XPCWrappedNativeScope(JS::Compartment* aCompartment,
|
||||
JS::HandleObject aFirstGlobal)
|
||||
: mWrappedNativeMap(new Native2WrappedNativeMap()),
|
||||
mWrappedNativeProtoMap(new ClassInfo2WrappedNativeProtoMap()),
|
||||
: mWrappedNativeMap(mozilla::MakeUnique<Native2WrappedNativeMap>()),
|
||||
mWrappedNativeProtoMap(
|
||||
mozilla::MakeUnique<ClassInfo2WrappedNativeProtoMap>()),
|
||||
mComponents(nullptr),
|
||||
mCompartment(aCompartment) {
|
||||
#ifdef DEBUG
|
||||
|
@ -225,10 +226,8 @@ XPCWrappedNativeScope::~XPCWrappedNativeScope() {
|
|||
// We can do additional cleanup assertions here...
|
||||
|
||||
MOZ_ASSERT(0 == mWrappedNativeMap->Count(), "scope has non-empty map");
|
||||
delete mWrappedNativeMap;
|
||||
|
||||
MOZ_ASSERT(0 == mWrappedNativeProtoMap->Count(), "scope has non-empty map");
|
||||
delete mWrappedNativeProtoMap;
|
||||
|
||||
// This should not be necessary, since the Components object should die
|
||||
// with the scope but just in case.
|
||||
|
@ -445,7 +444,7 @@ void XPCWrappedNativeScope::DebugDump(int16_t depth) {
|
|||
XPC_LOG_ALWAYS(("mCompartment @ %p", mCompartment));
|
||||
|
||||
XPC_LOG_ALWAYS(("mWrappedNativeMap @ %p with %d wrappers(s)",
|
||||
mWrappedNativeMap, mWrappedNativeMap->Count()));
|
||||
mWrappedNativeMap.get(), mWrappedNativeMap->Count()));
|
||||
// iterate contexts...
|
||||
if (depth && mWrappedNativeMap->Count()) {
|
||||
XPC_LOG_INDENT();
|
||||
|
@ -457,7 +456,8 @@ void XPCWrappedNativeScope::DebugDump(int16_t depth) {
|
|||
}
|
||||
|
||||
XPC_LOG_ALWAYS(("mWrappedNativeProtoMap @ %p with %d protos(s)",
|
||||
mWrappedNativeProtoMap, mWrappedNativeProtoMap->Count()));
|
||||
mWrappedNativeProtoMap.get(),
|
||||
mWrappedNativeProtoMap->Count()));
|
||||
// iterate contexts...
|
||||
if (depth && mWrappedNativeProtoMap->Count()) {
|
||||
XPC_LOG_INDENT();
|
||||
|
|
|
@ -471,21 +471,21 @@ class XPCJSRuntime final : public mozilla::CycleCollectedJSRuntime {
|
|||
void AssertInvalidWrappedJSNotInTable(nsXPCWrappedJS* wrapper) const;
|
||||
|
||||
JSObject2WrappedJSMap* GetMultiCompartmentWrappedJSMap() const {
|
||||
return mWrappedJSMap;
|
||||
return mWrappedJSMap.get();
|
||||
}
|
||||
|
||||
IID2NativeInterfaceMap* GetIID2NativeInterfaceMap() const {
|
||||
return mIID2NativeInterfaceMap;
|
||||
return mIID2NativeInterfaceMap.get();
|
||||
}
|
||||
|
||||
ClassInfo2NativeSetMap* GetClassInfo2NativeSetMap() const {
|
||||
return mClassInfo2NativeSetMap;
|
||||
return mClassInfo2NativeSetMap.get();
|
||||
}
|
||||
|
||||
NativeSetMap* GetNativeSetMap() const { return mNativeSetMap; }
|
||||
NativeSetMap* GetNativeSetMap() const { return mNativeSetMap.get(); }
|
||||
|
||||
XPCWrappedNativeProtoMap* GetDyingWrappedNativeProtoMap() const {
|
||||
return mDyingWrappedNativeProtoMap;
|
||||
return mDyingWrappedNativeProtoMap.get();
|
||||
}
|
||||
|
||||
XPCWrappedNativeScopeList& GetWrappedNativeScopes() {
|
||||
|
@ -604,13 +604,13 @@ class XPCJSRuntime final : public mozilla::CycleCollectedJSRuntime {
|
|||
Hasher, js::SystemAllocPolicy, SweepPolicy>
|
||||
Principal2JSObjectMap;
|
||||
|
||||
JSObject2WrappedJSMap* mWrappedJSMap;
|
||||
IID2NativeInterfaceMap* mIID2NativeInterfaceMap;
|
||||
ClassInfo2NativeSetMap* mClassInfo2NativeSetMap;
|
||||
NativeSetMap* mNativeSetMap;
|
||||
mozilla::UniquePtr<JSObject2WrappedJSMap> mWrappedJSMap;
|
||||
mozilla::UniquePtr<IID2NativeInterfaceMap> mIID2NativeInterfaceMap;
|
||||
mozilla::UniquePtr<ClassInfo2NativeSetMap> mClassInfo2NativeSetMap;
|
||||
mozilla::UniquePtr<NativeSetMap> mNativeSetMap;
|
||||
Principal2JSObjectMap mUAWidgetScopeMap;
|
||||
XPCWrappedNativeScopeList mWrappedNativeScopes;
|
||||
XPCWrappedNativeProtoMap* mDyingWrappedNativeProtoMap;
|
||||
mozilla::UniquePtr<XPCWrappedNativeProtoMap> mDyingWrappedNativeProtoMap;
|
||||
bool mGCIsRunning;
|
||||
nsTArray<nsISupports*> mNativesToReleaseArray;
|
||||
bool mDoingFinalization;
|
||||
|
@ -795,11 +795,11 @@ class XPCWrappedNativeScope final
|
|||
XPCJSRuntime* GetRuntime() const { return XPCJSRuntime::Get(); }
|
||||
|
||||
Native2WrappedNativeMap* GetWrappedNativeMap() const {
|
||||
return mWrappedNativeMap;
|
||||
return mWrappedNativeMap.get();
|
||||
}
|
||||
|
||||
ClassInfo2WrappedNativeProtoMap* GetWrappedNativeProtoMap() const {
|
||||
return mWrappedNativeProtoMap;
|
||||
return mWrappedNativeProtoMap.get();
|
||||
}
|
||||
|
||||
nsXPCComponentsBase* GetComponents() const { return mComponents; }
|
||||
|
@ -887,8 +887,8 @@ class XPCWrappedNativeScope final
|
|||
XPCWrappedNativeScope() = delete;
|
||||
|
||||
private:
|
||||
Native2WrappedNativeMap* mWrappedNativeMap;
|
||||
ClassInfo2WrappedNativeProtoMap* mWrappedNativeProtoMap;
|
||||
mozilla::UniquePtr<Native2WrappedNativeMap> mWrappedNativeMap;
|
||||
mozilla::UniquePtr<ClassInfo2WrappedNativeProtoMap> mWrappedNativeProtoMap;
|
||||
RefPtr<nsXPCComponentsBase> mComponents;
|
||||
JS::Compartment* mCompartment;
|
||||
|
||||
|
@ -2644,7 +2644,7 @@ class CompartmentPrivate {
|
|||
// Whether SystemIsBeingShutDown has been called on this compartment.
|
||||
bool wasShutdown;
|
||||
|
||||
JSObject2WrappedJSMap* GetWrappedJSMap() const { return mWrappedJSMap; }
|
||||
JSObject2WrappedJSMap* GetWrappedJSMap() const { return mWrappedJSMap.get(); }
|
||||
void UpdateWeakPointersAfterGC();
|
||||
|
||||
void SystemIsBeingShutDown();
|
||||
|
@ -2667,7 +2667,7 @@ class CompartmentPrivate {
|
|||
XPCWrappedNativeScope* GetScope() { return mScope.get(); }
|
||||
|
||||
private:
|
||||
JSObject2WrappedJSMap* mWrappedJSMap;
|
||||
mozilla::UniquePtr<JSObject2WrappedJSMap> mWrappedJSMap;
|
||||
|
||||
// Cache holding proxy objects for Window objects (and their Location object)
|
||||
// that are loaded in a different process.
|
||||
|
|
Загрузка…
Ссылка в новой задаче