Commit 3000cdbe authored by Nidhi Jaju's avatar Nidhi Jaju Committed by Commit Bot

Change parameter of pipeTo to WritableStream

In an effort to change the blink implementation of readable streams to
better match the Web IDL descriptions in the Streams API Standard, this
CL changes the first parameter of pipeTo() in readable_stream.idl to
WritableStream type based on https://streams.spec.whatwg.org/#ref-for-rs-pipe-to%E2%91%A1.

This CL also modifies the ordering and comments within pipeTo()
inside the ReadableStream class to better reflect the steps outlined
in https://streams.spec.whatwg.org/#rs-pipe-to.

Bug: 1093862
Change-Id: Id6029dc3dc0551e59c812daac499a8e538f3be75
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2505333Reviewed-by: default avatarAdam Rice <ricea@chromium.org>
Commit-Queue: Nidhi Jaju <nidhijaju@google.com>
Cr-Commit-Position: refs/heads/master@{#822055}
parent 34ec06a4
......@@ -1325,47 +1325,37 @@ ScriptValue ReadableStream::pipeThrough(ScriptState* script_state,
}
ScriptPromise ReadableStream::pipeTo(ScriptState* script_state,
ScriptValue destination,
WritableStream* destination,
ExceptionState& exception_state) {
return pipeTo(script_state, destination, StreamPipeOptions::Create(),
exception_state);
}
ScriptPromise ReadableStream::pipeTo(ScriptState* script_state,
ScriptValue destination_value,
WritableStream* destination,
const StreamPipeOptions* options,
ExceptionState& exception_state) {
// https://streams.spec.whatwg.org/#rs-pipe-to
// 2. If ! IsWritableStream(dest) is false, return a promise rejected with a
// TypeError exception.
// TODO(ricea): Do this in the IDL instead.
WritableStream* destination = V8WritableStream::ToImplWithTypeCheck(
script_state->GetIsolate(), destination_value.V8Value());
if (!destination) {
exception_state.ThrowTypeError("Illegal invocation");
return ScriptPromise();
}
// 3. If signal is not undefined, and signal is not an instance of the
// AbortSignal interface, return a promise rejected with a TypeError
// exception.
auto* pipe_options = MakeGarbageCollected<PipeOptions>(options);
// 4. If ! IsReadableStreamLocked(this) is true, return a promise rejected
// with a TypeError exception.
// 1. If ! IsReadableStreamLocked(this) is true, return a promise rejected
// with a TypeError exception.
if (IsLocked(this)) {
exception_state.ThrowTypeError("Cannot pipe a locked stream");
return ScriptPromise();
}
// 5. If ! IsWritableStreamLocked(dest) is true, return a promise rejected
// with a TypeError exception.
// 2. If ! IsWritableStreamLocked(destination) is true, return a promise
// rejected with a TypeError exception.
if (WritableStream::IsLocked(destination)) {
exception_state.ThrowTypeError("Cannot pipe to a locked stream");
return ScriptPromise();
}
// 3. Let signal be options["signal"] if it exists, or undefined otherwise.
auto* pipe_options = MakeGarbageCollected<PipeOptions>(options);
// 4. Return ! ReadableStreamPipeTo(this, destination,
// options["preventClose"], options["preventAbort"],
// options["preventCancel"], signal).
return PipeTo(script_state, this, destination, pipe_options);
}
......
......@@ -125,11 +125,13 @@ class CORE_EXPORT ReadableStream : public ScriptWrappable {
const StreamPipeOptions* options,
ExceptionState&);
ScriptPromise pipeTo(ScriptState*, ScriptValue destination, ExceptionState&);
ScriptPromise pipeTo(ScriptState*,
WritableStream* destination,
ExceptionState&);
// https://streams.spec.whatwg.org/#rs-pipe-to
ScriptPromise pipeTo(ScriptState*,
ScriptValue destination_value,
WritableStream* destination,
const StreamPipeOptions* options,
ExceptionState&);
......
......@@ -15,6 +15,6 @@
[RaisesException, CallWith=ScriptState, MeasureAs=ReadableStreamPipeThrough] any pipeThrough(
any transformStream, optional StreamPipeOptions options);
[RaisesException, CallWith=ScriptState, MeasureAs=ReadableStreamPipeTo] Promise<any> pipeTo(
any destination, optional StreamPipeOptions options);
WritableStream destination, optional StreamPipeOptions options);
[RaisesException, CallWith=ScriptState] any tee();
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment