Bug 1503236 - Move WorkletImpl reference from WorkletGlobalScope to classes inheriting WorkletGlobalScope r=karlt
authorArnaud Bienner <arnaud.bienner@gmail.com>
Wed, 31 Oct 2018 23:03:39 +0000
changeset 500293 10d4bab0bccbc6faf6f909a537a9780db7c4edf9
parent 500292 2150b1a321795b7374a343c49e56bac4b07d2ac7
child 500294 1cab84e7439428307dbb40a7e8cf100daa083914
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs1503236
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1503236 - Move WorkletImpl reference from WorkletGlobalScope to classes inheriting WorkletGlobalScope r=karlt Differential Revision: https://phabricator.services.mozilla.com/D10215
dom/media/webaudio/AudioWorkletGlobalScope.cpp
dom/media/webaudio/AudioWorkletGlobalScope.h
dom/worklet/WorkletGlobalScope.cpp
dom/worklet/WorkletGlobalScope.h
layout/style/PaintWorkletGlobalScope.cpp
layout/style/PaintWorkletGlobalScope.h
--- a/dom/media/webaudio/AudioWorkletGlobalScope.cpp
+++ b/dom/media/webaudio/AudioWorkletGlobalScope.cpp
@@ -1,33 +1,35 @@
 /* -*- 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 "AudioWorkletGlobalScope.h"
+
+#include "AudioWorkletImpl.h"
 #include "jsapi.h"
 #include "mozilla/dom/AudioWorkletGlobalScopeBinding.h"
 #include "mozilla/dom/WorkletPrincipal.h"
 
 namespace mozilla {
 namespace dom {
 
 NS_IMPL_CYCLE_COLLECTION_INHERITED(AudioWorkletGlobalScope, WorkletGlobalScope,
                                    mNameToProcessorMap);
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AudioWorkletGlobalScope)
 NS_INTERFACE_MAP_END_INHERITING(WorkletGlobalScope)
 
 NS_IMPL_ADDREF_INHERITED(AudioWorkletGlobalScope, WorkletGlobalScope)
 NS_IMPL_RELEASE_INHERITED(AudioWorkletGlobalScope, WorkletGlobalScope)
 
-AudioWorkletGlobalScope::AudioWorkletGlobalScope(WorkletImpl* aImpl)
-  : WorkletGlobalScope(aImpl)
+AudioWorkletGlobalScope::AudioWorkletGlobalScope(AudioWorkletImpl* aImpl)
+  : mImpl(aImpl)
   , mCurrentFrame(0)
   , mCurrentTime(0)
   , mSampleRate(0.0)
 {}
 
 bool
 AudioWorkletGlobalScope::WrapGlobalObject(JSContext* aCx,
                                           JS::MutableHandle<JSObject*> aReflector)
@@ -184,16 +186,21 @@ AudioWorkletGlobalScope::RegisterProcess
    *     map of the associated BaseAudioContext.
    */
   // TODO: we don't have a proper mechanism to communicate with the
   // control thread currently. See
   // https://bugzilla.mozilla.org/show_bug.cgi?id=1473467#c3
   // and https://bugzilla.mozilla.org/show_bug.cgi?id=1492014
 }
 
+WorkletImpl* AudioWorkletGlobalScope::Impl() const
+{
+  return mImpl;
+}
+
 uint64_t AudioWorkletGlobalScope::CurrentFrame() const
 {
   return mCurrentFrame;
 }
 
 double AudioWorkletGlobalScope::CurrentTime() const
 {
   return mCurrentTime;
--- a/dom/media/webaudio/AudioWorkletGlobalScope.h
+++ b/dom/media/webaudio/AudioWorkletGlobalScope.h
@@ -8,47 +8,50 @@
 #define mozilla_dom_AudioWorkletGlobalScope_h
 
 #include "mozilla/dom/FunctionBinding.h"
 #include "mozilla/dom/WorkletGlobalScope.h"
 #include "nsRefPtrHashtable.h"
 
 namespace mozilla {
 
-class WorkletImpl;
+class AudioWorkletImpl;
 
 namespace dom {
 
-
 class AudioWorkletGlobalScope final : public WorkletGlobalScope
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AudioWorkletGlobalScope, WorkletGlobalScope);
 
-  explicit AudioWorkletGlobalScope(WorkletImpl* aImpl);
+  explicit AudioWorkletGlobalScope(AudioWorkletImpl* aImpl);
 
   bool
   WrapGlobalObject(JSContext* aCx,
                    JS::MutableHandle<JSObject*> aReflector) override;
 
   void
   RegisterProcessor(JSContext* aCx, const nsAString& aName,
                     VoidFunction& aProcessorCtor,
                     ErrorResult& aRv);
 
+  WorkletImpl* Impl() const override;
+
   uint64_t CurrentFrame() const;
 
   double CurrentTime() const;
 
   float SampleRate() const;
 
 private:
   ~AudioWorkletGlobalScope() = default;
 
+  const RefPtr<AudioWorkletImpl> mImpl;
+
   uint64_t mCurrentFrame;
   double mCurrentTime;
   float mSampleRate;
 
   typedef nsRefPtrHashtable<nsStringHashKey, VoidFunction> NodeNameToProcessorDefinitionMap;
   NodeNameToProcessorDefinitionMap mNameToProcessorMap;
 };
 
--- a/dom/worklet/WorkletGlobalScope.cpp
+++ b/dom/worklet/WorkletGlobalScope.cpp
@@ -31,18 +31,17 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCA
 NS_IMPL_CYCLE_COLLECTING_ADDREF(WorkletGlobalScope)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(WorkletGlobalScope)
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WorkletGlobalScope)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   NS_INTERFACE_MAP_ENTRY(nsIGlobalObject)
   NS_INTERFACE_MAP_ENTRY(WorkletGlobalScope)
 NS_INTERFACE_MAP_END
 
