Skip to content

Commit

Permalink
lib: use kEmptyObject in various places
Browse files Browse the repository at this point in the history
PR-URL: #43159
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
  • Loading branch information
LiviaMedeiros authored and danielleadams committed Jun 13, 2022
1 parent 44b65d0 commit 3b2f7ee
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lib/internal/blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const {
const {
createDeferredPromise,
customInspectSymbol: kInspect,
kEmptyObject,
} = require('internal/util');
const { inspect } = require('internal/util/inspect');

Expand Down Expand Up @@ -134,7 +135,7 @@ class Blob {
* }} [options]
* @constructs {Blob}
*/
constructor(sources = [], options = {}) {
constructor(sources = [], options = kEmptyObject) {
if (sources === null ||
typeof sources[SymbolIterator] !== 'function' ||
typeof sources === 'string') {
Expand Down
9 changes: 5 additions & 4 deletions lib/internal/encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const kEncoder = Symbol('encoder');
const {
getConstructorOf,
customInspectSymbol: inspect,
kEmptyObject,
kEnumerableProperty,
} = require('internal/util');

Expand Down Expand Up @@ -379,7 +380,7 @@ function makeTextDecoderICU() {
} = internalBinding('icu');

class TextDecoder {
constructor(encoding = 'utf-8', options = {}) {
constructor(encoding = 'utf-8', options = kEmptyObject) {
encoding = `${encoding}`;
validateObject(options, 'options', {
nullable: true,
Expand Down Expand Up @@ -408,7 +409,7 @@ function makeTextDecoderICU() {
}


decode(input = empty, options = {}) {
decode(input = empty, options = kEmptyObject) {
validateDecoder(this);
if (isAnyArrayBuffer(input)) {
input = lazyBuffer().from(input);
Expand Down Expand Up @@ -453,7 +454,7 @@ function makeTextDecoderJS() {
}

class TextDecoder {
constructor(encoding = 'utf-8', options = {}) {
constructor(encoding = 'utf-8', options = kEmptyObject) {
encoding = `${encoding}`;
validateObject(options, 'options', {
nullable: true,
Expand Down Expand Up @@ -481,7 +482,7 @@ function makeTextDecoderJS() {
this[kBOMSeen] = false;
}

decode(input = empty, options = {}) {
decode(input = empty, options = kEmptyObject) {
validateDecoder(this);
if (isAnyArrayBuffer(input)) {
input = lazyBuffer().from(input);
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const {

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

const { inspect } = require('util');
Expand Down Expand Up @@ -352,7 +353,7 @@ internalRecordableHistogram.prototype[kDeserialize] = () => {};
* }} [options]
* @returns {RecordableHistogram}
*/
function createHistogram(options = {}) {
function createHistogram(options = kEmptyObject) {
validateObject(options, 'options');
const {
lowest = 1,
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/promise_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {
const { setPromiseHooks } = internalBinding('async_wrap');
const { triggerUncaughtException } = internalBinding('errors');

const { kEmptyObject } = require('internal/util');
const { validatePlainFunction } = require('internal/validators');

const hooks = {
Expand Down Expand Up @@ -101,7 +102,7 @@ const onBefore = makeUseHook('before');
const onAfter = makeUseHook('after');
const onSettled = makeUseHook('settled');

function createHook({ init, before, after, settled } = {}) {
function createHook({ init, before, after, settled } = kEmptyObject) {
const hooks = [];

if (init) ArrayPrototypePush(hooks, onInit(init));
Expand Down

0 comments on commit 3b2f7ee

Please sign in to comment.