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

Function addPrototypeProperties

lib/internal/util/inspect.js:970–1023  ·  view source on GitHub ↗
(ctx, main, obj, recurseTimes, output)

Source from the content-addressed store, hash-verified

968// `output` argument (which is an array). This is intended to highlight user
969// defined prototype properties.
970function addPrototypeProperties(ctx, main, obj, recurseTimes, output) {
971 let depth = 0;
972 let keys;
973 let keySet;
974 do {
975 if (depth !== 0 || main === obj) {
976 obj = ObjectGetPrototypeOf(obj);
977 // Stop as soon as a null prototype is encountered.
978 if (obj === null) {
979 return;
980 }
981 // Stop as soon as a built-in object type is detected.
982 const descriptor = ObjectGetOwnPropertyDescriptor(obj, 'constructor');
983 if (descriptor !== undefined &&
984 typeof descriptor.value === 'function' &&
985 builtInObjects.has(descriptor.value.name)) {
986 return;
987 }
988 }
989
990 if (depth === 0) {
991 keySet = new SafeSet();
992 } else {
993 ArrayPrototypeForEach(keys, (key) => keySet.add(key));
994 }
995 // Get all own property names and symbols.
996 keys = ReflectOwnKeys(obj);
997 ArrayPrototypePush(ctx.seen, main);
998 for (const key of keys) {
999 // Ignore the `constructor` property and keys that exist on layers above.
1000 if (key === 'constructor' ||
1001 ObjectPrototypeHasOwnProperty(main, key) ||
1002 (depth !== 0 && keySet.has(key))) {
1003 continue;
1004 }
1005 const desc = ObjectGetOwnPropertyDescriptor(obj, key);
1006 if (typeof desc.value === 'function') {
1007 continue;
1008 }
1009 const value = formatProperty(
1010 ctx, obj, recurseTimes, key, kObjectType, desc, main);
1011 if (ctx.colors) {
1012 // Faint!
1013 ArrayPrototypePush(output, `\u001b[2m${value}\u001b[22m`);
1014 } else {
1015 ArrayPrototypePush(output, value);
1016 }
1017 }
1018 ArrayPrototypePop(ctx.seen);
1019 // Limit the inspection to up to three prototype layers. Using `recurseTimes`
1020 // is not a good choice here, because it's as if the properties are declared
1021 // on the current object from the users perspective.
1022 } while (++depth !== 3);
1023}
1024
1025/** @type {(constructor: string, tag: string, fallback: string, size?: string) => string} */
1026function getPrefix(constructor, tag, fallback, size = '') {

Callers 1

getConstructorNameFunction · 0.85

Calls 3

formatPropertyFunction · 0.85
hasMethod · 0.65
addMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…