* 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)
| 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]); |
no test coverage detected
searching dependent graphs…