[Finishes #40853563] Allowed the DelayedFunctionScheduler to support strings that are eval'd

This commit is contained in:
Greg Cobb and JR Boyens
2013-07-18 13:57:51 -07:00
parent f637c1f833
commit 3e2d9baec2
3 changed files with 31 additions and 2 deletions

View File

@@ -866,12 +866,21 @@ getJasmineRequireObj().DelayedFunctionScheduler = function() {
};
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;
timeoutKey = timeoutKey || ++delayedFnCount;
runAtMillis = runAtMillis || (currentTime + millis);
scheduledFunctions[timeoutKey] = {
runAtMillis: runAtMillis,
funcToCall: funcToCall,
funcToCall: f,
recurring: recurring,
params: params,
timeoutKey: timeoutKey,

View File

@@ -12,6 +12,17 @@ describe("DelayedFunctionScheduler", function() {
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() {
var scheduler = new j$.DelayedFunctionScheduler(),
fn = jasmine.createSpy('fn');

View File

@@ -12,12 +12,21 @@ getJasmineRequireObj().DelayedFunctionScheduler = function() {
};
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;
timeoutKey = timeoutKey || ++delayedFnCount;
runAtMillis = runAtMillis || (currentTime + millis);
scheduledFunctions[timeoutKey] = {
runAtMillis: runAtMillis,
funcToCall: funcToCall,
funcToCall: f,
recurring: recurring,
params: params,
timeoutKey: timeoutKey,