From e417af6c1e20374bb04468fe5a789fef701d0bec Mon Sep 17 00:00:00 2001 From: Alexander Early Date: Wed, 20 May 2015 16:33:05 -0700 Subject: guard against setImmediate mocking. Fixes #609 #611 --- lib/async.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/async.js b/lib/async.js index bbb3495..1e76ee8 100644 --- a/lib/async.js +++ b/lib/async.js @@ -112,11 +112,18 @@ //// exported async module functions //// //// nextTick implementation with browser-compatible fallback //// + + // capture the global reference to guard against fakeTimer mocks + var _setImmediate; + if (typeof setImmediate === 'function') { + _setImmediate = setImmediate; + } + if (typeof process === 'undefined' || !(process.nextTick)) { - if (typeof setImmediate === 'function') { + if (_setImmediate) { async.nextTick = function (fn) { // not a direct alias for IE10 compatibility - setImmediate(fn); + _setImmediate(fn); }; async.setImmediate = async.nextTick; } @@ -129,10 +136,10 @@ } else { async.nextTick = process.nextTick; - if (typeof setImmediate !== 'undefined') { + if (_setImmediate) { async.setImmediate = function (fn) { // not a direct alias for IE10 compatibility - setImmediate(fn); + _setImmediate(fn); }; } else { -- cgit v1.2.1