b=991533 throw exception from AudioProcessingEvent buffer getters when allocation fails r=ehsan,bz

--HG--
extra : transplant_source : C%60%E5f6%1D%D3%0F%D6%0B%9CV%A6%AD%C5%5D%E9%9B%C6%BD
This commit is contained in:
Karl Tomlinson 2014-05-16 09:11:13 +12:00
Родитель 4b5c66fc5a
Коммит 1b213a521f
4 изменённых файлов: 36 добавлений и 18 удалений

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

@ -37,23 +37,30 @@ AudioProcessingEvent::WrapObject(JSContext* aCx)
return AudioProcessingEventBinding::Wrap(aCx, this);
}
void
AudioProcessingEvent::LazilyCreateBuffer(nsRefPtr<AudioBuffer>& aBuffer,
uint32_t aNumberOfChannels)
already_AddRefed<AudioBuffer>
AudioProcessingEvent::LazilyCreateBuffer(uint32_t aNumberOfChannels,
ErrorResult& aRv)
{
// We need the global for the context so that we can enter its compartment.
JSObject* global = mNode->Context()->GetGlobalJSObject();
if (NS_WARN_IF(!global)) {
return;
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
AutoJSAPI jsapi;
JSContext* cx = jsapi.cx();
JSAutoCompartment ac(cx, global);
aBuffer = new AudioBuffer(mNode->Context(), mNode->BufferSize(),
mNode->Context()->SampleRate());
aBuffer->InitializeBuffers(aNumberOfChannels, cx);
nsRefPtr<AudioBuffer> buffer =
new AudioBuffer(mNode->Context(), mNode->BufferSize(),
mNode->Context()->SampleRate());
if (!buffer->InitializeBuffers(aNumberOfChannels, cx)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
}
return buffer.forget();
}
}

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

@ -42,18 +42,18 @@ public:
return mPlaybackTime;
}
AudioBuffer* InputBuffer()
AudioBuffer* GetInputBuffer(ErrorResult& aRv)
{
if (!mInputBuffer) {
LazilyCreateBuffer(mInputBuffer, mNumberOfInputChannels);
mInputBuffer = LazilyCreateBuffer(mNumberOfInputChannels, aRv);
}
return mInputBuffer;
}
AudioBuffer* OutputBuffer()
AudioBuffer* GetOutputBuffer(ErrorResult& aRv)
{
if (!mOutputBuffer) {
LazilyCreateBuffer(mOutputBuffer, mNode->NumberOfOutputChannels());
mOutputBuffer = LazilyCreateBuffer(mNode->NumberOfOutputChannels(), aRv);
}
return mOutputBuffer;
}
@ -64,8 +64,8 @@ public:
}
private:
void LazilyCreateBuffer(nsRefPtr<AudioBuffer>& aBuffer,
uint32_t aNumberOfChannels);
already_AddRefed<AudioBuffer>
LazilyCreateBuffer(uint32_t aNumberOfChannels, ErrorResult& rv);
private:
double mPlaybackTime;

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

@ -438,10 +438,18 @@ private:
mPlaybackTime);
node->DispatchTrustedEvent(event);
// Steal the output buffers
// Steal the output buffers if they have been set.
// Don't create a buffer if it hasn't been used to return output;
// FinishProducingOutputBuffer() will optimize output = null.
// GetThreadSharedChannelsForRate() may also return null after OOM.
nsRefPtr<ThreadSharedFloatArrayBufferList> output;
if (event->HasOutputBuffer()) {
output = event->OutputBuffer()->GetThreadSharedChannelsForRate(cx);
ErrorResult rv;
AudioBuffer* buffer = event->GetOutputBuffer(rv);
// HasOutputBuffer() returning true means that GetOutputBuffer()
// will not fail.
MOZ_ASSERT(!rv.Failed());
output = buffer->GetThreadSharedChannelsForRate(cx);
}
// Append it to our output buffer queue

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

@ -12,9 +12,12 @@
interface AudioProcessingEvent : Event {
readonly attribute double playbackTime;
readonly attribute AudioBuffer inputBuffer;
readonly attribute AudioBuffer outputBuffer;
readonly attribute double playbackTime;
[Throws]
readonly attribute AudioBuffer inputBuffer;
[Throws]
readonly attribute AudioBuffer outputBuffer;
};