(fn, criteria = 1, field)
| 48 | } |
| 49 | |
| 50 | function _mustCallInner(fn, criteria = 1, field) { |
| 51 | if (process._exiting) |
| 52 | throw new Error('Cannot use common.mustCall*() in process exit handler'); |
| 53 | |
| 54 | if (typeof fn === 'number') { |
| 55 | criteria = fn; |
| 56 | fn = noop; |
| 57 | } else if (fn === undefined) { |
| 58 | fn = noop; |
| 59 | } |
| 60 | |
| 61 | if (typeof criteria !== 'number') |
| 62 | throw new TypeError(`Invalid ${field} value: ${criteria}`); |
| 63 | |
| 64 | const context = { |
| 65 | [field]: criteria, |
| 66 | actual: 0, |
| 67 | stack: inspect(new Error()), |
| 68 | name: fn.name || '<anonymous>' |
| 69 | }; |
| 70 | |
| 71 | // Add the exit listener only once to avoid listener leak warnings |
| 72 | if (mustCallChecks.length === 0) |
| 73 | process.on('exit', runCallChecks); |
| 74 | |
| 75 | mustCallChecks.push(context); |
| 76 | |
| 77 | function wrapped(...args) { |
| 78 | ++context.actual; |
| 79 | return fn.call(this, ...args); |
| 80 | } |
| 81 | // TODO: remove origFn? |
| 82 | wrapped.origFn = fn; |
| 83 | |
| 84 | return wrapped; |
| 85 | } |
| 86 | |
| 87 | function getCallSite(top) { |
| 88 | const originalStackFormatter = Error.prepareStackTrace; |
no test coverage detected
searching dependent graphs…