зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
4b5c66fc5a
Коммит
1b213a521f
|
@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче