MCPcopy Create free account
hub / github.com/cure53/DOMPurify / lookupGetter

Function lookupGetter

src/utils.ts:288–313  ·  view source on GitHub ↗

* This method automatically checks if the prop is function or getter and behaves accordingly. * * @param object - The object to look up the getter function in its prototype chain. * @param prop - The property name for which to find the getter function. * @returns The getter function found in the

(
  object: T,
  prop: string
)

Source from the content-addressed store, hash-verified

286 * @returns The getter function found in the prototype chain or a fallback function.
287 */
288function lookupGetter<T extends Record<string, any>>(
289 object: T,
290 prop: string
291): ReturnType<typeof unapply<any>> | (() => null) {
292 while (object !== null) {
293 const desc = getOwnPropertyDescriptor(object, prop);
294
295 if (desc) {
296 if (desc.get) {
297 return unapply(desc.get);
298 }
299
300 if (typeof desc.value === 'function') {
301 return unapply(desc.value);
302 }
303 }
304
305 object = getPrototypeOf(object);
306 }
307
308 function fallbackValue(): null {
309 return null;
310 }
311
312 return fallbackValue;
313}
314
315/**
316 * Like lookupGetter, but for accessor properties only, and returns null

Callers 2

createDOMPurifyFunction · 0.85
stringifyValueFunction · 0.85

Calls 1

unapplyFunction · 0.85

Tested by

no test coverage detected