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

Function getConstructorName

lib/internal/util/inspect.js:908–965  ·  view source on GitHub ↗
(obj, ctx, recurseTimes, protoProps)

Source from the content-addressed store, hash-verified

906 .set(WeakSetPrototype, { name: 'WeakSet', constructor: WeakSet });
907
908function getConstructorName(obj, ctx, recurseTimes, protoProps) {
909 let firstProto;
910 const tmp = obj;
911 while (obj || isUndetectableObject(obj)) {
912 const wellKnownPrototypeNameAndConstructor = wellKnownPrototypes.get(obj);
913 if (wellKnownPrototypeNameAndConstructor !== undefined) {
914 const { name, constructor } = wellKnownPrototypeNameAndConstructor;
915 if (FunctionPrototypeSymbolHasInstance(constructor, tmp)) {
916 if (protoProps !== undefined && firstProto !== obj) {
917 addPrototypeProperties(
918 ctx, tmp, firstProto || tmp, recurseTimes, protoProps);
919 }
920 return name;
921 }
922 }
923 const descriptor = ObjectGetOwnPropertyDescriptor(obj, 'constructor');
924 if (descriptor !== undefined &&
925 typeof descriptor.value === 'function' &&
926 descriptor.value.name !== '' &&
927 isInstanceof(tmp, descriptor.value)) {
928 if (protoProps !== undefined &&
929 (firstProto !== obj ||
930 !builtInObjects.has(descriptor.value.name))) {
931 addPrototypeProperties(
932 ctx, tmp, firstProto || tmp, recurseTimes, protoProps);
933 }
934 return String(descriptor.value.name);
935 }
936
937 obj = ObjectGetPrototypeOf(obj);
938 if (firstProto === undefined) {
939 firstProto = obj;
940 }
941 }
942
943 if (firstProto === null) {
944 return null;
945 }
946
947 const res = internalGetConstructorName(tmp);
948
949 if (recurseTimes > ctx.depth && ctx.depth !== null) {
950 return `${res} <Complex prototype>`;
951 }
952
953 const protoConstr = getConstructorName(
954 firstProto, ctx, recurseTimes + 1, protoProps);
955
956 if (protoConstr === null) {
957 return `${res} <${inspect(firstProto, {
958 ...ctx,
959 customInspect: false,
960 depth: -1,
961 })}>`;
962 }
963
964 return `${res} <${protoConstr}>`;
965}

Callers 1

formatRawFunction · 0.85

Calls 7

isUndetectableObjectFunction · 0.85
addPrototypePropertiesFunction · 0.85
isInstanceofFunction · 0.85
StringClass · 0.85
inspectFunction · 0.70
getMethod · 0.65
hasMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…