Skip to content

Commit

Permalink
lib: use kEmptyObject and update JSDoc in webstreams
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
deokjinkim authored and juanarbol committed Jan 31, 2023
1 parent 4f2d9ea commit edcd4fc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
11 changes: 1 addition & 10 deletions lib/internal/webstreams/readablestream.js
Expand Up @@ -1132,16 +1132,7 @@ class ReadableByteStreamController {
enqueue(chunk) {
if (!isReadableByteStreamController(this))
throw new ERR_INVALID_THIS('ReadableByteStreamController');
if (!isArrayBufferView(chunk)) {
throw new ERR_INVALID_ARG_TYPE(
'chunk',
[
'Buffer',
'TypedArray',
'DataView',
],
chunk);
}
validateBuffer(chunk);
const chunkByteLength = ArrayBufferViewGetByteLength(chunk);
const chunkBuffer = ArrayBufferViewGetBuffer(chunk);
const chunkBufferByteLength = ArrayBufferPrototypeGetByteLength(chunkBuffer);
Expand Down
9 changes: 5 additions & 4 deletions lib/internal/webstreams/transformstream.js
Expand Up @@ -26,6 +26,7 @@ const {
const {
createDeferredPromise,
customInspectSymbol: kInspect,
kEmptyObject,
kEnumerableProperty,
} = require('internal/util');

Expand Down Expand Up @@ -117,8 +118,8 @@ class TransformStream {
*/
constructor(
transformer = null,
writableStrategy = {},
readableStrategy = {}) {
writableStrategy = kEmptyObject,
readableStrategy = kEmptyObject) {
const readableType = transformer?.readableType;
const writableType = transformer?.writableType;
const start = transformer?.start;
Expand Down Expand Up @@ -292,7 +293,7 @@ class TransformStreamDefaultController {
}

/**
* @param {any} chunk
* @param {any} [chunk]
*/
enqueue(chunk = undefined) {
if (!isTransformStreamDefaultController(this))
Expand All @@ -301,7 +302,7 @@ class TransformStreamDefaultController {
}

/**
* @param {any} reason
* @param {any} [reason]
*/
error(reason = undefined) {
if (!isTransformStreamDefaultController(this))
Expand Down
7 changes: 4 additions & 3 deletions lib/internal/webstreams/writablestream.js
Expand Up @@ -33,6 +33,7 @@ const {
const {
createDeferredPromise,
customInspectSymbol: kInspect,
kEmptyObject,
kEnumerableProperty,
SideEffectFreeRegExpPrototypeSymbolReplace,
} = require('internal/util');
Expand Down Expand Up @@ -148,7 +149,7 @@ class WritableStream {
* @param {UnderlyingSink} [sink]
* @param {QueuingStrategy} [strategy]
*/
constructor(sink = null, strategy = {}) {
constructor(sink = null, strategy = kEmptyObject) {
const type = sink?.type;
if (type !== undefined)
throw new ERR_INVALID_ARG_VALUE.RangeError('type', type);
Expand Down Expand Up @@ -217,7 +218,7 @@ class WritableStream {
}

/**
* @param {any} reason
* @param {any} [reason]
* @returns {Promise<void>}
*/
abort(reason = undefined) {
Expand Down Expand Up @@ -475,7 +476,7 @@ class WritableStreamDefaultWriter {
}

/**
* @param {any} chunk
* @param {any} [chunk]
* @returns {Promise<void>}
*/
write(chunk = undefined) {
Expand Down

0 comments on commit edcd4fc

Please sign in to comment.