Bug 1412184 - Set the main thread after BindToOwner in AudioNode ctor. r?smaug draft
authorPaul Adenot <paul@paul.cx>
Mon, 30 Oct 2017 13:13:25 +0100
changeset 688806 39396592558d7aea9eb0c8ef7ac26c490e865313
parent 688337 d3910b7628b8066d3f30d58b17b5824b05768854
child 738169 272c7dd7b9aec2fb20d42b69a79e9ec4a74ffea1
push id86855
push userpaul@paul.cx
push dateMon, 30 Oct 2017 17:56:26 +0000
reviewerssmaug
bugs1412184
milestone58.0a1
Bug 1412184 - Set the main thread after BindToOwner in AudioNode ctor. r?smaug We dont't have a garantee to have a global here. MozReview-Commit-ID: 8aTcYxuVISi
dom/media/webaudio/AudioNode.cpp
dom/media/webaudio/AudioNode.h
--- a/dom/media/webaudio/AudioNode.cpp
+++ b/dom/media/webaudio/AudioNode.cpp
@@ -49,20 +49,26 @@ AudioNode::AudioNode(AudioContext* aCont
                      ChannelInterpretation aChannelInterpretation)
   : DOMEventTargetHelper(aContext->GetParentObject())
   , mContext(aContext)
   , mChannelCount(aChannelCount)
   , mChannelCountMode(aChannelCountMode)
   , mChannelInterpretation(aChannelInterpretation)
   , mId(gId++)
   , mPassThrough(false)
-  , mAbstractMainThread(aContext->GetOwnerGlobal()->AbstractMainThreadFor(TaskCategory::Other))
+  , mAbstractMainThread(nullptr)
 {
   MOZ_ASSERT(aContext);
   DOMEventTargetHelper::BindToOwner(aContext->GetParentObject());
+
+  if (aContext->GetOwnerGlobal()) {
+    mAbstractMainThread =
+      aContext->GetOwnerGlobal()->AbstractMainThreadFor(TaskCategory::Other);
+  }
+
   aContext->RegisterNode(this);
 }
 
 AudioNode::~AudioNode()
 {
   MOZ_ASSERT(mInputNodes.IsEmpty());
   MOZ_ASSERT(mOutputNodes.IsEmpty());
   MOZ_ASSERT(mOutputParams.IsEmpty());
--- a/dom/media/webaudio/AudioNode.h
+++ b/dom/media/webaudio/AudioNode.h
@@ -289,15 +289,15 @@ private:
   uint32_t mChannelCount;
   ChannelCountMode mChannelCountMode;
   ChannelInterpretation mChannelInterpretation;
   const uint32_t mId;
   // Whether the node just passes through its input.  This is a devtools API that
   // only works for some node types.
   bool mPassThrough;
   // DocGroup-specifc AbstractThread::MainThread() for MediaStreamGraph operations.
-  const RefPtr<AbstractThread> mAbstractMainThread;
+  RefPtr<AbstractThread> mAbstractMainThread;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif