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 <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
1 parent 1015a60 commit 4d73ea7

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed

lib/internal/webstreams/readablestream.js

+1-10
Original file line numberDiff line numberDiff line change
@@ -1132,16 +1132,7 @@ class ReadableByteStreamController {
11321132
enqueue(chunk) {
11331133
if (!isReadableByteStreamController(this))
11341134
throw new ERR_INVALID_THIS('ReadableByteStreamController');
1135-
if (!isArrayBufferView(chunk)) {
1136-
throw new ERR_INVALID_ARG_TYPE(
1137-
'chunk',
1138-
[
1139-
'Buffer',
1140-
'TypedArray',
1141-
'DataView',
1142-
],
1143-
chunk);
1144-
}
1135+
validateBuffer(chunk);
11451136
const chunkByteLength = ArrayBufferViewGetByteLength(chunk);
11461137
const chunkBuffer = ArrayBufferViewGetBuffer(chunk);
11471138
const chunkBufferByteLength = ArrayBufferPrototypeGetByteLength(chunkBuffer);

lib/internal/webstreams/transformstream.js

+5-4
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
const readableType = transformer?.readableType;
123124
const writableType = transformer?.writableType;
124125
const start = 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

+4-3
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
const type = sink?.type;
153154
if (type !== undefined)
154155
throw new ERR_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)