Bug 1328964 - part 1 - Remove the window from worklet draft
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 16 May 2017 09:51:40 -0400
changeset 697789 9069fb0cca48fff5af285f86fcbaa914239fa2d8
parent 697275 c616a6fd5e4b20cca139fcdd3957682afaa862b9
child 697790 5cbbb77ec4599b90dc30e6af50961cf19e777025
push id89093
push userjbruaroey@mozilla.com
push dateTue, 14 Nov 2017 17:33:26 +0000
bugs1328964
milestone59.0a1
Bug 1328964 - part 1 - Remove the window from worklet MozReview-Commit-ID: 6S52ht1zIGh
dom/worklet/AudioWorkletGlobalScope.cpp
dom/worklet/AudioWorkletGlobalScope.h
dom/worklet/PaintWorkletGlobalScope.cpp
dom/worklet/PaintWorkletGlobalScope.h
dom/worklet/Worklet.cpp
dom/worklet/WorkletGlobalScope.cpp
dom/worklet/WorkletGlobalScope.h
--- a/dom/worklet/AudioWorkletGlobalScope.cpp
+++ b/dom/worklet/AudioWorkletGlobalScope.cpp
@@ -6,22 +6,17 @@
 
 #include "AudioWorkletGlobalScope.h"
 #include "mozilla/dom/AudioWorkletGlobalScopeBinding.h"
 #include "mozilla/dom/FunctionBinding.h"
 
 namespace mozilla {
 namespace dom {
 
-AudioWorkletGlobalScope::AudioWorkletGlobalScope(nsPIDOMWindowInner* aWindow)
-  : WorkletGlobalScope(aWindow)
-{
-}
-
-AudioWorkletGlobalScope::~AudioWorkletGlobalScope()
+AudioWorkletGlobalScope::AudioWorkletGlobalScope()
 {
 }
 
 bool
 AudioWorkletGlobalScope::WrapGlobalObject(JSContext* aCx,
                                           nsIPrincipal* aPrincipal,
                                           JS::MutableHandle<JSObject*> aReflector)
 {
--- a/dom/worklet/AudioWorkletGlobalScope.h
+++ b/dom/worklet/AudioWorkletGlobalScope.h
@@ -12,26 +12,26 @@
 namespace mozilla {
 namespace dom {
 
 class VoidFunction;
 
 class AudioWorkletGlobalScope final : public WorkletGlobalScope
 {
 public:
-  explicit AudioWorkletGlobalScope(nsPIDOMWindowInner* aWindow);
+  AudioWorkletGlobalScope();
 
   bool
   WrapGlobalObject(JSContext* aCx, nsIPrincipal* aPrincipal,
                    JS::MutableHandle<JSObject*> aReflector) override;
 
   void
   RegisterProcessor(const nsAString& aType,
                     VoidFunction& aProcessorCtor);
 
 private:
-  ~AudioWorkletGlobalScope();
+  ~AudioWorkletGlobalScope() = default;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_AudioWorkletGlobalScope_h
--- a/dom/worklet/PaintWorkletGlobalScope.cpp
+++ b/dom/worklet/PaintWorkletGlobalScope.cpp
@@ -6,22 +6,17 @@
 
 #include "PaintWorkletGlobalScope.h"
 #include "mozilla/dom/PaintWorkletGlobalScopeBinding.h"
 #include "mozilla/dom/FunctionBinding.h"
 
 namespace mozilla {
 namespace dom {
 
-PaintWorkletGlobalScope::PaintWorkletGlobalScope(nsPIDOMWindowInner* aWindow)
-  : WorkletGlobalScope(aWindow)
-{
-}
-
-PaintWorkletGlobalScope::~PaintWorkletGlobalScope()
+PaintWorkletGlobalScope::PaintWorkletGlobalScope()
 {
 }
 
 bool
 PaintWorkletGlobalScope::WrapGlobalObject(JSContext* aCx,
                                           nsIPrincipal* aPrincipal,
                                           JS::MutableHandle<JSObject*> aReflector)
 {
--- a/dom/worklet/PaintWorkletGlobalScope.h
+++ b/dom/worklet/PaintWorkletGlobalScope.h
@@ -12,25 +12,25 @@
 namespace mozilla {
 namespace dom {
 
 class VoidFunction;
 
 class PaintWorkletGlobalScope final : public WorkletGlobalScope
 {
 public:
-  explicit PaintWorkletGlobalScope(nsPIDOMWindowInner* aWindow);
+  PaintWorkletGlobalScope();
 
   bool
   WrapGlobalObject(JSContext* aCx, nsIPrincipal* aPrincipal,
                    JS::MutableHandle<JSObject*> aReflector) override;
 
   void
   RegisterPaint(const nsAString& aType, VoidFunction& aProcessorCtor);
 
 private:
-  ~PaintWorkletGlobalScope();
+  ~PaintWorkletGlobalScope() = default;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_PaintWorkletGlobalScope_h
--- a/dom/worklet/Worklet.cpp
+++ b/dom/worklet/Worklet.cpp
@@ -359,20 +359,20 @@ Worklet::Import(const nsAString& aModule
 }
 
 WorkletGlobalScope*
 Worklet::GetOrCreateGlobalScope(JSContext* aCx)
 {
   if (!mScope) {
     switch (mWorkletType) {
       case eAudioWorklet:
-        mScope = new AudioWorkletGlobalScope(mWindow);
+        mScope = new AudioWorkletGlobalScope();
         break;
       case ePaintWorklet:
-        mScope = new PaintWorkletGlobalScope(mWindow);
+        mScope = new PaintWorkletGlobalScope();
         break;
     }
 
     JS::Rooted<JSObject*> global(aCx);
     NS_ENSURE_TRUE(mScope->WrapGlobalObject(aCx, mPrincipal, &global), nullptr);
 
     JSAutoCompartment ac(aCx, global);
 
--- a/dom/worklet/WorkletGlobalScope.cpp
+++ b/dom/worklet/WorkletGlobalScope.cpp
@@ -11,70 +11,68 @@
 
 namespace mozilla {
 namespace dom {
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(WorkletGlobalScope)
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(WorkletGlobalScope)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindow)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mConsole)
   tmp->UnlinkHostObjectURIs();
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(WorkletGlobalScope)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mConsole)
   tmp->TraverseHostObjectURIs(cb);
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(WorkletGlobalScope)
 
 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(nsPIDOMWindowInner* aWindow)
-  : mWindow(aWindow)
-{
-  MOZ_ASSERT(aWindow);
-}
-
-WorkletGlobalScope::~WorkletGlobalScope()
+WorkletGlobalScope::WorkletGlobalScope()
 {
 }
 
 JSObject*
-WorkletGlobalScope::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
+WorkletGlobalScope::WrapObject(JSContext* aCx,
+                               JS::Handle<JSObject*> aGivenProto)
 {
   MOZ_CRASH("We should never get here!");
   return nullptr;
 }
 
 Console*
 WorkletGlobalScope::GetConsole(ErrorResult& aRv)
 {
+  aRv.Throw(NS_ERROR_FAILURE);
+/* TODO
   if (!mConsole) {
-    mConsole = Console::Create(mWindow, aRv);
+    mConsole = Console::CreateForWorklet(aRv);
     if (NS_WARN_IF(aRv.Failed())) {
       return nullptr;
     }
-  }
+  } */
 
   return mConsole;
 }
 
 void
 WorkletGlobalScope::Dump(const Optional<nsAString>& aString) const
 {
+  return;
+
+  // TODO: this is not thread-safe!!
   if (!nsContentUtils::DOMWindowDumpEnabled()) {
     return;
   }
 
   if (!aString.WasPassed()) {
     return;
   }
 
--- a/dom/worklet/WorkletGlobalScope.h
+++ b/dom/worklet/WorkletGlobalScope.h
@@ -13,33 +13,32 @@
 #include "nsIGlobalObject.h"
 #include "nsWrapperCache.h"
 
 #define WORKLET_IID \
   { 0x1b3f62e7, 0xe357, 0x44be, \
     { 0xbf, 0xe0, 0xdf, 0x85, 0xe6, 0x56, 0x85, 0xac } }
 
 class nsIPrincipal;
-class nsPIDOMWindowInner;
 
 namespace mozilla {
 namespace dom {
 
 class Console;
 
 class WorkletGlobalScope : public nsIGlobalObject
                          , 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(nsPIDOMWindowInner* aWindow);
+  WorkletGlobalScope();
 
   nsIGlobalObject* GetParentObject() const
   {
     return nullptr;
   }
 
   virtual JSObject*
   WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
@@ -56,20 +55,19 @@ public:
 
   Console*
   GetConsole(ErrorResult& aRv);
 
   void
   Dump(const Optional<nsAString>& aString) const;
 
 protected:
-  ~WorkletGlobalScope();
+  ~WorkletGlobalScope() = default;
 
 private:
-  nsCOMPtr<nsPIDOMWindowInner> mWindow;
   RefPtr<Console> mConsole;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(WorkletGlobalScope, WORKLET_IID)
 
 } // namespace dom
 } // namespace mozilla