From b4f3139fcc56d25ebfe2062c103c27fcb18f53ea Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Wed, 9 Nov 2016 17:14:16 +0100 Subject: [PATCH] Only overwrite globals when running in IE --- lolex.js | 15 ++++++++++----- src/lolex-src.js | 15 ++++++++++----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/lolex.js b/lolex.js index dca19f4d..66fc9d69 100644 --- a/lolex.js +++ b/lolex.js @@ -3,13 +3,18 @@ (function (global) { "use strict"; + var userAgent = global.navigator && global.navigator.userAgent; + var isRunningInIE = userAgent && userAgent.indexOf("MSIE ") > -1; + // Make properties writable in IE, as per // http://www.adequatelygood.com/Replacing-setTimeout-Globally.html - global.setTimeout = global.setTimeout; - global.clearTimeout = global.clearTimeout; - global.setInterval = global.setInterval; - global.clearInterval = global.clearInterval; - global.Date = global.Date; + if (isRunningInIE) { + global.setTimeout = global.setTimeout; + global.clearTimeout = global.clearTimeout; + global.setInterval = global.setInterval; + global.clearInterval = global.clearInterval; + global.Date = global.Date; + } // setImmediate is not a standard function // avoid adding the prop to the window object if not present diff --git a/src/lolex-src.js b/src/lolex-src.js index e8fd3a34..631823da 100644 --- a/src/lolex-src.js +++ b/src/lolex-src.js @@ -1,13 +1,18 @@ (function (global) { "use strict"; + var userAgent = global.navigator && global.navigator.userAgent; + var isRunningInIE = userAgent && userAgent.indexOf("MSIE ") > -1; + // Make properties writable in IE, as per // http://www.adequatelygood.com/Replacing-setTimeout-Globally.html - global.setTimeout = global.setTimeout; - global.clearTimeout = global.clearTimeout; - global.setInterval = global.setInterval; - global.clearInterval = global.clearInterval; - global.Date = global.Date; + if (isRunningInIE) { + global.setTimeout = global.setTimeout; + global.clearTimeout = global.clearTimeout; + global.setInterval = global.setInterval; + global.clearInterval = global.clearInterval; + global.Date = global.Date; + } // setImmediate is not a standard function // avoid adding the prop to the window object if not present