Skip to content

Commit

Permalink
util: simpler module namespace code
Browse files Browse the repository at this point in the history
This removes a special casing for this data type in the main function.

PR-URL: #25255
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
BridgeAR authored and addaleax committed Jan 14, 2019
1 parent a333272 commit 45a8eb6
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,6 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
let braces;
let noIterator = true;
let i = 0;
let skip = false;
const filter = ctx.showHidden ? ALL_PROPERTIES : ONLY_ENUMERABLE;

let extrasType = kObjectType;
Expand Down Expand Up @@ -701,7 +700,6 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
} else if (isModuleNamespaceObject(value)) {
braces[0] = `[${tag}] {`;
formatter = formatNamespaceObject;
skip = true;
} else if (isBoxedPrimitive(value)) {
let type;
if (isNumberObject(value)) {
Expand Down Expand Up @@ -761,11 +759,9 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
const indentationLvl = ctx.indentationLvl;
try {
output = formatter(ctx, value, recurseTimes, keys);
if (skip === false) {
for (i = 0; i < keys.length; i++) {
output.push(
formatProperty(ctx, value, recurseTimes, keys[i], extrasType));
}
for (i = 0; i < keys.length; i++) {
output.push(
formatProperty(ctx, value, recurseTimes, keys[i], extrasType));
}
} catch (err) {
return handleMaxCallStackSize(ctx, err, constructor, tag, indentationLvl);
Expand Down Expand Up @@ -875,9 +871,8 @@ function formatError(value) {
}

function formatNamespaceObject(ctx, value, recurseTimes, keys) {
const len = keys.length;
const output = new Array(len);
for (var i = 0; i < len; i++) {
const output = new Array(keys.length);
for (var i = 0; i < keys.length; i++) {
try {
output[i] = formatProperty(ctx, value, recurseTimes, keys[i],
kObjectType);
Expand All @@ -897,6 +892,8 @@ function formatNamespaceObject(ctx, value, recurseTimes, keys) {
ctx.stylize('<uninitialized>', 'special');
}
}
// Reset the keys to an empty array. This prevents duplicated inspection.
keys.length = 0;
return output;
}

Expand Down

0 comments on commit 45a8eb6

Please sign in to comment.