Skip to content

Commit 4d73ea7

Browse files
deokjinkimRafaelGSS
authored andcommitted
lib: use kEmptyObject and update JSDoc in webstreams
Use kEmptyObject as default value of strategy. Plus, make reason and chunk as optional. And refactor to use validateBuffer. Refs: https://github.com/nodejs/node/blob/main/doc/api/webstreams.md#transformstreamdefaultcontrollerenqueuechunk Refs: https://github.com/nodejs/node/blob/main/doc/api/webstreams.md#transformstreamdefaultcontrollererrorreason Refs: https://github.com/nodejs/node/blob/main/doc/api/webstreams.md#writablestreamdefaultwriterabortreason Refs: https://github.com/nodejs/node/blob/main/doc/api/webstreams.md#writablestreamdefaultwriterwritechunk PR-URL: #46183 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
1 parent 1015a60 commit 4d73ea7

3 files changed

Lines changed: 10 additions & 17 deletions

File tree

‎lib/internal/webstreams/readablestream.js‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,16 +1132,7 @@ class ReadableByteStreamController {
11321132
enqueue(chunk){
11331133
if(!isReadableByteStreamController(this))
11341134
thrownewERR_INVALID_THIS('ReadableByteStreamController');
1135-
if(!isArrayBufferView(chunk)){
1136-
thrownewERR_INVALID_ARG_TYPE(
1137-
'chunk',
1138-
[
1139-
'Buffer',
1140-
'TypedArray',
1141-
'DataView',
1142-
],
1143-
chunk);
1144-
}
1135+
validateBuffer(chunk);
11451136
constchunkByteLength=ArrayBufferViewGetByteLength(chunk);
11461137
constchunkBuffer=ArrayBufferViewGetBuffer(chunk);
11471138
constchunkBufferByteLength=ArrayBufferPrototypeGetByteLength(chunkBuffer);

‎lib/internal/webstreams/transformstream.js‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const {
2626
const{
2727
createDeferredPromise,
2828
customInspectSymbol: kInspect,
29+
kEmptyObject,
2930
kEnumerableProperty,
3031
}=require('internal/util');
3132

@@ -117,8 +118,8 @@ class TransformStream {
117118
*/
118119
constructor(
119120
transformer=null,
120-
writableStrategy={},
121-
readableStrategy={}){
121+
writableStrategy=kEmptyObject,
122+
readableStrategy=kEmptyObject){
122123
constreadableType=transformer?.readableType;
123124
constwritableType=transformer?.writableType;
124125
conststart=transformer?.start;
@@ -292,7 +293,7 @@ class TransformStreamDefaultController {
292293
}
293294

294295
/**
295-
* @param {any} chunk
296+
* @param {any} [chunk]
296297
*/
297298
enqueue(chunk=undefined){
298299
if(!isTransformStreamDefaultController(this))
@@ -301,7 +302,7 @@ class TransformStreamDefaultController {
301302
}
302303

303304
/**
304-
* @param {any} reason
305+
* @param {any} [reason]
305306
*/
306307
error(reason=undefined){
307308
if(!isTransformStreamDefaultController(this))

‎lib/internal/webstreams/writablestream.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const {
3333
const{
3434
createDeferredPromise,
3535
customInspectSymbol: kInspect,
36+
kEmptyObject,
3637
kEnumerableProperty,
3738
SideEffectFreeRegExpPrototypeSymbolReplace,
3839
}=require('internal/util');
@@ -148,7 +149,7 @@ class WritableStream {
148149
* @param {UnderlyingSink} [sink]
149150
* @param {QueuingStrategy} [strategy]
150151
*/
151-
constructor(sink=null,strategy={}){
152+
constructor(sink=null,strategy=kEmptyObject){
152153
consttype=sink?.type;
153154
if(type!==undefined)
154155
thrownewERR_INVALID_ARG_VALUE.RangeError('type',type);
@@ -217,7 +218,7 @@ class WritableStream {
217218
}
218219

219220
/**
220-
* @param {any} reason
221+
* @param {any} [reason]
221222
* @returns {Promise<void>}
222223
*/
223224
abort(reason=undefined){
@@ -475,7 +476,7 @@ class WritableStreamDefaultWriter {
475476
}
476477

477478
/**
478-
* @param {any} chunk
479+
* @param {any} [chunk]
479480
* @returns {Promise<void>}
480481
*/
481482
write(chunk=undefined){

0 commit comments

Comments
 (0)