MCPcopy Create free account
hub / github.com/mscdex/ssh2 / _mustCallInner

Function _mustCallInner

test/common.js:50–85  ·  view source on GitHub ↗
(fn, criteria = 1, field)

Source from the content-addressed store, hash-verified

48}
49
50function _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
87function getCallSite(top) {
88 const originalStackFormatter = Error.prepareStackTrace;

Callers 2

mustCallFunction · 0.85
mustCallAtLeastFunction · 0.85

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…