Bug 1480364 - AbortSignal doesn't need to keep alive AbortController, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 03 Aug 2018 07:06:16 +0200
changeset 826237 56cd87390012d2959066c06a33e968ffea544e07
parent 826236 3686ee636ac2a7ff2a37318b93fcaea1ac605c51
child 826238 3f58dc7309e39047199a848db90d9ce940308505
push id118275
push userbmo:dharvey@mozilla.com
push dateFri, 03 Aug 2018 11:44:33 +0000
reviewerssmaug
bugs1480364
milestone63.0a1
Bug 1480364 - AbortSignal doesn't need to keep alive AbortController, r=smaug
dom/abort/AbortController.cpp
dom/abort/AbortSignal.cpp
dom/abort/AbortSignal.h
--- a/dom/abort/AbortController.cpp
+++ b/dom/abort/AbortController.cpp
@@ -51,17 +51,17 @@ AbortController::GetParentObject() const
 {
   return mGlobal;
 }
 
 AbortSignal*
 AbortController::Signal()
 {
   if (!mSignal) {
-    mSignal = new AbortSignal(this, mAborted);
+    mSignal = new AbortSignal(mGlobal, mAborted);
   }
 
   return mSignal;
 }
 
 void
 AbortController::Abort()
 {
--- a/dom/abort/AbortSignal.cpp
+++ b/dom/abort/AbortSignal.cpp
@@ -1,45 +1,41 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "AbortSignal.h"
 
-#include "AbortController.h"
 #include "mozilla/dom/Event.h"
 #include "mozilla/dom/AbortSignalBinding.h"
 
 namespace mozilla {
 namespace dom {
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(AbortSignal)
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(AbortSignal,
                                                   DOMEventTargetHelper)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mController)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(AbortSignal,
                                                 DOMEventTargetHelper)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mController)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AbortSignal)
 NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
 
 NS_IMPL_ADDREF_INHERITED(AbortSignal, DOMEventTargetHelper)
 NS_IMPL_RELEASE_INHERITED(AbortSignal, DOMEventTargetHelper)
 
-AbortSignal::AbortSignal(AbortController* aController,
+AbortSignal::AbortSignal(nsIGlobalObject* aGlobalObject,
                          bool aAborted)
-  : DOMEventTargetHelper(aController->GetParentObject())
-  , mController(aController)
+  : DOMEventTargetHelper(aGlobalObject)
   , mAborted(aAborted)
 {}
 
 AbortSignal::AbortSignal(bool aAborted)
   : mAborted(aAborted)
 {}
 
 JSObject*
--- a/dom/abort/AbortSignal.h
+++ b/dom/abort/AbortSignal.h
@@ -7,17 +7,16 @@
 #ifndef mozilla_dom_AbortSignal_h
 #define mozilla_dom_AbortSignal_h
 
 #include "mozilla/DOMEventTargetHelper.h"
 
 namespace mozilla {
 namespace dom {
 
-class AbortController;
 class AbortSignal;
 
 // This class must be implemented by objects who want to follow a AbortSignal.
 class AbortFollower
 {
 public:
   virtual void Abort() = 0;
 
@@ -38,17 +37,17 @@ protected:
 
 class AbortSignal final : public DOMEventTargetHelper
                         , public AbortFollower
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AbortSignal, DOMEventTargetHelper)
 
-  AbortSignal(AbortController* aController, bool aAborted);
+  AbortSignal(nsIGlobalObject* aGlobalObject, bool aAborted);
   explicit AbortSignal(bool aAborted);
 
   JSObject*
   WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 
   bool
   Aborted() const;
 
@@ -61,18 +60,16 @@ public:
   AddFollower(AbortFollower* aFollower);
 
   void
   RemoveFollower(AbortFollower* aFollower);
 
 private:
   ~AbortSignal() = default;
 
-  RefPtr<AbortController> mController;
-
   // Raw pointers. AbortFollower unregisters itself in the DTOR.
   nsTArray<AbortFollower*> mFollowers;
 
   bool mAborted;
 };
 
 } // dom namespace
 } // mozilla namespace