Don't install the clock if the current timing functions aren't the originals

[finish #64116664] Fix #782
This commit is contained in:
Gregg Van Hove and Nikhil Gajwani
2015-03-27 10:14:03 -07:00
parent 692c8716f0
commit d137b83c1c
3 changed files with 92 additions and 0 deletions

View File

@@ -19,6 +19,9 @@ getJasmineRequireObj().Clock = function() {
self.install = function() {
if(!originalTimingFunctionsIntact()) {
throw new Error('Jasmine Clock was unable to install over custom global timer functions. Is the clock already installed?');
}
replace(global, fakeTimingFunctions);
timer = fakeTimingFunctions;
delayedFunctionScheduler = delayedFunctionSchedulerFactory();
@@ -88,6 +91,13 @@ getJasmineRequireObj().Clock = function() {
return self;
function originalTimingFunctionsIntact() {
return global.setTimeout === realTimingFunctions.setTimeout &&
global.clearTimeout === realTimingFunctions.clearTimeout &&
global.setInterval === realTimingFunctions.setInterval &&
global.clearInterval === realTimingFunctions.clearInterval;
}
function legacyIE() {
//if these methods are polyfilled, apply will be present
return !(realTimingFunctions.setTimeout || realTimingFunctions.setInterval).apply;