MCPcopy Index your code
hub / github.com/nodejs/node / wrapHook

Function wrapHook

lib/internal/modules/customization_hooks.js:183–196  ·  view source on GitHub ↗

* Helper function to wrap around invocation of user hook or the default step * in order to fill in missing arguments or check returned results. * Due to the merging of the context, this must be a closure. * @param {number} index Index in the chain. Default step is 0, last added hook is 1,

(index, userHookOrDefault, next)

Source from the content-addressed store, hash-verified

181 * @returns {Function} Wrapped hook or default step.
182 */
183 function wrapHook(index, userHookOrDefault, next) {
184 return function nextStep(arg0, context) {
185 lastRunIndex = index;
186 if (context && context !== mergedContext) {
187 ObjectAssign(mergedContext, context);
188 }
189 const hookResult = userHookOrDefault(arg0, mergedContext, next);
190 if (lastRunIndex > 0 && lastRunIndex === index && !hookResult.shortCircuit) {
191 throw new ERR_INVALID_RETURN_PROPERTY_VALUE('true', name, 'shortCircuit',
192 hookResult.shortCircuit);
193 }
194 return validate(arg0, mergedContext, hookResult);
195 };
196 }
197 const chain = [wrapHook(0, defaultStep)];
198 for (let i = 0; i < hooks.length; ++i) {
199 const wrappedHook = wrapHook(i + 1, hooks[i][name], chain[i]);

Callers 1

buildHooksFunction · 0.85

Calls 2

ObjectAssignFunction · 0.85
validateFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…