Skip to content

Commit

Permalink
Update Readable Byte Streams with recent spec changes
Browse files Browse the repository at this point in the history
This CL is based on spec changes made in whatwg/streams#1123.

Bug: 1223565
Change-Id: I7235817f6f18e161d721212971c042624df059d2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3216570
Commit-Queue: Nidhi Jaju <nidhijaju@chromium.org>
Reviewed-by: Adam Rice <ricea@chromium.org>
Cr-Commit-Position: refs/heads/main@{#930929}
NOKEYCHECK=True
GitOrigin-RevId: 3280161d249fef949e4901799827ad81f5df082c
  • Loading branch information
nidhijaju authored and copybara-github committed Oct 13, 2021
1 parent cd6b97a commit e297c9d
Show file tree
Hide file tree
Showing 9 changed files with 244 additions and 228 deletions.
317 changes: 208 additions & 109 deletions blink/renderer/core/streams/readable_byte_stream_controller.cc

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions blink/renderer/core/streams/readable_byte_stream_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class ReadableByteStreamController : public ReadableStreamController {
size_t);

explicit PullIntoDescriptor(DOMArrayBuffer* buffer,
size_t buffer_byte_length,
size_t byte_offset,
size_t byte_length,
size_t bytes_filled,
Expand All @@ -98,6 +99,7 @@ class ReadableByteStreamController : public ReadableStreamController {
ReaderType reader_type);

Member<DOMArrayBuffer> buffer;
const size_t buffer_byte_length;
size_t byte_offset;
const size_t byte_length;
size_t bytes_filled;
Expand Down Expand Up @@ -131,7 +133,8 @@ class ReadableByteStreamController : public ReadableStreamController {
// https://streams.spec.whatwg.org/#readable-byte-stream-controller-process-pull-into-descriptors-using-queue
static void ProcessPullIntoDescriptorsUsingQueue(
ScriptState*,
ReadableByteStreamController*);
ReadableByteStreamController*,
ExceptionState&);

// https://streams.spec.whatwg.org/#readable-byte-stream-controller-call-pull-if-needed
static void CallPullIfNeeded(ScriptState*, ReadableByteStreamController*);
Expand All @@ -146,10 +149,13 @@ class ReadableByteStreamController : public ReadableStreamController {
// https://streams.spec.whatwg.org/#readable-byte-stream-controller-commit-pull-into-descriptor
static void CommitPullIntoDescriptor(ScriptState*,
ReadableStream*,
PullIntoDescriptor*);
PullIntoDescriptor*,
ExceptionState&);

// https://streams.spec.whatwg.org/#readable-byte-stream-controller-convert-pull-into-descriptor
static DOMArrayBufferView* ConvertPullIntoDescriptor(PullIntoDescriptor*);
static DOMArrayBufferView* ConvertPullIntoDescriptor(ScriptState*,
PullIntoDescriptor*,
ExceptionState&);

// https://streams.spec.whatwg.org/#readable-byte-stream-controller-clear-pending-pull-intos
static void ClearPendingPullIntos(ReadableByteStreamController*);
Expand Down Expand Up @@ -233,6 +239,9 @@ class ReadableByteStreamController : public ReadableStreamController {
NotShared<DOMArrayBufferView> view,
ExceptionState&);

// https://streams.spec.whatwg.org/#can-transfer-array-buffer
static bool CanTransferArrayBuffer(DOMArrayBuffer* buffer);

// https://streams.spec.whatwg.org/#transfer-array-buffer
static DOMArrayBuffer* TransferArrayBuffer(ScriptState*,
DOMArrayBuffer* buffer,
Expand Down
19 changes: 14 additions & 5 deletions blink/renderer/core/streams/readable_stream_byob_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,16 @@ ScriptPromise ReadableStreamBYOBReader::read(ScriptState* script_state,
return ScriptPromise();
}

// 3. If this.[[stream]] is undefined, return a promise rejected with a
// 3. If ! IsDetachedBuffer(view.[[ViewedArrayBuffer]]) is true, return a
// promise rejected with a TypeError exception.
if (view->buffer()->IsDetached()) {
exception_state.ThrowTypeError(
"This readable stream reader cannot be used to read as the viewed "
"array buffer is detached");
return ScriptPromise();
}

// 4. If this.[[stream]] is undefined, return a promise rejected with a
// TypeError exception.
if (!owner_readable_stream_) {
exception_state.ThrowTypeError(
Expand All @@ -98,10 +107,10 @@ ScriptPromise ReadableStreamBYOBReader::read(ScriptState* script_state,
return ScriptPromise();
}

// 4. Let promise be a new promise.
// 5. Let promise be a new promise.
auto* promise = MakeGarbageCollected<StreamPromiseResolver>(script_state);

// 5. Let readIntoRequest be a new read-into request with the following items:
// 6. Let readIntoRequest be a new read-into request with the following items:
// chunk steps, given chunk
// 1. Resolve promise with «[ "value" → chunk, "done" → false ]».
// close steps, given chunk
Expand All @@ -110,9 +119,9 @@ ScriptPromise ReadableStreamBYOBReader::read(ScriptState* script_state,
// 1. Reject promise with e.
auto* read_into_request = MakeGarbageCollected<ReadIntoRequest>(promise);

// 6. Perform ! ReadableStreamBYOBReaderRead(this, view, readIntoRequest).
// 7. Perform ! ReadableStreamBYOBReaderRead(this, view, readIntoRequest).
Read(script_state, this, view, read_into_request, exception_state);
// 7. Return promise.
// 8. Return promise.
return promise->GetScriptPromise(script_state);
}

Expand Down
23 changes: 9 additions & 14 deletions blink/renderer/core/streams/readable_stream_byob_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void ReadableStreamBYOBRequest::respond(ScriptState* script_state,
"Cannot respond to an invalidated ReadableStreamBYOBRequest");
return;
}
// 2. If IsDetachedBuffer(this.[[view]].[[ArrayBuffer]]) is true, throw a
// 2. If ! IsDetachedBuffer(this.[[view]].[[ArrayBuffer]]) is true, throw a
// TypeError exception.
if (view_->buffer()->IsDetached()) {
exception_state.ThrowTypeError("ArrayBufferView is detached");
Expand All @@ -55,24 +55,19 @@ void ReadableStreamBYOBRequest::respondWithNewView(
NotShared<DOMArrayBufferView> view,
ExceptionState& exception_state) {
// https://streams.spec.whatwg.org/#rs-byob-request-respond-with-new-view
// 1. If view.[[ByteLength]] is 0, throw a TypeError exception.
if (view->byteLength() == 0) {
exception_state.ThrowTypeError("ArrayBufferView is empty");
return;
}
// 2. If view.[[ViewedArrayBuffer]].[[ArrayBufferByteLength]] is 0, throw a
// TypeError exception.
if (view->buffer()->ByteLength() == 0) {
exception_state.ThrowTypeError("ArrayBuffer is empty");
return;
}
// 3. If this.[[controller]] is undefined, throw a TypeError exception.
// 1. If this.[[controller]] is undefined, throw a TypeError exception.
if (!controller_) {
exception_state.ThrowTypeError(
"Cannot respond to an invalidated ReadableStreamBYOBRequest");
return;
}
// 4. Return ?
// 2. If ! IsDetachedBuffer(view.[[ViewedArrayBuffer]]) is true, throw a
// TypeError exception.
if (view->buffer()->IsDetached()) {
exception_state.ThrowTypeError("ViewedArrayBuffer is detached");
return;
}
// 3. Return ?
// ReadableByteStreamControllerRespondWithNewView(this.[[controller]], view).
ReadableByteStreamController::RespondWithNewView(script_state, controller_,
view, exception_state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ v8::Local<v8::Promise> ReadableStreamDefaultController::CancelSteps(
StreamPromiseResolver* ReadableStreamDefaultController::PullSteps(
ScriptState* script_state) {
// https://streams.spec.whatwg.org/#rs-default-controller-private-pull
// 1. Let stream be this.[[controlledReadableStream]].
// 1. Let stream be this.[[stream]].
ReadableStream* stream = controlled_readable_stream_;

// 2. If this.[[queue]] is not empty,
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit e297c9d

Please sign in to comment.