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

Function fill

packages/core/src/utils/object.ts:21–46  ·  view source on GitHub ↗
(source: { [key: string]: any }, name: string, replacementFactory: (...args: any[]) => any)

Source from the content-addressed store, hash-verified

19 */
20
21export function fill(source: { [key: string]: any }, name: string, replacementFactory: (...args: any[]) => any): void {
22 if (!(name in source)) {
23 return;
24 }
25
26 // explicitly casting to unknown because we don't know the type of the method initially at all
27 const original = source[name] as unknown;
28
29 if (typeof original !== 'function') {
30 return;
31 }
32
33 const wrapped = replacementFactory(original) as WrappedFunction;
34
35 // Make sure it's a function first, as we need to attach an empty prototype for `defineProperties` to work
36 // otherwise it'll throw "TypeError: Object.defineProperties called on non-object"
37 if (typeof wrapped === 'function') {
38 markFunctionWrapped(wrapped, original);
39 }
40
41 try {
42 source[name] = wrapped;
43 } catch {
44 DEBUG_BUILD && debug.log(`Failed to replace method "${name}" in object`, source);
45 }
46}
47
48/**
49 * Defines a non-enumerable property on the given object.

Callers 15

instrumentBuildCallbackFunction · 0.90
instrumentServerFunction · 0.90
setupOnceFunction · 0.90
setupOnceFunction · 0.90
fillGrpcFunctionFunction · 0.90
object.test.tsFile · 0.90
instrumentConsoleFunction · 0.90
instrumentFetchFunction · 0.90
setupOnceFunction · 0.90
wrapMcpServerWithSentryFunction · 0.90
wrapTransportOnMessageFunction · 0.90

Calls 2

markFunctionWrappedFunction · 0.85
logMethod · 0.65

Tested by

no test coverage detected