diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index a15ad5ee..ac72688e 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -3492,10 +3492,9 @@ getJasmineRequireObj().CurrentRunableTracker = function() { return CurrentRunableTracker; }; -// Warning: don't add "use strict" to this file. Doing so potentially changes -// the behavior of user code that does things like setTimeout("var x = 1;") -// while the mock clock is installed. getJasmineRequireObj().DelayedFunctionScheduler = function(j$) { + 'use strict'; + function DelayedFunctionScheduler() { this.scheduledLookup_ = []; this.scheduledFunctions_ = {}; @@ -3518,20 +3517,10 @@ getJasmineRequireObj().DelayedFunctionScheduler = function(j$) { timeoutKey, runAtMillis ) { - let f; if (typeof funcToCall === 'string') { - // setTimeout("some code") and setInterval("some code") are legal, if - // not recommended. We don't do that ourselves, but user code might. - // This allows such code to work when the mock clock is installed. - j$.getEnv().deprecated( - "The eval form of setTimeout and setInterval is deprecated and will stop working in a future version of Jasmine's mock clock. Pass a function instead of a string." + throw new Error( + 'The mock clock does not support the eval form of setTimeout and setInterval. Pass a function instead of a string.' ); - f = function() { - // eslint-disable-next-line no-eval - return eval(funcToCall); - }; - } else { - f = funcToCall; } millis = millis || 0; @@ -3540,7 +3529,7 @@ getJasmineRequireObj().DelayedFunctionScheduler = function(j$) { const funcToSchedule = { runAtMillis: runAtMillis, - funcToCall: f, + funcToCall, recurring: recurring, params: params, timeoutKey: timeoutKey, diff --git a/spec/core/DelayedFunctionSchedulerSpec.js b/spec/core/DelayedFunctionSchedulerSpec.js index 9ff98c74..c7ea4a7c 100644 --- a/spec/core/DelayedFunctionSchedulerSpec.js +++ b/spec/core/DelayedFunctionSchedulerSpec.js @@ -1,4 +1,6 @@ describe('DelayedFunctionScheduler', function() { + 'use strict'; + it('schedules a function for later execution', function() { const scheduler = new jasmineUnderTest.DelayedFunctionScheduler(), fn = jasmine.createSpy('fn'); @@ -12,21 +14,14 @@ describe('DelayedFunctionScheduler', function() { expect(fn).toHaveBeenCalled(); }); - it('schedules a string for later execution', function() { - const scheduler = new jasmineUnderTest.DelayedFunctionScheduler(), - strfn = 'horrible = true;'; - spyOn(jasmineUnderTest.getEnv(), 'deprecated'); + it('throws if a string is passed', function() { + const scheduler = new jasmineUnderTest.DelayedFunctionScheduler(); - scheduler.scheduleFunction(strfn, 0); - expect(jasmineUnderTest.getEnv().deprecated).toHaveBeenCalledWith( - 'The eval form of setTimeout and setInterval is deprecated and will ' + - "stop working in a future version of Jasmine's mock clock. Pass a " + - 'function instead of a string.' + expect(function() { + scheduler.scheduleFunction('horrible = true;', 0); + }).toThrowError( + 'The mock clock does not support the eval form of setTimeout and setInterval. Pass a function instead of a string.' ); - - scheduler.tick(0); - - expect(horrible).toEqual(true); }); it('#tick defaults to 0', function() { diff --git a/src/core/DelayedFunctionScheduler.js b/src/core/DelayedFunctionScheduler.js index abe157aa..b59c88cf 100644 --- a/src/core/DelayedFunctionScheduler.js +++ b/src/core/DelayedFunctionScheduler.js @@ -1,7 +1,6 @@ -// Warning: don't add "use strict" to this file. Doing so potentially changes -// the behavior of user code that does things like setTimeout("var x = 1;") -// while the mock clock is installed. getJasmineRequireObj().DelayedFunctionScheduler = function(j$) { + 'use strict'; + function DelayedFunctionScheduler() { this.scheduledLookup_ = []; this.scheduledFunctions_ = {}; @@ -24,20 +23,10 @@ getJasmineRequireObj().DelayedFunctionScheduler = function(j$) { timeoutKey, runAtMillis ) { - let f; if (typeof funcToCall === 'string') { - // setTimeout("some code") and setInterval("some code") are legal, if - // not recommended. We don't do that ourselves, but user code might. - // This allows such code to work when the mock clock is installed. - j$.getEnv().deprecated( - "The eval form of setTimeout and setInterval is deprecated and will stop working in a future version of Jasmine's mock clock. Pass a function instead of a string." + throw new Error( + 'The mock clock does not support the eval form of setTimeout and setInterval. Pass a function instead of a string.' ); - f = function() { - // eslint-disable-next-line no-eval - return eval(funcToCall); - }; - } else { - f = funcToCall; } millis = millis || 0; @@ -46,7 +35,7 @@ getJasmineRequireObj().DelayedFunctionScheduler = function(j$) { const funcToSchedule = { runAtMillis: runAtMillis, - funcToCall: f, + funcToCall, recurring: recurring, params: params, timeoutKey: timeoutKey,