Skip to content

Commit

Permalink
Set ReadableStreamBYOBReaderReadOptions.min = 1 by default
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiasBuelens committed Sep 16, 2023
1 parent 78f7adc commit 6f5196a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 33 deletions.
27 changes: 13 additions & 14 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,7 @@ interface ReadableStreamBYOBReader {
ReadableStreamBYOBReader includes ReadableStreamGenericReader;

dictionary ReadableStreamBYOBReaderReadOptions {
[EnforceRange] unsigned long long min;
[EnforceRange] unsigned long long min = 1;
};
</xmp>

Expand Down Expand Up @@ -1454,20 +1454,19 @@ value: newViewOnSameMemory, done: true }</code> 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}}"] &gt; |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}}"] &gt; |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}}"] &gt; |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}}"] &gt; |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=].
Expand Down
34 changes: 16 additions & 18 deletions reference-implementation/lib/ReadableStreamBYOBReader-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ interface ReadableStreamBYOBReader {
ReadableStreamBYOBReader includes ReadableStreamGenericReader;

dictionary ReadableStreamBYOBReaderReadOptions {
[EnforceRange] unsigned long long min;
[EnforceRange] unsigned long long min = 1;
};

0 comments on commit 6f5196a

Please sign in to comment.