Skip to content

Commit

Permalink
Only overwrite globals when running in IE
Browse files Browse the repository at this point in the history
  • Loading branch information
mroderick committed Nov 9, 2016
1 parent ead72f4 commit 5eb4c2c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
15 changes: 10 additions & 5 deletions lolex.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions src/lolex-src.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 5eb4c2c

Please sign in to comment.