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

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

Issue 2561443004: Implementation of ReadableStream pipeTo and pipeThrough (Closed)
Patch Set: Changes from domenic review Created 3 years, 11 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 // Implementation of WritableStream for Blink. See 5 // Implementation of WritableStream for Blink. See
6 // https://streams.spec.whatwg.org/#ws. The implementation closely follows the 6 // https://streams.spec.whatwg.org/#ws. The implementation closely follows the
7 // standard, except where required for performance or integration with Blink. In 7 // standard, except where required for performance or integration with Blink. In
8 // particular, classes, methods and abstract operations are implemented in the 8 // particular, classes, methods and abstract operations are implemented in the
9 // same order as in the standard, to simplify side-by-side reading. 9 // same order as in the standard, to simplify side-by-side reading.
10 10
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 } 357 }
358 if (backpressure) { 358 if (backpressure) {
359 writer[_readyPromise] = v8.createPromise(); 359 writer[_readyPromise] = v8.createPromise();
360 } else { 360 } else {
361 TEMP_ASSERT(backpressure === false, 361 TEMP_ASSERT(backpressure === false,
362 'backpressure is false.'); 362 'backpressure is false.');
363 v8.resolvePromise(writer[_readyPromise], undefined); 363 v8.resolvePromise(writer[_readyPromise], undefined);
364 } 364 }
365 } 365 }
366 366
367 // Functions to expose internals for ReadableStream.pipeTo. These are not
368 // part of the standard.
369 function isWritableStreamErrored(stream) {
370 TEMP_ASSERT(IsWritableStream(stream),
371 '! IsWritableStream(stream) is true.');
372 return stream[_state] === ERRORED;
373 }
374
375 function isWritableStreamClosingOrClosed(stream) {
376 TEMP_ASSERT(IsWritableStream(stream),
377 '! IsWritableStream(stream) is true.');
378 return stream[_state] === CLOSING || stream[_state] === CLOSED;
379 }
380
381 function getWritableStreamStoredError(stream) {
382 TEMP_ASSERT(IsWritableStream(stream),
383 '! IsWritableStream(stream) is true.');
384 return stream[_storedError];
385 }
386
367 class WritableStreamDefaultWriter { 387 class WritableStreamDefaultWriter {
368 constructor(stream) { 388 constructor(stream) {
369 if (!IsWritableStream(stream)) { 389 if (!IsWritableStream(stream)) {
370 throw new TypeError(streamErrors.illegalConstructor); 390 throw new TypeError(streamErrors.illegalConstructor);
371 } 391 }
372 if (IsWritableStreamLocked(stream)) { 392 if (IsWritableStreamLocked(stream)) {
373 throw new TypeError(streamErrors.illegalConstructor); 393 throw new TypeError(streamErrors.illegalConstructor);
374 } 394 }
375 this[_ownerWritableStream] = stream; 395 this[_ownerWritableStream] = stream;
376 stream[_writer] = this; 396 stream[_writer] = this;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 stream[_pendingCloseRequest] = v8.createPromise(); 517 stream[_pendingCloseRequest] = v8.createPromise();
498 if (WritableStreamDefaultControllerGetBackpressure( 518 if (WritableStreamDefaultControllerGetBackpressure(
499 stream[_writableStreamController])) { 519 stream[_writableStreamController])) {
500 v8.resolvePromise(writer[_readyPromise], undefined); 520 v8.resolvePromise(writer[_readyPromise], undefined);
501 } 521 }
502 stream[_state] = CLOSING; 522 stream[_state] = CLOSING;
503 WritableStreamDefaultControllerClose(stream[_writableStreamController]); 523 WritableStreamDefaultControllerClose(stream[_writableStreamController]);
504 return stream[_pendingCloseRequest]; 524 return stream[_pendingCloseRequest];
505 } 525 }
506 526
527 function WritableStreamDefaultWriterCloseWithErrorPropagation(writer) {
528 const stream = writer[_ownerWritableStream];
529 TEMP_ASSERT(stream !== undefined, 'stream is not undefined.');
530 const state = stream[_state];
531 if (state === CLOSING || state === CLOSED) {
532 return Promise_resolve(undefined);
533 }
534 if (state === ERRORED) {
535 return Promise_reject(stream[_storedError]);
536 }
537 TEMP_ASSERT(state === WRITABLE, 'state is "writable".');
538 return WritableStreamDefaultWriterClose(writer);
539 }
540
507 function WritableStreamDefaultWriterGetDesiredSize(writer) { 541 function WritableStreamDefaultWriterGetDesiredSize(writer) {
508 const stream = writer[_ownerWritableStream]; 542 const stream = writer[_ownerWritableStream];
509 const state = stream[_state]; 543 const state = stream[_state];
510 if (state === ERRORED) { 544 if (state === ERRORED) {
511 return null; 545 return null;
512 } 546 }
513 if (state === CLOSED) { 547 if (state === CLOSED) {
514 return 0; 548 return 0;
515 } 549 }
516 return WritableStreamDefaultControllerGetDesiredSize( 550 return WritableStreamDefaultControllerGetDesiredSize(
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 createCannotActionOnStateStreamError('write to', state)); 590 createCannotActionOnStateStreamError('write to', state));
557 } 591 }
558 TEMP_ASSERT(state === WRITABLE, 592 TEMP_ASSERT(state === WRITABLE,
559 'state is "writable".'); 593 'state is "writable".');
560 const promise = WritableStreamAddWriteRequest(stream); 594 const promise = WritableStreamAddWriteRequest(stream);
561 WritableStreamDefaultControllerWrite(stream[_writableStreamController], 595 WritableStreamDefaultControllerWrite(stream[_writableStreamController],
562 chunk); 596 chunk);
563 return promise; 597 return promise;
564 } 598 }
565 599
600 // Functions to expose internals for ReadableStream.pipeTo. These do not
601 // appear in the standard.
602 function getWritableStreamDefaultWriterClosedPromise(writer) {
603 TEMP_ASSERT(IsWritableStreamDefaultWriter(writer),
604 'writer is a WritableStreamDefaultWriter');
605 return writer[_closedPromise];
606 }
607
608 function getWritableStreamDefaultWriterReadyPromise(writer) {
609 TEMP_ASSERT(IsWritableStreamDefaultWriter(writer),
610 'writer is a WritableStreamDefaultWriter');
611 return writer[_readyPromise];
612 }
613
566 class WritableStreamDefaultController { 614 class WritableStreamDefaultController {
567 constructor(stream, underlyingSink, size, highWaterMark) { 615 constructor(stream, underlyingSink, size, highWaterMark) {
568 if (!IsWritableStream(stream)) { 616 if (!IsWritableStream(stream)) {
569 throw new TypeError(streamErrors.illegalConstructor); 617 throw new TypeError(streamErrors.illegalConstructor);
570 } 618 }
571 if (stream[_writableStreamController] !== undefined) { 619 if (stream[_writableStreamController] !== undefined) {
572 throw new TypeError(streamErrors.illegalConstructor); 620 throw new TypeError(streamErrors.illegalConstructor);
573 } 621 }
574 this[_controlledWritableStream] = stream; 622 this[_controlledWritableStream] = stream;
575 this[_underlyingSink] = underlyingSink; 623 this[_underlyingSink] = underlyingSink;
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 // 975 //
928 976
929 defineProperty(global, 'WritableStream', { 977 defineProperty(global, 'WritableStream', {
930 value: WritableStream, 978 value: WritableStream,
931 enumerable: false, 979 enumerable: false,
932 configurable: true, 980 configurable: true,
933 writable: true 981 writable: true
934 }); 982 });
935 983
936 // TODO(ricea): Exports to Blink 984 // TODO(ricea): Exports to Blink
985
986 // Exports for ReadableStream
987 binding.AcquireWritableStreamDefaultWriter =
988 AcquireWritableStreamDefaultWriter;
989 binding.IsWritableStream = IsWritableStream;
990 binding.isWritableStreamClosingOrClosed = isWritableStreamClosingOrClosed;
991 binding.isWritableStreamErrored = isWritableStreamErrored;
992 binding.IsWritableStreamLocked = IsWritableStreamLocked;
993 binding.WritableStreamAbort = WritableStreamAbort;
994 binding.WritableStreamDefaultWriterCloseWithErrorPropagation =
995 WritableStreamDefaultWriterCloseWithErrorPropagation;
996 binding.getWritableStreamDefaultWriterClosedPromise =
997 getWritableStreamDefaultWriterClosedPromise;
998 binding.WritableStreamDefaultWriterGetDesiredSize =
999 WritableStreamDefaultWriterGetDesiredSize;
1000 binding.getWritableStreamDefaultWriterReadyPromise =
1001 getWritableStreamDefaultWriterReadyPromise;
1002 binding.WritableStreamDefaultWriterRelease =
1003 WritableStreamDefaultWriterRelease;
1004 binding.WritableStreamDefaultWriterWrite = WritableStreamDefaultWriterWrite;
1005 binding.getWritableStreamStoredError = getWritableStreamStoredError;
937 }); 1006 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698