diff --git a/q.js b/q.js index d9405fdc..458c6711 100644 --- a/q.js +++ b/q.js @@ -157,9 +157,16 @@ var nextTick =(function () { } }; - if (typeof process !== "undefined" && process.nextTick) { - // Node.js before 0.9. Note that some fake-Node environments, like the - // Mocha test runner, introduce a `process` global without a `nextTick`. + if (typeof process === "object" && + process.toString() === '[object process]' && process.nextTick) { + // Ensure Q is in a real Node environment, with a `process.nextTick`. + // To see through fake Node environments: + // * Mocha test runner - exposes a `process` global without a `nextTick` + // * Browserify - exposes a `process.nexTick` function that uses + // `setTimeout`. In this case `setImmediate` is preferred because + // it is faster. Browserify's `process.toString()` yields + // '[object Object]', while in a real Node environment + // `process.nextTick()` yields '[object process]'. isNodeJS = true; requestTick = function () {