Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(687)

Unified Diff: third_party/WebKit/Source/core/streams/ReadableStream.js

Issue 2792513002: Ship ReadableStream pipeTo() (Closed)
Patch Set: Add a comment explaining the purpose of the asserts in PipeTo Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/streams/ReadableStream.js
diff --git a/third_party/WebKit/Source/core/streams/ReadableStream.js b/third_party/WebKit/Source/core/streams/ReadableStream.js
index 80580c76e90ad7b5de7c6650a4fea08d785c4911..02f1dbaf73f014e0c6f412460466809e181038be 100644
--- a/third_party/WebKit/Source/core/streams/ReadableStream.js
+++ b/third_party/WebKit/Source/core/streams/ReadableStream.js
@@ -176,45 +176,54 @@
throw new RangeError(errGetReaderBadMode);
}
- tee() {
- if (IsReadableStream(this) === false) {
- throw new TypeError(streamErrors.illegalInvocation);
+ pipeThrough({writable, readable}, options) {
+ this.pipeTo(writable, options);
+ return readable;
+ }
+
+ pipeTo(dest, {preventClose, preventAbort, preventCancel} = {}) {
+ if (!IsReadableStream(this)) {
+ return Promise_reject(new TypeError(streamErrors.illegalInvocation));
}
- return ReadableStreamTee(this);
- }
- }
+ if (!binding.IsWritableStream(dest)) {
+ // TODO(ricea): Think about having a better error message.
+ return Promise_reject(new TypeError(streamErrors.illegalInvocation));
+ }
- // TODO(ricea): Move this into the class definition once it ships.
- function ReadableStream_prototype_pipeThrough({writable, readable}, options) {
- this.pipeTo(writable, options);
- return readable;
- }
+ preventClose = Boolean(preventClose);
+ preventAbort = Boolean(preventAbort);
+ preventCancel = Boolean(preventCancel);
- // TODO(ricea): Move this into the class definition once it ships.
- function ReadableStream_prototype_pipeTo(
- dest, {preventClose, preventAbort, preventCancel} = {}) {
- if (!IsReadableStream(this)) {
- return Promise_reject(new TypeError(streamErrors.illegalInvocation));
- }
+ if (IsReadableStreamLocked(this)) {
+ return Promise_reject(new TypeError(errCannotPipeLockedStream));
+ }
+
+ if (binding.IsWritableStreamLocked(dest)) {
+ return Promise_reject(new TypeError(errCannotPipeToALockedStream));
+ }
- if (!binding.IsWritableStream(dest)) {
- // TODO(ricea): Think about having a better error message.
- return Promise_reject(new TypeError(streamErrors.illegalInvocation));
+ return ReadableStreamPipeTo(this, dest, preventClose, preventAbort,
+ preventCancel);
}
- preventClose = Boolean(preventClose);
- preventAbort = Boolean(preventAbort);
- preventCancel = Boolean(preventCancel);
+ tee() {
+ if (IsReadableStream(this) === false) {
+ throw new TypeError(streamErrors.illegalInvocation);
+ }
- const readable = this;
- if (IsReadableStreamLocked(readable)) {
- return Promise_reject(new TypeError(errCannotPipeLockedStream));
+ return ReadableStreamTee(this);
}
+ }
- if (binding.IsWritableStreamLocked(dest)) {
- return Promise_reject(new TypeError(errCannotPipeToALockedStream));
- }
+ function ReadableStreamPipeTo(readable, dest, preventClose, preventAbort,
+ preventCancel) {
+ // Callers of this function must ensure that the following invariants
+ // are enforced:
+ // assert(IsReadableStream(readable));
+ // assert(binding.IsWritableStream(dest));
+ // assert(!IsReadableStreamLocked(readable));
+ // assert(!binding.IsWritableStreamLocked(dest));
const reader = AcquireReadableStreamDefaultReader(readable);
const writer = binding.AcquireWritableStreamDefaultWriter(dest);
@@ -1108,9 +1117,4 @@
return new ReadableStream(
underlyingSource, strategy, createWithExternalControllerSentinel);
};
-
- // Temporary exports while pipeTo() and pipeThrough() are behind flags
- binding.ReadableStream_prototype_pipeThrough =
- ReadableStream_prototype_pipeThrough;
- binding.ReadableStream_prototype_pipeTo = ReadableStream_prototype_pipeTo;
});

Powered by Google App Engine
This is Rietveld 408576698