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
parent 449848718e
commit cff596396d
4 changed files with 36 additions and 18 deletions

View File

@ -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(),
nsRefPtr<AudioBuffer> buffer =
new AudioBuffer(mNode->Context(), mNode->BufferSize(),
mNode->Context()->SampleRate());
aBuffer->InitializeBuffers(aNumberOfChannels, cx);
if (!buffer->InitializeBuffers(aNumberOfChannels, cx)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
}
return buffer.forget();
}
}

View File

@ -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;

View File

@ -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

View File

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