MCPcopy Index your code
hub / github.com/nodejs/node / formatValue

Function formatValue

lib/internal/util/inspect.js:1108–1204  ·  view source on GitHub ↗
(ctx, value, recurseTimes, typedArray)

Source from the content-addressed store, hash-verified

1106// corrected by setting `ctx.indentationLvL += diff` and then to decrease the
1107// value afterwards again.
1108function formatValue(ctx, value, recurseTimes, typedArray) {
1109 // Primitive types cannot have properties.
1110 if (typeof value !== 'object' &&
1111 typeof value !== 'function' &&
1112 !isUndetectableObject(value)) {
1113 return formatPrimitive(ctx.stylize, value, ctx);
1114 }
1115 if (value === null) {
1116 return ctx.stylize('null', 'null');
1117 }
1118
1119 // Memorize the context for custom inspection on proxies.
1120 const context = value;
1121 let proxies = 0;
1122 // Always check for proxies to prevent side effects and to prevent triggering
1123 // any proxy handlers.
1124 let proxy = getProxyDetails(value, !!ctx.showProxy);
1125 if (proxy !== undefined) {
1126 if (ctx.showProxy) {
1127 if (proxy[0] === null) {
1128 return ctx.stylize('<Revoked Proxy>', 'special');
1129 }
1130 return formatProxy(ctx, proxy, recurseTimes);
1131 }
1132 do {
1133 if (proxy === null) {
1134 let formatted = ctx.stylize('<Revoked Proxy>', 'special');
1135 for (let i = 0; i < proxies; i++) {
1136 formatted = `${ctx.stylize('Proxy(', 'special')}${formatted}${ctx.stylize(')', 'special')}`;
1137 }
1138 return formatted;
1139 }
1140 value = proxy;
1141 proxy = getProxyDetails(value, false);
1142 proxies += 1;
1143 } while (proxy !== undefined);
1144 }
1145
1146 // Provide a hook for user-specified inspect functions.
1147 // Check that value is an object with an inspect function on it.
1148 if (ctx.customInspect) {
1149 const maybeCustom = value[customInspectSymbol];
1150 if (typeof maybeCustom === 'function' &&
1151 // Filter out the util module, its inspect function is special.
1152 maybeCustom !== inspect &&
1153 // Also filter out any prototype objects using the circular check.
1154 ObjectGetOwnPropertyDescriptor(value, 'constructor')?.value?.prototype !== value) {
1155 // This makes sure the recurseTimes are reported as before while using
1156 // a counter internally.
1157 const depth = ctx.depth === null ? null : ctx.depth - recurseTimes;
1158 const isCrossContext =
1159 proxies !== 0 || !FunctionPrototypeSymbolHasInstance(Object, context);
1160 const ret = FunctionPrototypeCall(
1161 maybeCustom,
1162 context,
1163 depth,
1164 getUserOptions(ctx, isCrossContext),
1165 inspect,

Callers 11

inspectFunction · 0.85
formatProxyFunction · 0.85
getFunctionBaseFunction · 0.85
getStackStringFunction · 0.85
formatSetFunction · 0.85
formatMapFunction · 0.85
formatSetIterInnerFunction · 0.85
formatMapIterInnerFunction · 0.85
formatPromiseFunction · 0.85
formatExtraPropertiesFunction · 0.85
formatPropertyFunction · 0.85

Calls 8

isUndetectableObjectFunction · 0.85
formatPrimitiveFunction · 0.85
formatProxyFunction · 0.85
getUserOptionsFunction · 0.85
formatRawFunction · 0.85
includesMethod · 0.80
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…