Commit 6b1ba760 authored by Nidhi Jaju's avatar Nidhi Jaju Committed by Commit Bot

Change return type of tee() to sequence<ReadableStream> in WebIDL

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 return type of tee() from |any| to
|sequence<ReadableStream> in readable_stream.idl, and |ScriptValue| to
|HeapVector<Member<ReadableStream>>| in readable_stream.cc. This allows
the code to be slightly simpler as well within
CallTeeAndReturnBranchArray() in the ReadableStream class.

Bug: 1093862
Change-Id: I273e9fa01c5601c578753952c1c0a4b5f8db0fd6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2520638Reviewed-by: default avatarAdam Rice <ricea@chromium.org>
Commit-Queue: Nidhi Jaju <nidhijaju@google.com>
Cr-Commit-Position: refs/heads/master@{#824698}
parent 75711c0e
...@@ -1316,8 +1316,9 @@ ScriptPromise ReadableStream::pipeTo(ScriptState* script_state, ...@@ -1316,8 +1316,9 @@ ScriptPromise ReadableStream::pipeTo(ScriptState* script_state,
return PipeTo(script_state, this, destination, pipe_options); return PipeTo(script_state, this, destination, pipe_options);
} }
ScriptValue ReadableStream::tee(ScriptState* script_state, HeapVector<Member<ReadableStream>> ReadableStream::tee(
ExceptionState& exception_state) { ScriptState* script_state,
ExceptionState& exception_state) {
return CallTeeAndReturnBranchArray(script_state, this, exception_state); return CallTeeAndReturnBranchArray(script_state, this, exception_state);
} }
...@@ -1808,12 +1809,11 @@ int ReadableStream::GetNumReadRequests(const ReadableStream* stream) { ...@@ -1808,12 +1809,11 @@ int ReadableStream::GetNumReadRequests(const ReadableStream* stream) {
// TODO(ricea): Functions for transferable streams. // TODO(ricea): Functions for transferable streams.
// //
ScriptValue ReadableStream::CallTeeAndReturnBranchArray( HeapVector<Member<ReadableStream>> ReadableStream::CallTeeAndReturnBranchArray(
ScriptState* script_state, ScriptState* script_state,
ReadableStream* readable, ReadableStream* readable,
ExceptionState& exception_state) { ExceptionState& exception_state) {
// https://streams.spec.whatwg.org/#rs-tee // https://streams.spec.whatwg.org/#rs-tee
v8::Isolate* isolate = script_state->GetIsolate();
ReadableStream* branch1 = nullptr; ReadableStream* branch1 = nullptr;
ReadableStream* branch2 = nullptr; ReadableStream* branch2 = nullptr;
...@@ -1821,35 +1821,12 @@ ScriptValue ReadableStream::CallTeeAndReturnBranchArray( ...@@ -1821,35 +1821,12 @@ ScriptValue ReadableStream::CallTeeAndReturnBranchArray(
readable->Tee(script_state, &branch1, &branch2, exception_state); readable->Tee(script_state, &branch1, &branch2, exception_state);
if (!branch1 || !branch2) if (!branch1 || !branch2)
return ScriptValue(); return HeapVector<Member<ReadableStream>>();
DCHECK(!exception_state.HadException()); DCHECK(!exception_state.HadException());
// 3. Return ! CreateArrayFromList(branches). // 3. Return ! CreateArrayFromList(branches).
v8::TryCatch block(isolate); return HeapVector<Member<ReadableStream>>({branch1, branch2});
v8::Local<v8::Context> context = script_state->GetContext();
v8::Local<v8::Array> array = v8::Array::New(isolate, 2);
v8::Local<v8::Object> global = context->Global();
v8::Local<v8::Value> v8_branch1 = ToV8(branch1, global, isolate);
if (v8_branch1.IsEmpty()) {
exception_state.RethrowV8Exception(block.Exception());
return ScriptValue();
}
v8::Local<v8::Value> v8_branch2 = ToV8(branch2, global, isolate);
if (v8_branch1.IsEmpty()) {
exception_state.RethrowV8Exception(block.Exception());
return ScriptValue();
}
if (array->Set(context, V8String(isolate, "0"), v8_branch1).IsNothing()) {
exception_state.RethrowV8Exception(block.Exception());
return ScriptValue();
}
if (array->Set(context, V8String(isolate, "1"), v8_branch2).IsNothing()) {
exception_state.RethrowV8Exception(block.Exception());
return ScriptValue();
}
return ScriptValue(script_state->GetIsolate(), array);
} }
} // namespace blink } // namespace blink
...@@ -138,7 +138,7 @@ class CORE_EXPORT ReadableStream : public ScriptWrappable { ...@@ -138,7 +138,7 @@ class CORE_EXPORT ReadableStream : public ScriptWrappable {
ExceptionState&); ExceptionState&);
// https://streams.spec.whatwg.org/#rs-tee // https://streams.spec.whatwg.org/#rs-tee
ScriptValue tee(ScriptState*, ExceptionState&); HeapVector<Member<ReadableStream>> tee(ScriptState*, ExceptionState&);
// TODO(domenic): cloneForBranch2 argument from spec not supported yet // TODO(domenic): cloneForBranch2 argument from spec not supported yet
void Tee(ScriptState*, void Tee(ScriptState*,
...@@ -272,7 +272,7 @@ class CORE_EXPORT ReadableStream : public ScriptWrappable { ...@@ -272,7 +272,7 @@ class CORE_EXPORT ReadableStream : public ScriptWrappable {
// Calls Tee() on |readable|, converts the two branches to a JavaScript array // Calls Tee() on |readable|, converts the two branches to a JavaScript array
// and returns them. // and returns them.
static ScriptValue CallTeeAndReturnBranchArray( static HeapVector<Member<ReadableStream>> CallTeeAndReturnBranchArray(
ScriptState* script_state, ScriptState* script_state,
ReadableStream* readable, ReadableStream* readable,
ExceptionState& exception_state); ExceptionState& exception_state);
......
...@@ -18,5 +18,5 @@ enum ReadableStreamReaderMode { "byob" }; ...@@ -18,5 +18,5 @@ enum ReadableStreamReaderMode { "byob" };
ReadableWritablePair transform, optional StreamPipeOptions options); ReadableWritablePair transform, optional StreamPipeOptions options);
[RaisesException, CallWith=ScriptState, MeasureAs=ReadableStreamPipeTo] Promise<any> pipeTo( [RaisesException, CallWith=ScriptState, MeasureAs=ReadableStreamPipeTo] Promise<any> pipeTo(
WritableStream destination, optional StreamPipeOptions options); WritableStream destination, optional StreamPipeOptions options);
[RaisesException, CallWith=ScriptState] any tee(); [RaisesException, CallWith=ScriptState] sequence<ReadableStream> 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