Bug 1690111 - Use new TypedArray APIs for appending data to a container. r=farre,extension-reviewers,media-playback-reviewers,kmag,alwu,padenot
Depends on D152494 Differential Revision: https://phabricator.services.mozilla.com/D152495
This commit is contained in:
@@ -325,21 +325,29 @@ void FetchStreamReader::ChunkSteps(JSContext* aCx, JS::Handle<JS::Value> aChunk,
|
||||
CloseAndRelease(aCx, NS_ERROR_DOM_WRONG_TYPE_ERR);
|
||||
return;
|
||||
}
|
||||
chunk.ComputeState();
|
||||
|
||||
MOZ_DIAGNOSTIC_ASSERT(mBuffer.IsEmpty());
|
||||
|
||||
// Let's take a copy of the data.
|
||||
// FIXME: We could sometimes avoid this copy by trying to write `chunk`
|
||||
// directly into `mPipeOut` eagerly, and only filling `mBuffer` if there isn't
|
||||
// enough space in the pipe's buffer.
|
||||
if (!mBuffer.AppendElements(chunk.Data(), chunk.Length(), fallible)) {
|
||||
nsTArray<uint8_t> buffer;
|
||||
if (!chunk.AppendDataTo(buffer)) {
|
||||
CloseAndRelease(aCx, NS_ERROR_OUT_OF_MEMORY);
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t len = buffer.Length();
|
||||
if (len == 0) {
|
||||
// If there is nothing to read, let's do another reading.
|
||||
OnOutputStreamReady(mPipeOut);
|
||||
return;
|
||||
}
|
||||
|
||||
MOZ_DIAGNOSTIC_ASSERT(mBuffer.IsEmpty());
|
||||
|
||||
mBuffer = std::move(buffer);
|
||||
mBufferOffset = 0;
|
||||
mBufferRemaining = chunk.Length();
|
||||
mBufferRemaining = mBuffer.Length();
|
||||
|
||||
nsresult rv = WriteBuffer();
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
|
||||
Reference in New Issue
Block a user