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

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

Issue 2561443004: Implementation of ReadableStream pipeTo and pipeThrough (Closed)
Patch Set: Rebase and move includes to .gn 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
« no previous file with comments | « third_party/WebKit/Source/core/streams/ReadableStreamExperimentalPipeTo.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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(
371 IsWritableStream(stream), '! IsWritableStream(stream) is true.');
372 return stream[_state] === ERRORED;
373 }
374
375 function isWritableStreamClosingOrClosed(stream) {
376 TEMP_ASSERT(
377 IsWritableStream(stream), '! IsWritableStream(stream) is true.');
378 return stream[_state] === CLOSING || stream[_state] === CLOSED;
379 }
380
381 function getWritableStreamStoredError(stream) {
382 TEMP_ASSERT(
383 IsWritableStream(stream), '! 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(
604 IsWritableStreamDefaultWriter(writer),
605 'writer is a WritableStreamDefaultWriter.');
606 return writer[_closedPromise];
607 }
608
609 function getWritableStreamDefaultWriterReadyPromise(writer) {
610 TEMP_ASSERT(
611 IsWritableStreamDefaultWriter(writer),
612 'writer is a WritableStreamDefaultWriter.');
613 return writer[_readyPromise];
614 }
615
566 class WritableStreamDefaultController { 616 class WritableStreamDefaultController {
567 constructor(stream, underlyingSink, size, highWaterMark) { 617 constructor(stream, underlyingSink, size, highWaterMark) {
568 if (!IsWritableStream(stream)) { 618 if (!IsWritableStream(stream)) {
569 throw new TypeError(streamErrors.illegalConstructor); 619 throw new TypeError(streamErrors.illegalConstructor);
570 } 620 }
571 if (stream[_writableStreamController] !== undefined) { 621 if (stream[_writableStreamController] !== undefined) {
572 throw new TypeError(streamErrors.illegalConstructor); 622 throw new TypeError(streamErrors.illegalConstructor);
573 } 623 }
574 this[_controlledWritableStream] = stream; 624 this[_controlledWritableStream] = stream;
575 this[_underlyingSink] = underlyingSink; 625 this[_underlyingSink] = underlyingSink;
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 // 977 //
928 978
929 defineProperty(global, 'WritableStream', { 979 defineProperty(global, 'WritableStream', {
930 value: WritableStream, 980 value: WritableStream,
931 enumerable: false, 981 enumerable: false,
932 configurable: true, 982 configurable: true,
933 writable: true 983 writable: true
934 }); 984 });
935 985
936 // TODO(ricea): Exports to Blink 986 // TODO(ricea): Exports to Blink
987
988 // Exports for ReadableStream
989 binding.AcquireWritableStreamDefaultWriter =
990 AcquireWritableStreamDefaultWriter;
991 binding.IsWritableStream = IsWritableStream;
992 binding.isWritableStreamClosingOrClosed = isWritableStreamClosingOrClosed;
993 binding.isWritableStreamErrored = isWritableStreamErrored;
994 binding.IsWritableStreamLocked = IsWritableStreamLocked;
995 binding.WritableStreamAbort = WritableStreamAbort;
996 binding.WritableStreamDefaultWriterCloseWithErrorPropagation =
997 WritableStreamDefaultWriterCloseWithErrorPropagation;
998 binding.getWritableStreamDefaultWriterClosedPromise =
999 getWritableStreamDefaultWriterClosedPromise;
1000 binding.WritableStreamDefaultWriterGetDesiredSize =
1001 WritableStreamDefaultWriterGetDesiredSize;
1002 binding.getWritableStreamDefaultWriterReadyPromise =
1003 getWritableStreamDefaultWriterReadyPromise;
1004 binding.WritableStreamDefaultWriterRelease =
1005 WritableStreamDefaultWriterRelease;
1006 binding.WritableStreamDefaultWriterWrite = WritableStreamDefaultWriterWrite;
1007 binding.getWritableStreamStoredError = getWritableStreamStoredError;
937 }); 1008 });
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/streams/ReadableStreamExperimentalPipeTo.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698