bug 1391482 move AudioBuffer parameter checking to constructor r=padenot

for sharing with a new factory method in a future patch.

MozReview-Commit-ID: LAtbRVttMh8

--HG--
extra : rebase_source : 72283c49fd713d0aef3add0eae344da0733149a1
This commit is contained in:
Karl Tomlinson 2017-08-16 17:38:43 +12:00
Родитель 580aed4daa
Коммит 1cd9d48de3
2 изменённых файлов: 17 добавлений и 14 удалений

Просмотреть файл

@ -159,10 +159,22 @@ AudioBufferMemoryTracker::CollectReports(nsIHandleReportCallback* aHandleReport,
AudioBuffer::AudioBuffer(nsPIDOMWindowInner* aWindow,
uint32_t aNumberOfChannels,
uint32_t aLength,
float aSampleRate)
float aSampleRate,
ErrorResult& aRv)
: mOwnerWindow(do_GetWeakReference(aWindow)),
mSampleRate(aSampleRate)
{
// Note that a buffer with zero channels is permitted here for the sake of
// AudioProcessingEvent, where channel counts must match parameters passed
// to createScriptProcessor(), one of which may be zero.
if (aSampleRate < WebAudioUtils::MinSampleRate ||
aSampleRate > WebAudioUtils::MaxSampleRate ||
aNumberOfChannels > WebAudioUtils::MaxChannelCount ||
!aLength || aLength > INT32_MAX) {
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
return;
}
mSharedChannels.mDuration = aLength;
mJSChannels.SetLength(aNumberOfChannels);
mozilla::HoldJSObjects(this);
@ -222,21 +234,12 @@ AudioBuffer::Create(nsPIDOMWindowInner* aWindow, uint32_t aNumberOfChannels,
ErrorResult& aRv)
{
RefPtr<ThreadSharedFloatArrayBufferList> initialContents = aInitialContents;
// Note that a buffer with zero channels is permitted here for the sake of
// AudioProcessingEvent, where channel counts must match parameters passed
// to createScriptProcessor(), one of which may be zero.
if (aSampleRate < WebAudioUtils::MinSampleRate ||
aSampleRate > WebAudioUtils::MaxSampleRate ||
aNumberOfChannels > WebAudioUtils::MaxChannelCount ||
!aLength || aLength > INT32_MAX) {
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
RefPtr<AudioBuffer> buffer =
new AudioBuffer(aWindow, aNumberOfChannels, aLength, aSampleRate, aRv);
if (aRv.Failed()) {
return nullptr;
}
RefPtr<AudioBuffer> buffer =
new AudioBuffer(aWindow, aNumberOfChannels, aLength, aSampleRate);
if (initialContents) {
MOZ_ASSERT(initialContents->GetChannels() == aNumberOfChannels);
buffer->SetSharedChannels(initialContents.forget());

Просмотреть файл

@ -113,7 +113,7 @@ public:
protected:
AudioBuffer(nsPIDOMWindowInner* aWindow, uint32_t aNumberOfChannels,
uint32_t aLength, float aSampleRate);
uint32_t aLength, float aSampleRate, ErrorResult& aRv);
~AudioBuffer();
void