MCPcopy
hub / github.com/jestjs/jest / _getSlots

Method _getSlots

packages/jest-mock/src/index.ts:506–548  ·  view source on GitHub ↗
(object?: Record<string, any>)

Source from the content-addressed store, hash-verified

504 }
505
506 private _getSlots(object?: Record<string, any>): Array<string> {
507 if (!object) {
508 return [];
509 }
510
511 const slots = new Set<string>();
512 const EnvObjectProto = this._environmentGlobal.Object.prototype;
513 const EnvFunctionProto = this._environmentGlobal.Function.prototype;
514 const EnvRegExpProto = this._environmentGlobal.RegExp.prototype;
515
516 // Also check the builtins in the current context as they leak through
517 // core node modules.
518 const ObjectProto = Object.prototype;
519 const FunctionProto = Function.prototype;
520 const RegExpProto = RegExp.prototype;
521
522 // Properties of Object.prototype, Function.prototype and RegExp.prototype
523 // are never reported as slots
524 while (
525 object != null &&
526 object !== EnvObjectProto &&
527 object !== EnvFunctionProto &&
528 object !== EnvRegExpProto &&
529 object !== ObjectProto &&
530 object !== FunctionProto &&
531 object !== RegExpProto
532 ) {
533 const ownNames = Object.getOwnPropertyNames(object);
534
535 for (const prop of ownNames) {
536 if (!isReadonlyProp(object, prop)) {
537 const propDesc = Object.getOwnPropertyDescriptor(object, prop);
538 if ((propDesc !== undefined && !propDesc.get) || object.__esModule) {
539 slots.add(prop);
540 }
541 }
542 }
543
544 object = Object.getPrototypeOf(object);
545 }
546
547 return [...slots];
548 }
549
550 private _ensureMockConfig(f: Mock): MockFunctionConfig {
551 let config = this._mockConfigRegistry.get(f);

Callers 3

_makeComponentMethod · 0.95
_generateMockMethod · 0.95
getMetadataMethod · 0.95

Calls 3

isReadonlyPropFunction · 0.85
addMethod · 0.45

Tested by

no test coverage detected