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

Side by Side Diff: third_party/WebKit/Source/core/streams/ReadableStream.js

Issue 2792513002: Ship ReadableStream pipeTo() (Closed)
Patch Set: Updates to stable interfaces in layout tests 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function(global, binding, v8) { 5 (function(global, binding, v8) {
6 'use strict'; 6 'use strict';
7 7
8 const _reader = v8.createPrivateSymbol('[[reader]]'); 8 const _reader = v8.createPrivateSymbol('[[reader]]');
9 const _storedError = v8.createPrivateSymbol('[[storedError]]'); 9 const _storedError = v8.createPrivateSymbol('[[storedError]]');
10 const _controller = v8.createPrivateSymbol('[[controller]]'); 10 const _controller = v8.createPrivateSymbol('[[controller]]');
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 throw new TypeError(errGetReaderNotByteStream); 169 throw new TypeError(errGetReaderNotByteStream);
170 } 170 }
171 171
172 if (mode === undefined) { 172 if (mode === undefined) {
173 return AcquireReadableStreamDefaultReader(this); 173 return AcquireReadableStreamDefaultReader(this);
174 } 174 }
175 175
176 throw new RangeError(errGetReaderBadMode); 176 throw new RangeError(errGetReaderBadMode);
177 } 177 }
178 178
179 pipeThrough({writable, readable}, options) {
180 this.pipeTo(writable, options);
181 return readable;
domenic 2017/04/03 05:49:30 Shouldn't this mark the promise as handled?
Adam Rice 2017/04/03 15:08:15 I want to update the implementation in a separate
182 }
183
184 pipeTo(dest, {preventClose, preventAbort, preventCancel} = {}) {
185 if (!IsReadableStream(this)) {
186 return Promise_reject(new TypeError(streamErrors.illegalInvocation));
187 }
188
189 if (!binding.IsWritableStream(dest)) {
190 // TODO(ricea): Think about having a better error message.
191 return Promise_reject(new TypeError(streamErrors.illegalInvocation));
192 }
193
194 preventClose = Boolean(preventClose);
195 preventAbort = Boolean(preventAbort);
196 preventCancel = Boolean(preventCancel);
197
198 if (IsReadableStreamLocked(this)) {
199 return Promise_reject(new TypeError(errCannotPipeLockedStream));
200 }
201
202 if (binding.IsWritableStreamLocked(dest)) {
203 return Promise_reject(new TypeError(errCannotPipeToALockedStream));
204 }
205
206 return ReadableStreamPipeTo(this, dest, preventClose, preventAbort,
207 preventCancel);
208 }
209
179 tee() { 210 tee() {
180 if (IsReadableStream(this) === false) { 211 if (IsReadableStream(this) === false) {
181 throw new TypeError(streamErrors.illegalInvocation); 212 throw new TypeError(streamErrors.illegalInvocation);
182 } 213 }
183 214
184 return ReadableStreamTee(this); 215 return ReadableStreamTee(this);
185 } 216 }
186 } 217 }
187 218
188 // TODO(ricea): Move this into the class definition once it ships. 219 function ReadableStreamPipeTo(readable, dest, preventClose, preventAbort,
189 function ReadableStream_prototype_pipeThrough({writable, readable}, options) { 220 preventCancel) {
190 this.pipeTo(writable, options); 221 // assert(IsReadableStream(readable));
191 return readable; 222 // assert(binding.IsWritableStream(dest));
192 } 223 // assert(!IsReadableStreamLocked(readable));
193 224 // assert(!binding.IsWritableStreamLocked(dest));
tyoshino (SeeGerritForStatus) 2017/04/05 06:08:41 Please write some comment in natural language to e
Adam Rice 2017/04/05 07:03:47 Done.
194 // TODO(ricea): Move this into the class definition once it ships.
195 function ReadableStream_prototype_pipeTo(
196 dest, {preventClose, preventAbort, preventCancel} = {}) {
197 if (!IsReadableStream(this)) {
198 return Promise_reject(new TypeError(streamErrors.illegalInvocation));
199 }
200
201 if (!binding.IsWritableStream(dest)) {
202 // TODO(ricea): Think about having a better error message.
203 return Promise_reject(new TypeError(streamErrors.illegalInvocation));
204 }
205
206 preventClose = Boolean(preventClose);
207 preventAbort = Boolean(preventAbort);
208 preventCancel = Boolean(preventCancel);
209
210 const readable = this;
211 if (IsReadableStreamLocked(readable)) {
212 return Promise_reject(new TypeError(errCannotPipeLockedStream));
213 }
214
215 if (binding.IsWritableStreamLocked(dest)) {
216 return Promise_reject(new TypeError(errCannotPipeToALockedStream));
217 }
218 225
219 const reader = AcquireReadableStreamDefaultReader(readable); 226 const reader = AcquireReadableStreamDefaultReader(readable);
220 const writer = binding.AcquireWritableStreamDefaultWriter(dest); 227 const writer = binding.AcquireWritableStreamDefaultWriter(dest);
221 let shuttingDown = false; 228 let shuttingDown = false;
222 const promise = v8.createPromise(); 229 const promise = v8.createPromise();
223 let reading = false; 230 let reading = false;
224 231
225 if (checkInitialState()) { 232 if (checkInitialState()) {
226 // Need to detect closing and error when we are not reading. 233 // Need to detect closing and error when we are not reading.
227 thenPromise(reader[_closedPromise], onReaderClosed, readableError); 234 thenPromise(reader[_closedPromise], onReaderClosed, readableError);
(...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 binding.ReadableStreamDefaultControllerClose = ReadableStreamDefaultController Close; 1108 binding.ReadableStreamDefaultControllerClose = ReadableStreamDefaultController Close;
1102 binding.ReadableStreamDefaultControllerGetDesiredSize = ReadableStreamDefaultC ontrollerGetDesiredSize; 1109 binding.ReadableStreamDefaultControllerGetDesiredSize = ReadableStreamDefaultC ontrollerGetDesiredSize;
1103 binding.ReadableStreamDefaultControllerEnqueue = ReadableStreamDefaultControll erEnqueue; 1110 binding.ReadableStreamDefaultControllerEnqueue = ReadableStreamDefaultControll erEnqueue;
1104 binding.ReadableStreamDefaultControllerError = ReadableStreamDefaultController Error; 1111 binding.ReadableStreamDefaultControllerError = ReadableStreamDefaultController Error;
1105 1112
1106 binding.createReadableStreamWithExternalController = 1113 binding.createReadableStreamWithExternalController =
1107 (underlyingSource, strategy) => { 1114 (underlyingSource, strategy) => {
1108 return new ReadableStream( 1115 return new ReadableStream(
1109 underlyingSource, strategy, createWithExternalControllerSentinel); 1116 underlyingSource, strategy, createWithExternalControllerSentinel);
1110 }; 1117 };
1111
1112 // Temporary exports while pipeTo() and pipeThrough() are behind flags
1113 binding.ReadableStream_prototype_pipeThrough =
1114 ReadableStream_prototype_pipeThrough;
1115 binding.ReadableStream_prototype_pipeTo = ReadableStream_prototype_pipeTo;
1116 }); 1118 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698