History

Fix two cases of negative timer intervals.

This fixes issue #2159:

Dale Glass committed 7 months ago

Commit e6b8fdf1 parent baf6fcb2 files · +15 −2Browse files

Showing the changes to libraries/script-engine/src/ScriptManager.cpp (1 of 2 files). Show all

Unified · Split

libraries/script-engine/src/ScriptManager.cpp+14−1
@@ -1281,7 +1281,20 @@ QTimer* ScriptManager::setupTimerWithInterval(const ScriptValue& function, int i · 1280 unmodified lines
12811281 CallbackData timerData = { function, currentEntityIdentifier, currentSandboxURL };
12821282 _timerFunctionMap.insert(newTimer, timerData);
12831283
1284− newTimer->start(intervalMS);
1284+ if (intervalMS < 0) {
1285+ int lineNumber = -1;
1286+ QString fileName = getFilename();
1287+ auto context = _engine->currentContext();
1288+ if (context) {
1289+ lineNumber = context->currentLineNumber();
1290+ fileName = context->currentFileName();
1291+ }
1292+
1293+ scriptWarningMessage("Script.setInterval() was passed negative value " + QString::number(intervalMS) + ". Ignored, timer not started. Parent script:" + getFilename(), fileName, lineNumber);
1294+ } else {
1295+ newTimer->start(intervalMS);
1296+ }
1297+
12851298 return newTimer;
12861299 }
12871300