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

Function derefWeakRef

packages/core/src/utils/weakRef.ts:48–65  ·  view source on GitHub ↗
(ref: MaybeWeakRef<T> | undefined)

Source from the content-addressed store, hash-verified

46 * @returns The referenced object, or undefined if GC'd or ref was undefined
47 */
48export function derefWeakRef<T extends object>(ref: MaybeWeakRef<T> | undefined): T | undefined {
49 if (!ref) {
50 return undefined;
51 }
52
53 // Check if this is a WeakRef (has deref method)
54 if (typeof ref === 'object' && 'deref' in ref && typeof ref.deref === 'function') {
55 try {
56 return ref.deref();
57 } catch {
58 // deref() failed - treat as GC'd
59 return undefined;
60 }
61 }
62
63 // Direct reference fallback
64 return ref as T;
65}

Callers 4

weakRef.test.tsFile · 0.90
_getSpanForScopeFunction · 0.90
getCapturedScopesOnSpanFunction · 0.90
getContextFromScopeFunction · 0.90

Calls 1

derefMethod · 0.65

Tested by

no test coverage detected