Bug 1743207 - Extract BaseQueuingStrategy r?smaug draft
authorMatthew Gaudet <mgaudet@mozilla.com>
Fri, 26 Nov 2021 14:14:30 -0700
changeset 4097847 9fd87cda0c299bb6aac67741f5a3b31e36bf1398
parent 4096131 c348ffc69b7fa70cc822f11e4b573006e7b824ee
child 4097848 980c94436576ae439b903cc140e0069492c6c3ce
push id755115
push usermgaudet@mozilla.com
push dateFri, 26 Nov 2021 22:43:38 +0000
treeherdertry@99dda87ae19f [default view] [failures only]
reviewerssmaug
bugs1743207
milestone96.0a1
Bug 1743207 - Extract BaseQueuingStrategy r?smaug
dom/streams/BaseQueuingStrategy.h
dom/streams/CountQueuingStrategy.cpp
dom/streams/CountQueuingStrategy.h
dom/streams/moz.build
new file mode 100644
--- /dev/null
+++ b/dom/streams/BaseQueuingStrategy.h
@@ -0,0 +1,37 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et cindent: */
+/* 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/. */
+
+#ifndef mozilla_dom_BaseQueuingStrategy_h
+#define mozilla_dom_BaseQueuingStrategy_h
+
+#include "nsCycleCollectionParticipant.h"
+#include "nsIGlobalObject.h"
+
+namespace mozilla::dom {
+
+class BaseQueuingStrategy : public nsISupports {
+ public:
+  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
+  NS_DECL_CYCLE_COLLECTION_CLASS(BaseQueuingStrategy)
+
+  BaseQueuingStrategy(nsISupports* aGlobal, double aHighWaterMark)
+      : mGlobal(do_QueryInterface(aGlobal)), mHighWaterMark(aHighWaterMark) {}
+
+  nsIGlobalObject* GetParentObject() const;
+
+  double HighWaterMark() const { return mHighWaterMark; }
+
+ protected:
+  virtual ~BaseQueuingStrategy() = default;
+
+ private:
+  nsCOMPtr<nsIGlobalObject> mGlobal;
+  double mHighWaterMark = 0.0;
+};
+
+}  // namespace mozilla::dom
+
+#endif
\ No newline at end of file
--- a/dom/streams/CountQueuingStrategy.cpp
+++ b/dom/streams/CountQueuingStrategy.cpp
@@ -2,38 +2,46 @@
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* 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 "mozilla/dom/CountQueuingStrategy.h"
 #include "mozilla/dom/QueuingStrategyBinding.h"
 #include "nsCOMPtr.h"
