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

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

Issue 1952793002: Move the exception logic to the AudioNode creator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments 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/PeriodicWave.cpp
diff --git a/third_party/WebKit/Source/modules/webaudio/PeriodicWave.cpp b/third_party/WebKit/Source/modules/webaudio/PeriodicWave.cpp
index f630e8f4acf4983d1b0afc82519145673dcd92ca..cbe3d437b6c15313156e4dd7d2acb873883de5ee 100644
--- a/third_party/WebKit/Source/modules/webaudio/PeriodicWave.cpp
+++ b/third_party/WebKit/Source/modules/webaudio/PeriodicWave.cpp
@@ -27,6 +27,10 @@
*/
#include "modules/webaudio/PeriodicWave.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/OscillatorNode.h"
#include "platform/audio/FFTFrame.h"
#include "platform/audio/VectorMath.h"
@@ -45,17 +49,33 @@ const float CentsPerRange = 1200 / kNumberOfOctaveBands;
using namespace VectorMath;
-PeriodicWave* PeriodicWave::create(float sampleRate, DOMFloat32Array* real, DOMFloat32Array* imag, bool disableNormalization)
+PeriodicWave* PeriodicWave::create(
+ AbstractAudioContext& context,
+ DOMFloat32Array* real,
+ DOMFloat32Array* imag,
+ bool disableNormalization,
+ ExceptionState& exceptionState)
{
- bool isGood = real && imag && real->length() == imag->length();
- ASSERT(isGood);
- if (isGood) {
- PeriodicWave* periodicWave = new PeriodicWave(sampleRate);
- size_t numberOfComponents = real->length();
- periodicWave->createBandLimitedTables(real->data(), imag->data(), numberOfComponents, disableNormalization);
- return periodicWave;
+ DCHECK(isMainThread());
+
+ if (context.isContextClosed()) {
+ context.throwExceptionForClosedState(exceptionState);
+ return nullptr;
+ }
+
+ if (real->length() != imag->length()) {
+ exceptionState.throwDOMException(
+ IndexSizeError,
+ "length of real array (" + String::number(real->length())
+ + ") and length of imaginary array (" + String::number(imag->length())
+ + ") must match.");
+ return nullptr;
}
- return nullptr;
+
+ PeriodicWave* periodicWave = new PeriodicWave(context.sampleRate());
+ size_t numberOfComponents = real->length();
+ periodicWave->createBandLimitedTables(real->data(), imag->data(), numberOfComponents, disableNormalization);
+ return periodicWave;
}
PeriodicWave* PeriodicWave::createSine(float sampleRate)

Powered by Google App Engine
This is Rietveld 408576698