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

Unified Diff: third_party/WebKit/Source/modules/webaudio/ScriptProcessorNode.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/ScriptProcessorNode.cpp
diff --git a/third_party/WebKit/Source/modules/webaudio/ScriptProcessorNode.cpp b/third_party/WebKit/Source/modules/webaudio/ScriptProcessorNode.cpp
index 6f26b7d3d951a565623fab7b6ed7e101915fbb99..9ad4e6e31490a8fd3238a222dc03189ad1332f4f 100644
--- a/third_party/WebKit/Source/modules/webaudio/ScriptProcessorNode.cpp
+++ b/third_party/WebKit/Source/modules/webaudio/ScriptProcessorNode.cpp
@@ -259,8 +259,75 @@ static size_t chooseBufferSize()
return bufferSize;
}
-ScriptProcessorNode* ScriptProcessorNode::create(AbstractAudioContext& context, float sampleRate, size_t bufferSize, unsigned numberOfInputChannels, unsigned numberOfOutputChannels)
+ScriptProcessorNode* ScriptProcessorNode::create(
+ AbstractAudioContext& context,
+ ExceptionState& exceptionState)
{
+ ASSERT(isMainThread());
hongchan 2016/05/13 01:20:13 DCHECK.
Raymond Toy 2016/05/20 23:12:01 Done.
+
+ return create(context, 0, 2, 2, exceptionState);
+}
+
+ScriptProcessorNode* ScriptProcessorNode::create(
+ AbstractAudioContext& context,
+ size_t bufferSize,
+ ExceptionState& exceptionState)
+{
+ ASSERT(isMainThread());
hongchan 2016/05/13 01:20:13 Ditto.
Raymond Toy 2016/05/20 23:12:01 Done.
+
+ return create(context, bufferSize, 2, 2, exceptionState);
+}
+
+ScriptProcessorNode* ScriptProcessorNode::create(
+ AbstractAudioContext& context,
+ size_t bufferSize,
+ unsigned numberOfInputChannels,
+ ExceptionState& exceptionState)
+{
+ ASSERT(isMainThread());
hongchan 2016/05/13 01:20:13 Ditto.
Raymond Toy 2016/05/20 23:12:01 Done.
+
+ return create(context, bufferSize, numberOfInputChannels, 2, exceptionState);
+}
+
+ScriptProcessorNode* ScriptProcessorNode::create(
+ AbstractAudioContext& context,
+ size_t bufferSize,
+ unsigned numberOfInputChannels,
+ unsigned numberOfOutputChannels,
+ ExceptionState& exceptionState)
+{
+ ASSERT(isMainThread());
+
+ if (context.isContextClosed()) {
+ context.throwExceptionForClosedState(exceptionState);
+ return nullptr;
+ }
+
+ if (numberOfInputChannels == 0 && numberOfOutputChannels == 0) {
+ exceptionState.throwDOMException(
+ IndexSizeError,
+ "number of input channels and output channels cannot both be zero.");
hongchan 2016/05/13 01:20:13 input channels and output channels => input and ou
Raymond Toy 2016/05/13 16:36:01 I chose this originally to kind of match the text
+ return nullptr;
+ }
+
+ if (numberOfInputChannels > AbstractAudioContext::maxNumberOfChannels()) {
+ exceptionState.throwDOMException(
+ IndexSizeError,
+ "number of input channels (" + String::number(numberOfInputChannels)
+ + ") exceeds maximum ("
+ + String::number(AbstractAudioContext::maxNumberOfChannels()) + ").");
+ return nullptr;
+ }
+
+ if (numberOfOutputChannels > AbstractAudioContext::maxNumberOfChannels()) {
+ exceptionState.throwDOMException(
+ IndexSizeError,
+ "number of output channels (" + String::number(numberOfInputChannels)
+ + ") exceeds maximum ("
+ + String::number(AbstractAudioContext::maxNumberOfChannels()) + ").");
+ return nullptr;
+ }
+
hongchan 2016/05/13 01:20:13 In the change above, we have few "80-col" issues.
// Check for valid buffer size.
switch (bufferSize) {
case 0:
@@ -275,19 +342,21 @@ ScriptProcessorNode* ScriptProcessorNode::create(AbstractAudioContext& context,
case 16384:
break;
default:
+ exceptionState.throwDOMException(
+ IndexSizeError,
+ "buffer size (" + String::number(bufferSize)
+ + ") must be 0 or a power of two between 256 and 16384.");
return nullptr;
}
- if (!numberOfInputChannels && !numberOfOutputChannels)
- return nullptr;
+ ScriptProcessorNode* node = new ScriptProcessorNode(context, context.sampleRate(), bufferSize, numberOfInputChannels, numberOfOutputChannels);
hongchan 2016/05/13 01:20:13 Let's wrap arguments.
- if (numberOfInputChannels > AbstractAudioContext::maxNumberOfChannels())
- return nullptr;
-
- if (numberOfOutputChannels > AbstractAudioContext::maxNumberOfChannels())
- return nullptr;
+ if (node) {
+ // context keeps reference until we stop making javascript rendering callbacks
hongchan 2016/05/13 01:20:13 If we move this comment above |if (node)| Then we
hongchan 2016/05/20 21:28:32 Perhaps it needs one more look here?
Raymond Toy 2016/05/20 21:46:09 I like the braces; moving the comment out just so
hongchan 2016/05/20 22:57:48 It goes both ways. Without braces, we can easily t
+ context.notifySourceNodeStartedProcessing(node);
+ }
- return new ScriptProcessorNode(context, sampleRate, bufferSize, numberOfInputChannels, numberOfOutputChannels);
+ return node;
hongchan 2016/05/13 01:20:13 The same issue before - we should return node when
hongchan 2016/05/20 21:28:32 Is this addressed somewhere?
Raymond Toy 2016/05/20 21:46:09 If line 352 fails to create a ScriptProcessor, nod
hongchan 2016/05/20 22:57:48 But can we be explicit about that? We can easily r
}
size_t ScriptProcessorNode::bufferSize() const

Powered by Google App Engine
This is Rietveld 408576698