Skip to content

Commit

Permalink
Safely overwrite properties in IE
Browse files Browse the repository at this point in the history
  • Loading branch information
cjohansen committed Jan 6, 2015
1 parent 9502572 commit 9ac6834
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 28 deletions.
2 changes: 2 additions & 0 deletions lib/sinon/util/fake_xdomain_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ if (typeof sinon == "undefined") {

// wrapper for global
(function (global) {
global.XDomainRequest = global.XDomainRequest;

var xdr = { XDomainRequest: global.XDomainRequest };
xdr.GlobalXDomainRequest = global.XDomainRequest;
xdr.supportsXDR = typeof xdr.GlobalXDomainRequest != "undefined";
Expand Down
3 changes: 3 additions & 0 deletions lib/sinon/util/fake_xml_http_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

(function (global) {

global.XMLHttpRequest = global.XMLHttpRequest;
global.ActiveXObject = global.ActiveXObject;

var supportsProgress = typeof ProgressEvent !== "undefined";
var supportsCustomEvent = typeof CustomEvent !== "undefined";
var sinonXhr = { XMLHttpRequest: global.XMLHttpRequest };
Expand Down
19 changes: 2 additions & 17 deletions lib/sinon/util/timers_ie.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,6 @@
* @license BSD
*
* Copyright (c) 2010-2013 Christian Johansen
*
* No longer needed!
*/
function setTimeout() {}
function clearTimeout() {}
function setImmediate() {}
function clearImmediate() {}
function setInterval() {}
function clearInterval() {}
function Date() {}

// Reassign the original functions. Now their writable attribute
// should be true. Hackish, I know, but it works.
setTimeout = sinon.timers.setTimeout;
clearTimeout = sinon.timers.clearTimeout;
setImmediate = sinon.timers.setImmediate;
clearImmediate = sinon.timers.clearImmediate;
setInterval = sinon.timers.setInterval;
clearInterval = sinon.timers.clearInterval;
Date = sinon.timers.Date;
7 changes: 2 additions & 5 deletions lib/sinon/util/xdr_ie.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
* crash.
*
* If you don't require fake XDR to work in IE, don't include this file.
*
* No longer needed!
*/
function XDomainRequest() {}

// Reassign the original function. Now its writable attribute
// should be true. Hackish, I know, but it works.
XDomainRequest = sinon.xdr.XDomainRequest || undefined;
7 changes: 2 additions & 5 deletions lib/sinon/util/xhr_ie.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
* @license BSD
*
* Copyright (c) 2010-2013 Christian Johansen
*
* No longer needed!
*/
function XMLHttpRequest() {}

// Reassign the original function. Now its writable attribute
// should be true. Hackish, I know, but it works.
XMLHttpRequest = sinon.xhr.XMLHttpRequest || undefined;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"dependencies": {
"formatio": "1.1.1",
"util": ">=0.10.3 <1",
"lolex": "1.1.0"
"lolex": "1.2.1"
},
"devDependencies": {
"buster-core": ">=0.6.4",
Expand Down

0 comments on commit 9ac6834

Please sign in to comment.