| OLD | NEW |
| 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 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 WritableStreamDefaultControllerWrite(stream[_writableStreamController], | 492 WritableStreamDefaultControllerWrite(stream[_writableStreamController], |
| 493 chunk); | 493 chunk); |
| 494 return promise; | 494 return promise; |
| 495 } | 495 } |
| 496 | 496 |
| 497 class WritableStreamDefaultController { | 497 class WritableStreamDefaultController { |
| 498 constructor(stream, underlyingSink, size, highWaterMark) { | 498 constructor(stream, underlyingSink, size, highWaterMark) { |
| 499 if (!IsWritableStream(stream)) { | 499 if (!IsWritableStream(stream)) { |
| 500 throw new TypeError(errIllegalConstructor); | 500 throw new TypeError(errIllegalConstructor); |
| 501 } | 501 } |
| 502 if (stream[_controlledWritableStream] !== undefined) { | 502 if (stream[_writableStreamController] !== undefined) { |
| 503 throw new TypeError(errIllegalConstructor); | 503 throw new TypeError(errIllegalConstructor); |
| 504 } | 504 } |
| 505 this[_controlledWritableStream] = stream; | 505 this[_controlledWritableStream] = stream; |
| 506 this[_underlyingSink] = underlyingSink; | 506 this[_underlyingSink] = underlyingSink; |
| 507 this[_queue] = new v8.InternalPackedArray(); | 507 this[_queue] = new v8.InternalPackedArray(); |
| 508 this[_queueSize] = 0; | 508 this[_queueSize] = 0; |
| 509 this[_defaultControllerFlags] = 0; | 509 this[_defaultControllerFlags] = 0; |
| 510 const normalizedStrategy = | 510 const normalizedStrategy = |
| 511 ValidateAndNormalizeQueuingStrategy(size, highWaterMark); | 511 ValidateAndNormalizeQueuingStrategy(size, highWaterMark); |
| 512 this[_strategySize] = normalizedStrategy.size; | 512 this[_strategySize] = normalizedStrategy.size; |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 } | 784 } |
| 785 } | 785 } |
| 786 | 786 |
| 787 // TODO(ricea): Share this operation with ReadableStream.js. | 787 // TODO(ricea): Share this operation with ReadableStream.js. |
| 788 function ValidateAndNormalizeQueuingStrategy(size, highWaterMark) { | 788 function ValidateAndNormalizeQueuingStrategy(size, highWaterMark) { |
| 789 if (size !== undefined && typeof size !== 'function') { | 789 if (size !== undefined && typeof size !== 'function') { |
| 790 throw new TypeError(errSizeNotAFunction); | 790 throw new TypeError(errSizeNotAFunction); |
| 791 } | 791 } |
| 792 | 792 |
| 793 highWaterMark = Number(highWaterMark); | 793 highWaterMark = Number(highWaterMark); |
| 794 if (Number_isNaN(highWaterMark)) { | 794 if (Number_isNaN(highWaterMark) || highWaterMark < 0) { |
| 795 throw new TypeError(errInvalidHWM); | |
| 796 } | |
| 797 if (highWaterMark < 0) { | |
| 798 throw new RangeError(errInvalidHWM); | 795 throw new RangeError(errInvalidHWM); |
| 799 } | 796 } |
| 800 | 797 |
| 801 return {size, highWaterMark}; | 798 return {size, highWaterMark}; |
| 802 } | 799 } |
| 803 | 800 |
| 804 // | 801 // |
| 805 // Additions to the global object | 802 // Additions to the global object |
| 806 // | 803 // |
| 807 | 804 |
| 808 defineProperty(global, 'WritableStream', { | 805 defineProperty(global, 'WritableStream', { |
| 809 value: WritableStream, | 806 value: WritableStream, |
| 810 enumerable: false, | 807 enumerable: false, |
| 811 configurable: true, | 808 configurable: true, |
| 812 writable: true | 809 writable: true |
| 813 }); | 810 }); |
| 814 | 811 |
| 815 // TODO(ricea): Exports to Blink | 812 // TODO(ricea): Exports to Blink |
| 816 }); | 813 }); |
| OLD | NEW |