MCPcopy Create free account
hub / github.com/nodejs/node / hasSafeIterator

Function hasSafeIterator

deps/undici/src/lib/core/util.js:322–326  ·  view source on GitHub ↗

* Checks whether an object has a safe Symbol.iterator — i.e. one that is * either own or inherited from a non-Object.prototype chain. This prevents * prototype-pollution attacks from injecting a fake iterator on * Object.prototype. * @param {object} obj * @returns {boolean}

(obj)

Source from the content-addressed store, hash-verified

320 * @returns {boolean}
321 */
322function hasSafeIterator (obj) {
323 const prototype = Object.getPrototypeOf(obj)
324 const ownIterator = Object.hasOwn(obj, Symbol.iterator)
325 return ownIterator || (prototype != null && prototype !== Object.prototype && typeof obj[Symbol.iterator] === 'function')
326}
327
328/**
329 * @param {Blob|Buffer|import ('stream').Stream} body

Callers 2

constructorMethod · 0.70
normalizeHeadersFunction · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected