Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(617)

Unified Diff: third_party/WebKit/Source/modules/webaudio/ChannelSplitterNode.cpp

Issue 1952793002: Move the exception logic to the AudioNode creator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move more things to Node::create() Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/webaudio/ChannelSplitterNode.cpp
diff --git a/third_party/WebKit/Source/modules/webaudio/ChannelSplitterNode.cpp b/third_party/WebKit/Source/modules/webaudio/ChannelSplitterNode.cpp
index 046aa7c1b406909ca6236ea9419d67fa9d897e65..bc1c62963ee95b0df13024f72354539fc634ac51 100644
--- a/third_party/WebKit/Source/modules/webaudio/ChannelSplitterNode.cpp
+++ b/third_party/WebKit/Source/modules/webaudio/ChannelSplitterNode.cpp
@@ -23,6 +23,9 @@
*/
#include "modules/webaudio/ChannelSplitterNode.h"
+#include "bindings/core/v8/ExceptionMessages.h"
+#include "bindings/core/v8/ExceptionState.h"
+#include "core/dom/ExceptionCode.h"
#include "modules/webaudio/AbstractAudioContext.h"
#include "modules/webaudio/AudioNodeInput.h"
#include "modules/webaudio/AudioNodeOutput.h"
@@ -71,17 +74,43 @@ void ChannelSplitterHandler::process(size_t framesToProcess)
// ----------------------------------------------------------------
-ChannelSplitterNode::ChannelSplitterNode(AbstractAudioContext& context, float sampleRate, unsigned numberOfOutputs)
+ChannelSplitterNode::ChannelSplitterNode(AbstractAudioContext& context, unsigned numberOfOutputs)
: AudioNode(context)
{
- setHandler(ChannelSplitterHandler::create(*this, sampleRate, numberOfOutputs));
+ setHandler(ChannelSplitterHandler::create(*this, context.sampleRate(), numberOfOutputs));
}
-ChannelSplitterNode* ChannelSplitterNode::create(AbstractAudioContext& context, float sampleRate, unsigned numberOfOutputs)
+ChannelSplitterNode* ChannelSplitterNode::create(AbstractAudioContext& context, ExceptionState& exceptionState)
{
- if (!numberOfOutputs || numberOfOutputs > AbstractAudioContext::maxNumberOfChannels())
+ ASSERT(isMainThread());
hongchan 2016/05/13 01:20:11 Let's use DCHECK.
Raymond Toy 2016/05/20 23:12:00 Done.
+
+ const unsigned ChannelSplitterDefaultNumberOfOutputs = 6;
+ return create(context, ChannelSplitterDefaultNumberOfOutputs, exceptionState);
+}
+
+ChannelSplitterNode* ChannelSplitterNode::create(AbstractAudioContext& context, unsigned numberOfOutputs, ExceptionState& exceptionState)
+{
+ ASSERT(isMainThread());
hongchan 2016/05/13 01:20:11 Ditto.
Raymond Toy 2016/05/20 23:12:00 Done.
+
+ if (context.isContextClosed()) {
+ context.throwExceptionForClosedState(exceptionState);
return nullptr;
- return new ChannelSplitterNode(context, sampleRate, numberOfOutputs);
+ }
+
+ if (!numberOfOutputs || numberOfOutputs > AbstractAudioContext::maxNumberOfChannels()) {
+ exceptionState.throwDOMException(
+ IndexSizeError,
+ ExceptionMessages::indexOutsideRange<size_t>(
+ "number of outputs",
+ numberOfOutputs,
+ 1,
+ ExceptionMessages::InclusiveBound,
+ AbstractAudioContext::maxNumberOfChannels(),
+ ExceptionMessages::InclusiveBound));
+ return nullptr;
+ }
+
+ return new ChannelSplitterNode(context, numberOfOutputs);
}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698