Skip to content

Commit

Permalink
Merge pull request #87 from mroderick/only-overwrite-globals-in-ie
Browse files Browse the repository at this point in the history
Fix sinonjs/sinon#1143: Only overwrite globals when running in IE
  • Loading branch information
fatso83 committed Nov 10, 2016
2 parents dfd73f5 + 2ea72ee commit a9c9b7f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 29 deletions.
25 changes: 11 additions & 14 deletions lolex.js
@@ -1,23 +1,20 @@
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.lolex = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
(function (global){
/*global global, window*/
/**
* @author Christian Johansen (christian@cjohansen.no) and contributors
* @license BSD
*
* Copyright (c) 2010-2014 Christian Johansen
*/

(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 Expand Up @@ -175,7 +172,7 @@

timer.id = uniqueTimerId++;
timer.createdAt = clock.now;
timer.callAt = clock.now + (timer.delay || (clock.duringTick ? 1 : 0));
timer.callAt = clock.now + (parseInt(timer.delay) || (clock.duringTick ? 1 : 0));

clock.timers[timer.id] = timer;

Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -23,9 +23,9 @@
"prepublish": "npm run bundle"
},
"devDependencies": {
"eslint": "^3.0.1",
"browserify": "^13.0.1",
"mocha": "^2.5.3",
"eslint": "^3.0.1",
"mocha": "^3.1.2",
"mochify": "^2.18.0",
"referee": "^1.2.0",
"sinon": "^1.17.4"
Expand Down
23 changes: 10 additions & 13 deletions src/lolex-src.js
@@ -1,21 +1,18 @@
/*global global, window*/
/**
* @author Christian Johansen (christian@cjohansen.no) and contributors
* @license BSD
*
* Copyright (c) 2010-2014 Christian Johansen
*/

(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 a9c9b7f

Please sign in to comment.