diff --git a/ospec/ospec.js b/ospec/ospec.js index 05b64f98..91bbc06c 100644 --- a/ospec/ospec.js +++ b/ospec/ospec.js @@ -1,7 +1,7 @@ "use strict" module.exports = new function init() { - var spec = {}, subjects = [], results = [], only = null, ctx = spec, start, stack = 0, hasProcess = typeof process === "object", hasOwn = ({}).hasOwnProperty + var spec = {}, subjects = [], results = [], only = null, ctx = spec, start, stack = 0, nextTickish, hasProcess = typeof process === "object", hasOwn = ({}).hasOwnProperty function o(subject, predicate) { if (predicate === undefined) return new Assert(subject) @@ -67,7 +67,6 @@ module.exports = new function init() { next() function next() { - stack++ if (cursor === fns.length) return var fn = fns[cursor++] @@ -104,8 +103,7 @@ module.exports = new function init() { } else { fn() - if (stack < 5000) next() - else (hasProcess ? process.nextTick : setTimeout)(next, stack = 0) + nextTickish(next) } } } @@ -218,5 +216,14 @@ module.exports = new function init() { if (hasProcess && status === 1) process.exit(1) } + if(hasProcess) { + nextTickish = process.nextTick + } else { + nextTickish = function fakeFastNextTick(fn) { + if (stack++ < 5000) next() + else setTimeout(next, stack = 0) + } + } + return o }