Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: use kEmptyObject and update JSDoc in webstreams #46183

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 1 addition & 10 deletions lib/internal/webstreams/readablestream.js
Expand Up @@ -1105,16 +1105,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,
} = require('internal/util');

Expand Down Expand Up @@ -133,7 +134,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 @@ -202,7 +203,7 @@ class WritableStream {
}

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

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