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

Function getUserOptions

lib/internal/util/inspect.js:299–345  ·  view source on GitHub ↗
(ctx, isCrossContext)

Source from the content-addressed store, hash-verified

297let getStringWidth;
298
299function getUserOptions(ctx, isCrossContext) {
300 const ret = {
301 stylize: ctx.stylize,
302 showHidden: ctx.showHidden,
303 depth: ctx.depth,
304 colors: ctx.colors,
305 customInspect: ctx.customInspect,
306 showProxy: ctx.showProxy,
307 maxArrayLength: ctx.maxArrayLength,
308 maxStringLength: ctx.maxStringLength,
309 breakLength: ctx.breakLength,
310 compact: ctx.compact,
311 sorted: ctx.sorted,
312 getters: ctx.getters,
313 numericSeparator: ctx.numericSeparator,
314 ...ctx.userOptions,
315 };
316
317 // Typically, the target value will be an instance of `Object`. If that is
318 // *not* the case, the object may come from another vm.Context, and we want
319 // to avoid passing it objects from this Context in that case, so we remove
320 // the prototype from the returned object itself + the `stylize()` function,
321 // and remove all other non-primitives, including non-primitive user options.
322 if (isCrossContext) {
323 ObjectSetPrototypeOf(ret, null);
324 for (const key of ObjectKeys(ret)) {
325 if ((typeof ret[key] === 'object' || typeof ret[key] === 'function') &&
326 ret[key] !== null) {
327 delete ret[key];
328 }
329 }
330 ret.stylize = ObjectSetPrototypeOf((value, flavour) => {
331 let stylized;
332 try {
333 stylized = `${ctx.stylize(value, flavour)}`;
334 } catch {
335 // Continue regardless of error.
336 }
337
338 if (typeof stylized !== 'string') return value;
339 // `stylized` is a string as it should be, which is safe to pass along.
340 return stylized;
341 }, null);
342 }
343
344 return ret;
345}
346
347/**
348 * Echos the value of any input. Tries to print the value out

Callers 1

formatValueFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…