History

Throw to stop non-evaluating scripts

Zach Pomerantz committed 10 years ago

Commit 11078821 parent 7e824941 file · +17 −9Browse files

Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 1 file). Show all

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+17−9
@@ -304,17 +304,25 @@ void ScriptEngine::wait() { · 303 unmodified lines
304304 QCoreApplication::processEvents();
305305
306306 // If the final evaluation takes too long, then tell the script engine to stop evaluating
307− static const auto MAX_SCRIPT_QUITTING_TIME = 0.5 * MAX_SCRIPT_EVALUATION_TIME;
308307 auto elapsedUsecs = usecTimestampNow() - startedWaiting;
309308 if (elapsedUsecs > MAX_SCRIPT_EVALUATION_TIME) {
310− qCDebug(scriptengine).nospace() <<
311− "Script Engine has been running too long, aborting:" << getFilename();
312− abortEvaluation(); // break out of current evaluation
313−
314− // Wait for the scripting thread to stop running
315− if (!workerThread->wait(MAX_SCRIPT_QUITTING_TIME)) {
316− qCWarning(scriptengine).nospace() <<
317− "Script Engine has been aborting too long, terminating:" << getFilename();
309+ workerThread->quit();
310+
311+ if (isEvaluating()) {
312+ qCWarning(scriptengine) << "Script Engine has been running too long, aborting:" << getFilename();
313+ abortEvaluation();
314+ } else {
315+ qCWarning(scriptengine) << "Script Engine has been running too long, throwing:" << getFilename();
316+ auto context = currentContext();
317+ if (context) {
318+ context->throwError("Timed out during shutdown");
319+ }
320+ }
321+
322+ // Wait for the scripting thread to stop running, as
323+ // flooding it with aborts/exceptions will persist it longer
324+ static const auto MAX_SCRIPT_QUITTING_TIME = 0.5 * MSECS_PER_SECOND;
325+ if (workerThread->wait(MAX_SCRIPT_QUITTING_TIME)) {
318326 workerThread->terminate();
319327 }
320328 }