stream: use kEmptyObject

PR-URL: https://github.com/nodejs/node/pull/43159
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
LiviaMedeiros
2022-05-21 17:55:42 +08:00
committed by Antoine du Hamel
parent 8e7e58f6b0
commit a0178a1169
4 changed files with 19 additions and 13 deletions

View File

@@ -11,7 +11,10 @@ const {
ERR_INVALID_ARG_TYPE,
ERR_STREAM_PREMATURE_CLOSE
} = codes;
const { once } = require('internal/util');
const {
kEmptyObject,
once,
} = require('internal/util');
const {
validateAbortSignal,
validateFunction,
@@ -43,9 +46,9 @@ const nop = () => {};
function eos(stream, options, callback) {
if (arguments.length === 2) {
callback = options;
options = {};
options = kEmptyObject;
} else if (options == null) {
options = {};
options = kEmptyObject;
} else {
validateObject(options, 'options');
}

View File

@@ -55,6 +55,7 @@ const {
const {
createDeferredPromise,
kEmptyObject,
} = require('internal/util');
const {
@@ -198,7 +199,7 @@ function newWritableStreamFromStreamWritable(streamWritable) {
* }} [options]
* @returns {Writable}
*/
function newStreamWritableFromWritableStream(writableStream, options = {}) {
function newStreamWritableFromWritableStream(writableStream, options = kEmptyObject) {
if (!isWritableStream(writableStream)) {
throw new ERR_INVALID_ARG_TYPE(
'writableStream',
@@ -441,7 +442,7 @@ function newReadableStreamFromStreamReadable(streamReadable) {
* }} [options]
* @returns {Readable}
*/
function newStreamReadableFromReadableStream(readableStream, options = {}) {
function newStreamReadableFromReadableStream(readableStream, options = kEmptyObject) {
if (!isReadableStream(readableStream)) {
throw new ERR_INVALID_ARG_TYPE(
'readableStream',
@@ -585,7 +586,7 @@ function newReadableWritablePairFromDuplex(duplex) {
* }} [options]
* @returns {Duplex}
*/
function newStreamDuplexFromReadableWritablePair(pair = {}, options = {}) {
function newStreamDuplexFromReadableWritablePair(pair = kEmptyObject, options = kEmptyObject) {
validateObject(pair, 'pair');
const {
readable: readableStream,
@@ -876,7 +877,7 @@ function newWritableStreamFromStreamBase(streamBase, strategy) {
* @param {QueuingStrategy} strategy
* @returns {ReadableStream}
*/
function newReadableStreamFromStreamBase(streamBase, strategy, options = {}) {
function newReadableStreamFromStreamBase(streamBase, strategy, options = kEmptyObject) {
validateObject(streamBase, 'streamBase');
validateObject(options, 'options');

View File

@@ -24,6 +24,7 @@ const {
const {
customInspectSymbol: kInspect,
kEmptyObject,
kEnumerableProperty,
} = require('internal/util');
@@ -114,7 +115,7 @@ class TextDecoderStream {
* ignoreBOM? : boolean,
* }} [options]
*/
constructor(encoding = 'utf-8', options = {}) {
constructor(encoding = 'utf-8', options = kEmptyObject) {
this[kType] = 'TextDecoderStream';
this[kHandle] = new TextDecoder(encoding, options);
this[kTransform] = new TransformStream({

View File

@@ -50,6 +50,7 @@ const {
const {
createDeferredPromise,
customInspectSymbol: kInspect,
kEmptyObject,
kEnumerableProperty,
} = require('internal/util');
@@ -206,7 +207,7 @@ class ReadableStream {
* @param {UnderlyingSource} [source]
* @param {QueuingStrategy} [strategy]
*/
constructor(source = {}, strategy = {}) {
constructor(source = {}, strategy = kEmptyObject) {
if (source === null)
throw new ERR_INVALID_ARG_VALUE('source', 'Object', source);
this[kState] = {
@@ -296,7 +297,7 @@ class ReadableStream {
* }} [options]
* @returns {ReadableStreamReader}
*/
getReader(options = {}) {
getReader(options = kEmptyObject) {
if (!isReadableStream(this))
throw new ERR_INVALID_THIS('ReadableStream');
validateObject(options, 'options', { nullable: true, allowFunction: true });
@@ -315,7 +316,7 @@ class ReadableStream {
* @param {StreamPipeOptions} [options]
* @returns {ReadableStream}
*/
pipeThrough(transform, options = {}) {
pipeThrough(transform, options = kEmptyObject) {
if (!isReadableStream(this))
throw new ERR_INVALID_THIS('ReadableStream');
const readable = transform?.readable;
@@ -365,7 +366,7 @@ class ReadableStream {
* @param {StreamPipeOptions} [options]
* @returns {Promise<void>}
*/
pipeTo(destination, options = {}) {
pipeTo(destination, options = kEmptyObject) {
try {
if (!isReadableStream(this))
throw new ERR_INVALID_THIS('ReadableStream');
@@ -416,7 +417,7 @@ class ReadableStream {
* }} [options]
* @returns {AsyncIterable}
*/
values(options = {}) {
values(options = kEmptyObject) {
if (!isReadableStream(this))
throw new ERR_INVALID_THIS('ReadableStream');
validateObject(options, 'options');