Skip to content

Commit

Permalink
stream: use kEmptyObject
Browse files Browse the repository at this point in the history
PR-URL: #43159
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
  • Loading branch information
LiviaMedeiros authored and danielleadams committed Jun 13, 2022
1 parent 5e98cac commit b200a5f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
9 changes: 6 additions & 3 deletions lib/internal/streams/end-of-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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');
}
Expand Down
9 changes: 5 additions & 4 deletions lib/internal/webstreams/adapters.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const {

const {
createDeferredPromise,
kEmptyObject,
} = require('internal/util');

const {
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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');

Expand Down
3 changes: 2 additions & 1 deletion lib/internal/webstreams/encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const {

const {
customInspectSymbol: kInspect,
kEmptyObject,
kEnumerableProperty,
} = require('internal/util');

Expand Down Expand Up @@ -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({
Expand Down
11 changes: 6 additions & 5 deletions lib/internal/webstreams/readablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const {
const {
createDeferredPromise,
customInspectSymbol: kInspect,
kEmptyObject,
kEnumerableProperty,
} = require('internal/util');

Expand Down Expand Up @@ -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] = {
Expand Down Expand Up @@ -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 });
Expand All @@ -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;
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit b200a5f

Please sign in to comment.