[Finishes #40853563] Allowed the DelayedFunctionScheduler to support strings that are eval'd
This commit is contained in:
@@ -866,12 +866,21 @@ getJasmineRequireObj().DelayedFunctionScheduler = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
self.scheduleFunction = function(funcToCall, millis, params, recurring, timeoutKey, runAtMillis) {
|
self.scheduleFunction = function(funcToCall, millis, params, recurring, timeoutKey, runAtMillis) {
|
||||||
|
var f;
|
||||||
|
if (typeof(funcToCall) === 'string') {
|
||||||
|
/* jshint evil: true */
|
||||||
|
f = function() { return eval(funcToCall); };
|
||||||
|
/* jshint evil: false */
|
||||||
|
} else {
|
||||||
|
f = funcToCall;
|
||||||
|
}
|
||||||
|
|
||||||
millis = millis || 0;
|
millis = millis || 0;
|
||||||
timeoutKey = timeoutKey || ++delayedFnCount;
|
timeoutKey = timeoutKey || ++delayedFnCount;
|
||||||
runAtMillis = runAtMillis || (currentTime + millis);
|
runAtMillis = runAtMillis || (currentTime + millis);
|
||||||
scheduledFunctions[timeoutKey] = {
|
scheduledFunctions[timeoutKey] = {
|
||||||
runAtMillis: runAtMillis,
|
runAtMillis: runAtMillis,
|
||||||
funcToCall: funcToCall,
|
funcToCall: f,
|
||||||
recurring: recurring,
|
recurring: recurring,
|
||||||
params: params,
|
params: params,
|
||||||
timeoutKey: timeoutKey,
|
timeoutKey: timeoutKey,
|
||||||
|
|||||||
@@ -12,6 +12,17 @@ describe("DelayedFunctionScheduler", function() {
|
|||||||
expect(fn).toHaveBeenCalled();
|
expect(fn).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("schedules a string for later execution", function() {
|
||||||
|
var scheduler = new j$.DelayedFunctionScheduler(),
|
||||||
|
strfn = "window.horrible = true;";
|
||||||
|
|
||||||
|
scheduler.scheduleFunction(strfn, 0);
|
||||||
|
|
||||||
|
scheduler.tick(0);
|
||||||
|
|
||||||
|
expect(window.horrible).toEqual(true);
|
||||||
|
});
|
||||||
|
|
||||||
it("#tick defaults to 0", function() {
|
it("#tick defaults to 0", function() {
|
||||||
var scheduler = new j$.DelayedFunctionScheduler(),
|
var scheduler = new j$.DelayedFunctionScheduler(),
|
||||||
fn = jasmine.createSpy('fn');
|
fn = jasmine.createSpy('fn');
|
||||||
|
|||||||
@@ -12,12 +12,21 @@ getJasmineRequireObj().DelayedFunctionScheduler = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
self.scheduleFunction = function(funcToCall, millis, params, recurring, timeoutKey, runAtMillis) {
|
self.scheduleFunction = function(funcToCall, millis, params, recurring, timeoutKey, runAtMillis) {
|
||||||
|
var f;
|
||||||
|
if (typeof(funcToCall) === 'string') {
|
||||||
|
/* jshint evil: true */
|
||||||
|
f = function() { return eval(funcToCall); };
|
||||||
|
/* jshint evil: false */
|
||||||
|
} else {
|
||||||
|
f = funcToCall;
|
||||||
|
}
|
||||||
|
|
||||||
millis = millis || 0;
|
millis = millis || 0;
|
||||||
timeoutKey = timeoutKey || ++delayedFnCount;
|
timeoutKey = timeoutKey || ++delayedFnCount;
|
||||||
runAtMillis = runAtMillis || (currentTime + millis);
|
runAtMillis = runAtMillis || (currentTime + millis);
|
||||||
scheduledFunctions[timeoutKey] = {
|
scheduledFunctions[timeoutKey] = {
|
||||||
runAtMillis: runAtMillis,
|
runAtMillis: runAtMillis,
|
||||||
funcToCall: funcToCall,
|
funcToCall: f,
|
||||||
recurring: recurring,
|
recurring: recurring,
|
||||||
params: params,
|
params: params,
|
||||||
timeoutKey: timeoutKey,
|
timeoutKey: timeoutKey,
|
||||||
|
|||||||
Reference in New Issue
Block a user