Bug 1456946 - Don't call AudioNode::Initialize on an ChannelSplitterNode during construction to avoid throwing. r?achronop draft
authorPaul Adenot <paul@paul.cx>
Tue, 29 May 2018 18:15:29 +0200
changeset 801050 684d80309527b038677091be350224eab3019776
parent 801049 75ad1fa6f65390b0c0cdb0c776dbbdc89679685c
child 801051 424399f615323b8c14d4ccc15a50e6622310920c
push id111553
push userpaul@paul.cx
push dateTue, 29 May 2018 16:29:08 +0000
reviewersachronop
bugs1456946
milestone62.0a1
Bug 1456946 - Don't call AudioNode::Initialize on an ChannelSplitterNode during construction to avoid throwing. r?achronop We initialize the channelCountMode and channelInterpretation (that cannot be changed) appropriately in the C++ ctor, and the channelCount manually as well. Then we check manually that the options for the channelCountMode and channelInterpretation have not been passed, and are not incorrect. MozReview-Commit-ID: 4YdYfaGqKqn
dom/media/webaudio/ChannelSplitterNode.cpp
--- a/dom/media/webaudio/ChannelSplitterNode.cpp
+++ b/dom/media/webaudio/ChannelSplitterNode.cpp
@@ -77,18 +77,32 @@ ChannelSplitterNode::Create(AudioContext
       aOptions.mNumberOfOutputs > WebAudioUtils::MaxChannelCount) {
     aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
     return nullptr;
   }
 
   RefPtr<ChannelSplitterNode> audioNode =
     new ChannelSplitterNode(&aAudioContext, aOptions.mNumberOfOutputs);
 
-  audioNode->Initialize(aOptions, aRv);
-  if (NS_WARN_IF(aRv.Failed())) {
+  // Manually check that the other options are valid, this node has channelCount,
+  // channelCountMode and channelInterpretation constraints: they cannot be
+  // changed from the default.
+  if (aOptions.mChannelCount.WasPassed() &&
+      aOptions.mChannelCount.Value() != audioNode->ChannelCount()) {
+    aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
+    return nullptr;
+  }
+  if (aOptions.mChannelInterpretation.WasPassed() &&
+      aOptions.mChannelInterpretation.Value() != audioNode->ChannelInterpretationValue()) {
+    aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
+    return nullptr;
+  }
+  if (aOptions.mChannelCountMode.WasPassed() &&
+      aOptions.mChannelCountMode.Value() != audioNode->ChannelCountModeValue()) {
+    aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return nullptr;
   }
 
   return audioNode.forget();
 }
 
 JSObject*
 ChannelSplitterNode::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)