| 1643 | // A recursive function for unwinding a nested array of handlers into a |
| 1644 | // single chain. |
| 1645 | function process(array) { |
| 1646 | for (var i = 0; i < array.length; i++) { |
| 1647 | if (Array.isArray(array[i])) { |
| 1648 | // Recursively call on nested arrays |
| 1649 | process(array[i]); |
| 1650 | continue; |
| 1651 | } |
| 1652 | // If an element of the array isn't an array, ensure it is a |
| 1653 | // handler function and then push it onto the chain of handlers |
| 1654 | assert.func(array[i], 'handler'); |
| 1655 | chain.push(array[i]); |
| 1656 | } |
| 1657 | |
| 1658 | return chain; |
| 1659 | } |
| 1660 | |
| 1661 | // Return the chain, note that if `handlers` is an empty array, this will |
| 1662 | // return an empty array. |