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: minor cleanup #25149

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ const {
kMaxLength,
kStringMaxLength
} = internalBinding('buffer');
const { isAnyArrayBuffer } = internalBinding('types');
const {
customInspectSymbol,
isInsideNodeModules,
normalizeEncoding,
kIsEncodingSymbol
} = require('internal/util');
const {
isAnyArrayBuffer,
isArrayBufferView,
isUint8Array
} = require('internal/util/types');
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ function startup() {
// TODO(addaleax): Turn into a full runtime deprecation.
const pendingDeprecation = getOptionValue('--pending-deprecation');
const utilBinding = internalBinding('util');
const types = internalBinding('types');
const types = NativeModule.require('internal/util/types');
for (const name of [
'isArrayBuffer', 'isArrayBufferView', 'isAsyncFunction',
'isDataView', 'isDate', 'isExternal', 'isMap', 'isMapIterator',
Expand Down
14 changes: 9 additions & 5 deletions lib/internal/console/constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,15 @@ Console.prototype.table = function(tabularData, properties) {
const final = (k, v) => this.log(cliTable(k, v));

const inspect = (v) => {
const opt = { depth: 0, maxArrayLength: 3 };
if (v !== null && typeof v === 'object' &&
!isArray(v) && ObjectKeys(v).length > 2)
opt.depth = -1;
Object.assign(opt, this[kGetInspectOptions](this._stdout));
const depth = v !== null &&
typeof v === 'object' &&
!isArray(v) &&
ObjectKeys(v).length > 2 ? -1 : 0;
const opt = {
depth,
maxArrayLength: 3,
...this[kGetInspectOptions](this._stdout)
};
return util.inspect(v, opt);
};
const getIndexArray = (length) => ArrayFrom({ length }, (_, i) => inspect(i));
Expand Down
7 changes: 3 additions & 4 deletions lib/internal/encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ const {
customInspectSymbol: inspect
} = require('internal/util');

const { isArrayBufferView } = require('internal/util/types');

const {
isArrayBuffer
} = internalBinding('types');
isArrayBuffer,
isArrayBufferView
} = require('internal/util/types');

const {
encodeUtf8String
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const {
} = internalBinding('util');
const {
isNativeError
} = internalBinding('types');
} = require('internal/util/types');

const { errmap } = internalBinding('uv');

Expand Down
4 changes: 2 additions & 2 deletions lib/internal/util/comparisons.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

const { compare } = internalBinding('buffer');
const { isArrayBufferView } = require('internal/util/types');
const {
isAnyArrayBuffer,
isArrayBufferView,
isDate,
isMap,
isRegExp,
Expand All @@ -15,7 +15,7 @@ const {
isBooleanObject,
isBigIntObject,
isSymbolObject
} = internalBinding('types');
} = require('internal/util/types');
const {
getOwnNonIndexProperties,
propertyFilter: {
Expand Down
14 changes: 7 additions & 7 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ const {
isStackOverflowError
} = require('internal/errors');

const types = internalBinding('types');
Object.assign(types, require('internal/util/types'));
const {
isAnyArrayBuffer,
isArrayBuffer,
Expand All @@ -38,6 +36,8 @@ const {
isExternal,
isMap,
isMapIterator,
isModuleNamespaceObject,
isNativeError,
isPromise,
isSet,
isSetIterator,
Expand All @@ -61,7 +61,7 @@ const {
isFloat64Array,
isBigInt64Array,
isBigUint64Array
} = types;
} = require('internal/util/types');

const ReflectApply = Reflect.apply;

Expand Down Expand Up @@ -385,9 +385,9 @@ function getKeys(value, showHidden) {
try {
keys = Object.keys(value);
} catch (err) {
if (types.isNativeError(err) &&
if (isNativeError(err) &&
err.name === 'ReferenceError' &&
types.isModuleNamespaceObject(value)) {
isModuleNamespaceObject(value)) {
keys = Object.getOwnPropertyNames(value);
} else {
throw err;
Expand Down Expand Up @@ -690,7 +690,7 @@ function formatRaw(ctx, value, recurseTimes) {
} else if (isWeakMap(value)) {
braces[0] = `${getPrefix(constructor, tag, 'WeakMap')}{`;
formatter = ctx.showHidden ? formatWeakMap : formatWeakCollection;
} else if (types.isModuleNamespaceObject(value)) {
} else if (isModuleNamespaceObject(value)) {
braces[0] = `[${tag}] {`;
formatter = formatNamespaceObject;
skip = true;
Expand Down Expand Up @@ -877,7 +877,7 @@ function formatNamespaceObject(ctx, value, recurseTimes, keys) {
output[i] = formatProperty(ctx, value, recurseTimes, keys[i],
kObjectType);
} catch (err) {
if (!(types.isNativeError(err) && err.name === 'ReferenceError')) {
if (!(isNativeError(err) && err.name === 'ReferenceError')) {
throw err;
}
// Use the existing functionality. This makes sure the indentation and
Expand Down
1 change: 1 addition & 0 deletions lib/internal/util/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function isBigUint64Array(value) {
}

module.exports = {
...internalBinding('types'),
isArrayBufferView,
isTypedArray,
isUint8Array,
Expand Down
12 changes: 3 additions & 9 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@ const {
const { validateNumber } = require('internal/validators');
const { TextDecoder, TextEncoder } = require('internal/encoding');
const { isBuffer } = require('buffer').Buffer;

const types = internalBinding('types');
Object.assign(types, require('internal/util/types'));
BridgeAR marked this conversation as resolved.
Show resolved Hide resolved
const {
isRegExp,
isDate,
} = types;
const types = require('internal/util/types');

const {
deprecate,
Expand Down Expand Up @@ -432,9 +426,9 @@ module.exports = exports = {
isString,
isSymbol,
isUndefined,
isRegExp,
isRegExp: types.isRegExp,
isObject,
isDate,
isDate: types.isDate,
isError(e) {
return objectToString(e) === '[object Error]' || e instanceof Error;
},
Expand Down