History

Merge pull request #1206 from odysseus654/pr/drop-script-debugging

drop remaining references to QScriptEngineDebugger

Kalila committed 5 years ago

Commit d8a0d132 parents a408294 04f8ccd3 files · +1 −118Browse files

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

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+0−98
@@ -36,8 +36,6 @@ · 35 unmodified lines
36#include <QtScript/QScriptValue>36#include <QtScript/QScriptValue>
37#include <QtScript/QScriptValueIterator>37#include <QtScript/QScriptValueIterator>
38 38
39#include <QtScriptTools/QScriptEngineDebugger>
40
41#include <shared/LocalFileAccessGate.h>39#include <shared/LocalFileAccessGate.h>
42#include <shared/QtHelpers.h>40#include <shared/QtHelpers.h>
43#include <shared/AbstractLoggerInterface.h>41#include <shared/AbstractLoggerInterface.h>
@@ -327,96 +325,6 @@ void ScriptEngine::disconnectNonEssentialSignals() { · 283 unmodified lines
327 }325 }
328}326}
329 327
330void ScriptEngine::runDebuggable() {
331 static QMenuBar* menuBar { nullptr };
332 static QMenu* scriptDebugMenu { nullptr };
333 static size_t scriptMenuCount { 0 };
334 if (!scriptDebugMenu) {
335 for (auto window : qApp->topLevelWidgets()) {
336 auto mainWindow = qobject_cast<QMainWindow*>(window);
337 if (mainWindow) {
338 menuBar = mainWindow->menuBar();
339 break;
340 }
341 }
342 if (menuBar) {
343 scriptDebugMenu = menuBar->addMenu("Script Debug");
344 }
345 }
346
347 init();
348 _isRunning = true;
349 _debuggable = true;
350 _debugger = new QScriptEngineDebugger(this);
351 _debugger->attachTo(this);
352
353 QMenu* parentMenu = scriptDebugMenu;
354 QMenu* scriptMenu { nullptr };
355 if (parentMenu) {
356 ++scriptMenuCount;
357 scriptMenu = parentMenu->addMenu(_fileNameString);
358 scriptMenu->addMenu(_debugger->createStandardMenu(qApp->activeWindow()));
359 } else {
360 qWarning() << "Unable to add script debug menu";
361 }
362
363 QScriptValue result = evaluate(_scriptContents, _fileNameString);
364
365 _lastUpdate = usecTimestampNow();
366 QTimer* timer = new QTimer(this);
367 connect(this, &ScriptEngine::finished, [this, timer, parentMenu, scriptMenu] {
368 if (scriptMenu) {
369 parentMenu->removeAction(scriptMenu->menuAction());
370 --scriptMenuCount;
371 if (0 == scriptMenuCount) {
372 menuBar->removeAction(scriptDebugMenu->menuAction());
373 scriptDebugMenu = nullptr;
374 }
375 }
376 disconnect(timer);
377 });
378
379 connect(timer, &QTimer::timeout, [this, timer] {
380 if (_isFinished) {
381 if (!_isRunning) {
382 return;
383 }
384 stopAllTimers(); // make sure all our timers are stopped if the script is ending
385
386 emit scriptEnding();
387 emit finished(_fileNameString, qSharedPointerCast<ScriptEngine>(sharedFromThis()));
388 _isRunning = false;
389
390 emit runningStateChanged();
391 emit doneRunning();
392
393 timer->deleteLater();
394 return;
395 }
396
397 qint64 now = usecTimestampNow();
398 // we check for 'now' in the past in case people set their clock back
399 if (_lastUpdate < now) {
400 float deltaTime = (float)(now - _lastUpdate) / (float)USECS_PER_SECOND;
401 if (!(_isFinished || _isStopping)) {
402 emit update(deltaTime);
403 }
404 }
405 _lastUpdate = now;
406
407 // only clear exceptions if we are not in the middle of evaluating
408 if (!isEvaluating() && hasUncaughtException()) {
409 qCWarning(scriptengine) << __FUNCTION__ << "---------- UNCAUGHT EXCEPTION --------";
410 qCWarning(scriptengine) << "runDebuggable" << uncaughtException().toString();
411 logException(__FUNCTION__);
412 clearExceptions();
413 }
414 });
415
416 timer->start(10);
417}
418
419
420void ScriptEngine::runInThread() {328void ScriptEngine::runInThread() {
421 Q_ASSERT_X(!_isThreaded, "ScriptEngine::runInThread()", "runInThread should not be called more than once");329 Q_ASSERT_X(!_isThreaded, "ScriptEngine::runInThread()", "runInThread should not be called more than once");
422 330
@@ -588,12 +496,6 @@ void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) { · 165 unmodified lines
588 496
589 _scriptContents = scriptContents;497 _scriptContents = scriptContents;
590 498
591 {
592 static const QString DEBUG_FLAG("#debug");
593 if (QRegularExpression(DEBUG_FLAG).match(scriptContents).hasMatch()) {
594 _debuggable = true;
595 }
596 }
597 emit scriptLoaded(url);499 emit scriptLoaded(url);
598 }, reload, maxRetries);500 }, reload, maxRetries);
599}501}