+#include "nsISupports.h"
 
 namespace mozilla {
 namespace dom {
 
-// Only needed for refcounted objects.
-NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(CountQueuingStrategy, mGlobal)
-NS_IMPL_CYCLE_COLLECTING_ADDREF(CountQueuingStrategy)
-NS_IMPL_CYCLE_COLLECTING_RELEASE(CountQueuingStrategy)
+NS_IMPL_CYCLE_COLLECTION(BaseQueuingStrategy, mGlobal)
+NS_IMPL_CYCLE_COLLECTING_ADDREF(BaseQueuingStrategy)
+NS_IMPL_CYCLE_COLLECTING_RELEASE(BaseQueuingStrategy)
+
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(BaseQueuingStrategy)
+  NS_INTERFACE_MAP_ENTRY(nsISupports)
+NS_INTERFACE_MAP_END
+
+NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(CountQueuingStrategy)
+NS_IMPL_ADDREF_INHERITED(CountQueuingStrategy, BaseQueuingStrategy)
+NS_IMPL_RELEASE_INHERITED(CountQueuingStrategy, BaseQueuingStrategy)
+
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CountQueuingStrategy)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
-  NS_INTERFACE_MAP_ENTRY(nsISupports)
-NS_INTERFACE_MAP_END
+NS_INTERFACE_MAP_END_INHERITING(BaseQueuingStrategy)
 
 /* static */
 already_AddRefed<CountQueuingStrategy> CountQueuingStrategy::Constructor(
     const GlobalObject& aGlobal, const QueuingStrategyInit& aInit) {
   RefPtr<CountQueuingStrategy> strategy =
       new CountQueuingStrategy(aGlobal.GetAsSupports(), aInit.mHighWaterMark);
   return strategy.forget();
 }
 
-nsIGlobalObject* CountQueuingStrategy::GetParentObject() const {
+nsIGlobalObject* BaseQueuingStrategy::GetParentObject() const {
   return mGlobal;
 }
 
 JSObject* CountQueuingStrategy::WrapObject(JSContext* aCx,
                                            JS::Handle<JSObject*> aGivenProto) {
   return CountQueuingStrategy_Binding::Wrap(aCx, this, aGivenProto);
 }
 
--- a/dom/streams/CountQueuingStrategy.h
+++ b/dom/streams/CountQueuingStrategy.h
@@ -5,60 +5,44 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_CountQueuingStrategy_h
 #define mozilla_dom_CountQueuingStrategy_h
 
 #include "js/TypeDecls.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/ErrorResult.h"
+#include "mozilla/dom/BaseQueuingStrategy.h"
 #include "mozilla/dom/BindingDeclarations.h"
 #include "mozilla/dom/QueuingStrategyBinding.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsWrapperCache.h"
 #include "nsIGlobalObject.h"
 
 namespace mozilla {
 namespace dom {
 
-class Function;
-
-}  // namespace dom
-}  // namespace mozilla
-
-namespace mozilla {
-namespace dom {
-
-class CountQueuingStrategy final : public nsISupports, public nsWrapperCache {
+class CountQueuingStrategy final : public BaseQueuingStrategy,
+                                   public nsWrapperCache {
  public:
-  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
-  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(CountQueuingStrategy)
+  NS_DECL_ISUPPORTS_INHERITED
+  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(CountQueuingStrategy,
+                                                         BaseQueuingStrategy)
 
  public:
   explicit CountQueuingStrategy(nsISupports* aGlobal, double aHighWaterMark)
-      : mGlobal(do_QueryInterface(aGlobal)), mHighWaterMark(aHighWaterMark) {}
+      : BaseQueuingStrategy(aGlobal, aHighWaterMark) {}
 
  protected:
   ~CountQueuingStrategy() = default;
 
-  nsCOMPtr<nsIGlobalObject> mGlobal;
-
  public:
-  nsIGlobalObject* GetParentObject() const;
-
   JSObject* WrapObject(JSContext* aCx,
                        JS::Handle<JSObject*> aGivenProto) override;
 
   static already_AddRefed<CountQueuingStrategy> Constructor(
       const GlobalObject& aGlobal, const QueuingStrategyInit& aInit);
-
-  double HighWaterMark() const { return mHighWaterMark; }
-
-  already_AddRefed<Function> Size() const;
-
- private:
-  double mHighWaterMark = 0.0;
 };
 
 }  // namespace dom
 }  // namespace mozilla
 
 #endif  // mozilla_dom_CountQueuingStrategy_h
--- a/dom/streams/moz.build
+++ b/dom/streams/moz.build
@@ -3,16 +3,17 @@
 # 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/.
 
 with Files("**"):
     BUG_COMPONENT = ("Core", "DOM: Streams")
 
 EXPORTS.mozilla.dom += [
+    "BaseQueuingStrategy.h",
     "ByteStreamHelpers.h",
     "CountQueuingStrategy.h",
     "NativeUnderlyingSource.h",
     "QueueWithSizes.h",
     "ReadableByteStreamController.h",
     "ReadableStream.h",
     "ReadableStreamBYOBReader.h",
     "ReadableStreamBYOBRequest.h",