diff --git a/dom/broadcastchannel/BroadcastChannel.h b/dom/broadcastchannel/BroadcastChannel.h index 78fe2b99eaff..792b53019d5f 100644 --- a/dom/broadcastchannel/BroadcastChannel.h +++ b/dom/broadcastchannel/BroadcastChannel.h @@ -105,6 +105,11 @@ private: void UpdateMustKeepAlive(); + bool IsCertainlyAliveForCC() const override + { + return mIsKeptAlive; + } + nsRefPtr mActor; nsTArray> mPendingMessages; diff --git a/dom/events/DOMEventTargetHelper.cpp b/dom/events/DOMEventTargetHelper.cpp index aa9be0be2294..327b644db430 100644 --- a/dom/events/DOMEventTargetHelper.cpp +++ b/dom/events/DOMEventTargetHelper.cpp @@ -48,10 +48,14 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(DOMEventTargetHelper) NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(DOMEventTargetHelper) - if (tmp->IsBlack()) { + if (tmp->IsBlack() || tmp->IsCertainlyAliveForCC()) { if (tmp->mListenerManager) { tmp->mListenerManager->MarkForCC(); } + if (!tmp->IsBlack() && tmp->PreservingWrapper()) { + // This marks the wrapper black. + tmp->GetWrapper(); + } return true; } NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END diff --git a/dom/events/DOMEventTargetHelper.h b/dom/events/DOMEventTargetHelper.h index 60e1f7d405a4..126dfe89de2e 100644 --- a/dom/events/DOMEventTargetHelper.h +++ b/dom/events/DOMEventTargetHelper.h @@ -167,6 +167,14 @@ protected: nsresult WantsUntrusted(bool* aRetVal); + // If this method returns true your object is kept alive until it returns + // false. You can use this method instead using + // NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN macro. + virtual bool IsCertainlyAliveForCC() const + { + return false; + } + nsRefPtr mListenerManager; // Make |event| trusted and dispatch |aEvent| to |this|. nsresult DispatchTrustedEvent(nsIDOMEvent* aEvent); diff --git a/dom/messagechannel/MessagePort.cpp b/dom/messagechannel/MessagePort.cpp index a6bb1e93475a..3b8b5e633254 100644 --- a/dom/messagechannel/MessagePort.cpp +++ b/dom/messagechannel/MessagePort.cpp @@ -192,29 +192,6 @@ MessagePortBase::MessagePortBase() NS_IMPL_CYCLE_COLLECTION_CLASS(MessagePort) -NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(MessagePort) - bool isBlack = tmp->IsBlack(); - if (isBlack || tmp->mIsKeptAlive) { - if (tmp->mListenerManager) { - tmp->mListenerManager->MarkForCC(); - } - if (!isBlack && tmp->PreservingWrapper()) { - // This marks the wrapper black. - tmp->GetWrapper(); - } - return true; - } -NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END - -NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_BEGIN(MessagePort) - return tmp-> - IsBlackAndDoesNotNeedTracing(static_cast(tmp)); -NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_END - -NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_BEGIN(MessagePort) - return tmp->IsBlack(); -NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_END - NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(MessagePort, MessagePortBase) if (tmp->mDispatchRunnable) { @@ -235,10 +212,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(MessagePort, NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mUnshippedEntangledPort); NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END -NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(MessagePort, - MessagePortBase) -NS_IMPL_CYCLE_COLLECTION_TRACE_END - NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(MessagePort) NS_INTERFACE_MAP_ENTRY(nsIIPCBackgroundChildCreateCallback) NS_INTERFACE_MAP_ENTRY(nsIObserver) diff --git a/dom/messagechannel/MessagePort.h b/dom/messagechannel/MessagePort.h index 6cf673e335cf..28b2920c2099 100644 --- a/dom/messagechannel/MessagePort.h +++ b/dom/messagechannel/MessagePort.h @@ -75,8 +75,8 @@ public: NS_DECL_NSIIPCBACKGROUNDCHILDCREATECALLBACK NS_DECL_NSIOBSERVER NS_DECL_ISUPPORTS_INHERITED - NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_INHERITED(MessagePort, - DOMEventTargetHelper) + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MessagePort, + MessagePortBase) static already_AddRefed Create(nsPIDOMWindow* aWindow, const nsID& aUUID, @@ -177,6 +177,11 @@ private: // We release the object when the port is closed or disentangled. void UpdateMustKeepAlive(); + bool IsCertainlyAliveForCC() const override + { + return mIsKeptAlive; + } + nsAutoPtr mWorkerFeature; nsRefPtr mDispatchRunnable;