MCPcopy
hub / github.com/cure53/DOMPurify / lookupGetter

Function lookupGetter

src/utils.ts:260–285  ·  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

258 * @returns The getter function found in the prototype chain or a fallback function.
259 */
260function lookupGetter<T extends Record<string, any>>(
261 object: T,
262 prop: string
263): ReturnType<typeof unapply<any>> | (() => null) {
264 while (object !== null) {
265 const desc = getOwnPropertyDescriptor(object, prop);
266
267 if (desc) {
268 if (desc.get) {
269 return unapply(desc.get);
270 }
271
272 if (typeof desc.value === 'function') {
273 return unapply(desc.value);
274 }
275 }
276
277 object = getPrototypeOf(object);
278 }
279
280 function fallbackValue(): null {
281 return null;
282 }
283
284 return fallbackValue;
285}
286
287function isRegex(value: unknown): value is RegExp {
288 try {

Callers 2

createDOMPurifyFunction · 0.85
stringifyValueFunction · 0.85

Calls 1

unapplyFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…