From 6f5196ab98dbdc04b2234fa69c6eb175410307cd Mon Sep 17 00:00:00 2001 From: Mattias Buelens Date: Sat, 16 Sep 2023 11:38:16 +0200 Subject: [PATCH] Set ReadableStreamBYOBReaderReadOptions.min = 1 by default --- index.bs | 27 +++++++-------- .../lib/ReadableStreamBYOBReader-impl.js | 34 +++++++++---------- .../lib/ReadableStreamBYOBReader.webidl | 2 +- 3 files changed, 30 insertions(+), 33 deletions(-) diff --git a/index.bs b/index.bs index 6759319c3..37bcc90b9 100644 --- a/index.bs +++ b/index.bs @@ -1328,7 +1328,7 @@ interface ReadableStreamBYOBReader { ReadableStreamBYOBReader includes ReadableStreamGenericReader; dictionary ReadableStreamBYOBReaderReadOptions { - [EnforceRange] unsigned long long min; + [EnforceRange] unsigned long long min = 1; }; @@ -1454,20 +1454,19 @@ value: newViewOnSameMemory, done: true } for closed streams. If the strea 1. If ! [$IsDetachedBuffer$](|view|.\[[ViewedArrayBuffer]]) is true, return [=a promise rejected with=] a {{TypeError}} exception. 1. Let |minimumFill| be undefined. - 1. If |options|["{{ReadableStreamBYOBReaderReadOptions/min}}"] was given, - 1. If |options|["{{ReadableStreamBYOBReaderReadOptions/min}}"] is 0, return [=a promise + 1. If |options|["{{ReadableStreamBYOBReaderReadOptions/min}}"] is 0, return [=a promise rejected with=] a {{TypeError}} exception. - 1. If |view| has a \[[TypedArrayName]] internal slot, - 1. If |options|["{{ReadableStreamBYOBReaderReadOptions/min}}"] > |view|.\[[ArrayLength]], - return [=a promise rejected with=] a {{RangeError}} exception. - 1. Let |elementSize| be the element size specified in [=the typed array constructors table=] for - |view|.\[[TypedArrayName]]. - 1. Set |minimumFill| to |options|["{{ReadableStreamBYOBReaderReadOptions/min}}"] * - |elementSize|. - 1. Otherwise (i.e., it is a {{DataView}}), - 1. If |options|["{{ReadableStreamBYOBReaderReadOptions/min}}"] > |view|.\[[ByteLength]], - return [=a promise rejected with=] a {{RangeError}} exception. - 1. Set |minimumFill| to |options|["{{ReadableStreamBYOBReaderReadOptions/min}}"]. + 1. If |view| has a \[[TypedArrayName]] internal slot, + 1. If |options|["{{ReadableStreamBYOBReaderReadOptions/min}}"] > |view|.\[[ArrayLength]], + return [=a promise rejected with=] a {{RangeError}} exception. + 1. Let |elementSize| be the element size specified in [=the typed array constructors table=] for + |view|.\[[TypedArrayName]]. + 1. Set |minimumFill| to |options|["{{ReadableStreamBYOBReaderReadOptions/min}}"] * + |elementSize|. + 1. Otherwise (i.e., it is a {{DataView}}), + 1. If |options|["{{ReadableStreamBYOBReaderReadOptions/min}}"] > |view|.\[[ByteLength]], + return [=a promise rejected with=] a {{RangeError}} exception. + 1. Set |minimumFill| to |options|["{{ReadableStreamBYOBReaderReadOptions/min}}"]. 1. If [=this=].[=ReadableStreamGenericReader/[[stream]]=] is undefined, return [=a promise rejected with=] a {{TypeError}} exception. 1. Let |promise| be [=a new promise=]. diff --git a/reference-implementation/lib/ReadableStreamBYOBReader-impl.js b/reference-implementation/lib/ReadableStreamBYOBReader-impl.js index c70c698c0..6cc982929 100644 --- a/reference-implementation/lib/ReadableStreamBYOBReader-impl.js +++ b/reference-implementation/lib/ReadableStreamBYOBReader-impl.js @@ -23,28 +23,26 @@ class ReadableStreamBYOBReaderImpl { } let minimumFill; - if ('min' in options) { - if (options.min === 0) { + if (options.min === 0) { + return promiseRejectedWith( + new TypeError('options.min must be greater than 0') + ); + } + if (view.constructor !== DataView) { + if (options.min > view.length) { return promiseRejectedWith( - new TypeError('options.min must be greater than 0') + new RangeError('options.min must be less than or equal to view\'s length') ); } - if (view.constructor !== DataView) { - if (options.min > view.length) { - return promiseRejectedWith( - new RangeError('options.min must be less than or equal to view\'s length') - ); - } - const elementSize = view.constructor.BYTES_PER_ELEMENT; - minimumFill = options.min * elementSize; - } else { - if (options.min > view.byteLength) { - return promiseRejectedWith( - new RangeError('options.min must be less than or equal to view\'s byteLength') - ); - } - minimumFill = options.min; + const elementSize = view.constructor.BYTES_PER_ELEMENT; + minimumFill = options.min * elementSize; + } else { + if (options.min > view.byteLength) { + return promiseRejectedWith( + new RangeError('options.min must be less than or equal to view\'s byteLength') + ); } + minimumFill = options.min; } if (this._stream === undefined) { diff --git a/reference-implementation/lib/ReadableStreamBYOBReader.webidl b/reference-implementation/lib/ReadableStreamBYOBReader.webidl index 5e03fc3f4..6967c4311 100644 --- a/reference-implementation/lib/ReadableStreamBYOBReader.webidl +++ b/reference-implementation/lib/ReadableStreamBYOBReader.webidl @@ -8,5 +8,5 @@ interface ReadableStreamBYOBReader { ReadableStreamBYOBReader includes ReadableStreamGenericReader; dictionary ReadableStreamBYOBReaderReadOptions { - [EnforceRange] unsigned long long min; + [EnforceRange] unsigned long long min = 1; };