(
target: any,
name: string,
patchFn: (
delegate: Function,
delegateName: string,
name: string,
) => (self: any, args: any[]) => any,
)
| 422 | } |
| 423 | |
| 424 | export 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 | |
| 463 | export interface MacroTaskMeta extends TaskData { |
| 464 | name: string; |
no test coverage detected
searching dependent graphs…