From 58bee05c3634f82a29fa30fa8bc5c6d4b6b66d3b Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Thu, 17 Aug 2023 12:30:25 -0700 Subject: [PATCH] Documented usage of eval in DelayedFunctionScheduler --- lib/jasmine-core/jasmine.js | 6 ++++++ src/core/DelayedFunctionScheduler.js | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 6939bd8f..67e5424f 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -3224,6 +3224,9 @@ getJasmineRequireObj().CompleteOnFirstErrorSkipPolicy = function(j$) { return CompleteOnFirstErrorSkipPolicy; }; +// 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$) { function DelayedFunctionScheduler() { this.scheduledLookup_ = []; @@ -3249,6 +3252,9 @@ getJasmineRequireObj().DelayedFunctionScheduler = function(j$) { ) { 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. f = function() { // eslint-disable-next-line no-eval return eval(funcToCall); diff --git a/src/core/DelayedFunctionScheduler.js b/src/core/DelayedFunctionScheduler.js index ef2c2f4f..9ea6c5f3 100644 --- a/src/core/DelayedFunctionScheduler.js +++ b/src/core/DelayedFunctionScheduler.js @@ -1,3 +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$) { function DelayedFunctionScheduler() { this.scheduledLookup_ = []; @@ -23,6 +26,9 @@ getJasmineRequireObj().DelayedFunctionScheduler = function(j$) { ) { 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. f = function() { // eslint-disable-next-line no-eval return eval(funcToCall);