MCPcopy Index your code
hub / github.com/angular/angular / patchMethod

Function patchMethod

packages/zone.js/lib/common/utils.ts:424–461  ·  view source on GitHub ↗
(
  target: any,
  name: string,
  patchFn: (
    delegate: Function,
    delegateName: string,
    name: string,
  ) => (self: any, args: any[]) => any,
)

Source from the content-addressed store, hash-verified

422}
423
424export function patchMethod(
425 target: any,
426 name: string,
427 patchFn: (
428 delegate: Function,
429 delegateName: string,
430 name: string,
431 ) => (self: any, args: any[]) => any,
432): Function | null {
433 let proto = target;
434 while (proto && !proto.hasOwnProperty(name)) {
435 proto = ObjectGetPrototypeOf(proto);
436 }
437 if (!proto && target[name]) {
438 // somehow we did not find it, but we can see it. This happens on IE for Window properties.
439 proto = target;
440 }
441
442 const delegateName = zoneSymbol(name);
443 let delegate: Function | null = null;
444 if (proto && (!(delegate = proto[delegateName]) || !proto.hasOwnProperty(delegateName))) {
445 delegate = proto[delegateName] = proto[name];
446 // check whether proto[name] is writable
447 // some property is readonly in safari, such as HtmlCanvasElement.prototype.toBlob
448 const desc = proto && ObjectGetOwnPropertyDescriptor(proto, name);
449 if (isPropertyWritable(desc)) {
450 const patchDelegate = patchFn(delegate!, delegateName, name);
451 proto[name] = function () {
452 return patchDelegate(this, arguments as any);
453 };
454 attachOriginToPatched(proto[name], delegate);
455 if (shouldCopySymbolProperties) {
456 copySymbolProperties(delegate, proto[name]);
457 }
458 }
459 }
460 return delegate;
461}
462
463export interface MacroTaskMeta extends TaskData {
464 name: string;

Callers 7

patchBrowserFunction · 0.90
patchXHRFunction · 0.90
patchPromiseFunction · 0.90
patchTimerFunction · 0.90
util.spec.tsFile · 0.90
patchMacroTaskFunction · 0.85
patchMicroTaskFunction · 0.85

Calls 3

isPropertyWritableFunction · 0.85
attachOriginToPatchedFunction · 0.85
copySymbolPropertiesFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…