-WorkletGlobalScope::WorkletGlobalScope(WorkletImpl* aImpl)
-  : mImpl(aImpl)
+WorkletGlobalScope::WorkletGlobalScope()
 {
 }
 
 WorkletGlobalScope::~WorkletGlobalScope() = default;
 
 JSObject*
 WorkletGlobalScope::WrapObject(JSContext* aCx,
                                JS::Handle<JSObject*> aGivenProto)
@@ -50,17 +49,18 @@ WorkletGlobalScope::WrapObject(JSContext
   MOZ_CRASH("We should never get here!");
   return nullptr;
 }
 
 already_AddRefed<Console>
 WorkletGlobalScope::GetConsole(JSContext* aCx, ErrorResult& aRv)
 {
   if (!mConsole) {
-    const WorkletLoadInfo& loadInfo = mImpl->LoadInfo();
+    MOZ_ASSERT(Impl());
+    const WorkletLoadInfo& loadInfo = Impl()->LoadInfo();
     mConsole = Console::CreateForWorklet(aCx, this,
                                          loadInfo.OuterWindowID(),
                                          loadInfo.InnerWindowID(), aRv);
     if (NS_WARN_IF(aRv.Failed())) {
       return nullptr;
     }
   }
 
--- a/dom/worklet/WorkletGlobalScope.h
+++ b/dom/worklet/WorkletGlobalScope.h
@@ -29,17 +29,17 @@ class WorkletGlobalScope : public nsIGlo
                          , public nsWrapperCache
 {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(WORKLET_IID)
 
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(WorkletGlobalScope)
 
-  explicit WorkletGlobalScope(WorkletImpl* aImpl);
+  WorkletGlobalScope();
 
   nsIGlobalObject* GetParentObject() const
   {
     return nullptr;
   }
 
   virtual JSObject*
   WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
@@ -51,26 +51,25 @@ public:
   GetGlobalJSObject() override
   {
     return GetWrapper();
   }
 
   already_AddRefed<Console>
   GetConsole(JSContext* aCx, ErrorResult& aRv);
 
-  WorkletImpl* Impl() const { return mImpl; }
+  virtual WorkletImpl* Impl() const = 0;
 
   void
   Dump(const Optional<nsAString>& aString) const;
 
 protected:
   ~WorkletGlobalScope();;
 
 private:
-  const RefPtr<WorkletImpl> mImpl;
   RefPtr<Console> mConsole;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(WorkletGlobalScope, WORKLET_IID)
 
 } // namespace dom
 } // namespace mozilla
 
--- a/layout/style/PaintWorkletGlobalScope.cpp
+++ b/layout/style/PaintWorkletGlobalScope.cpp
@@ -1,24 +1,26 @@
 /* -*- 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 "PaintWorkletGlobalScope.h"
+
 #include "mozilla/dom/WorkletPrincipal.h"
 #include "mozilla/dom/PaintWorkletGlobalScopeBinding.h"
 #include "mozilla/dom/FunctionBinding.h"
+#include "PaintWorkletImpl.h"
 
 namespace mozilla {
 namespace dom {
 
-PaintWorkletGlobalScope::PaintWorkletGlobalScope(WorkletImpl* aImpl)
-  : WorkletGlobalScope(aImpl)
+PaintWorkletGlobalScope::PaintWorkletGlobalScope(PaintWorkletImpl* aImpl)
+  : mImpl(aImpl)
 {
 }
 
 bool
 PaintWorkletGlobalScope::WrapGlobalObject(JSContext* aCx,
                                           JS::MutableHandle<JSObject*> aReflector)
 {
   JS::RealmOptions options;
@@ -30,10 +32,15 @@ PaintWorkletGlobalScope::WrapGlobalObjec
 
 void
 PaintWorkletGlobalScope::RegisterPaint(const nsAString& aType,
                                        VoidFunction& aProcessorCtor)
 {
   // Nothing to do here, yet.
 }
 
+WorkletImpl* PaintWorkletGlobalScope::Impl() const
+{
+  return mImpl;
+}
+
 } // dom namespace
 } // mozilla namespace
--- a/layout/style/PaintWorkletGlobalScope.h
+++ b/layout/style/PaintWorkletGlobalScope.h
@@ -6,34 +6,38 @@
 
 #ifndef mozilla_dom_PaintWorkletGlobalScope_h
 #define mozilla_dom_PaintWorkletGlobalScope_h
 
 #include "mozilla/dom/WorkletGlobalScope.h"
 
 namespace mozilla {
 
-class WorkletImpl;
+class PaintWorkletImpl;
 
 namespace dom {
 
 class VoidFunction;
 
 class PaintWorkletGlobalScope final : public WorkletGlobalScope
 {
 public:
-  explicit PaintWorkletGlobalScope(WorkletImpl* aImpl);
+  explicit PaintWorkletGlobalScope(PaintWorkletImpl* aImpl);
 
   bool
   WrapGlobalObject(JSContext* aCx,
                    JS::MutableHandle<JSObject*> aReflector) override;
 
   void
   RegisterPaint(const nsAString& aType, VoidFunction& aProcessorCtor);
 
+  WorkletImpl* Impl() const override;
+
 private:
   ~PaintWorkletGlobalScope() = default;
+
+  const RefPtr<PaintWorkletImpl> mImpl;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_PaintWorkletGlobalScope_h