MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / wrapMethod

Function wrapMethod

packages/core/src/utils/object.ts:92–112  ·  view source on GitHub ↗
(
  obj: O,
  field: T,
  wrapped: WrappedFunction,
  enumerable: boolean = true,
)

Source from the content-addressed store, hash-verified

90 * the rare case where we might patch a non-enumerable method.
91 */
92export function wrapMethod<O extends {}, T extends string & keyof O>(
93 obj: O,
94 field: T,
95 wrapped: WrappedFunction,
96 enumerable: boolean = true,
97): void {
98 const original = obj[field];
99 if (typeof original !== 'function') {
100 throw new Error(`Cannot wrap method: ${field} is not a function`);
101 }
102 if (getOriginalFunction(original)) {
103 throw new Error(`Attempting to wrap method ${field} multiple times`);
104 }
105 markFunctionWrapped(wrapped, original);
106 Object.defineProperty(obj, field, {
107 writable: true,
108 configurable: true,
109 enumerable,
110 value: wrapped,
111 });
112}
113
114/**
115 * This extracts the original function if available. See

Callers 4

object.test.tsFile · 0.90
patchHttpRequestFunction · 0.90
patchHttpGetFunction · 0.90
patchExpressModuleFunction · 0.90

Calls 2

getOriginalFunctionFunction · 0.85
markFunctionWrappedFunction · 0.85

Tested by

no test coverage detected