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

drop remaining references to QScriptEngineDebugger
This commit is contained in:
Kalila 2021-06-03 18:01:40 -04:00 committed by GitHub
commit d8a0d13812
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 1 additions and 118 deletions

View file

@ -36,8 +36,6 @@
#include <QtScript/QScriptValue>
#include <QtScript/QScriptValueIterator>
#include <QtScriptTools/QScriptEngineDebugger>
#include <shared/LocalFileAccessGate.h>
#include <shared/QtHelpers.h>
#include <shared/AbstractLoggerInterface.h>
@ -327,96 +325,6 @@ void ScriptEngine::disconnectNonEssentialSignals() {
}
}
void ScriptEngine::runDebuggable() {
static QMenuBar* menuBar { nullptr };
static QMenu* scriptDebugMenu { nullptr };
static size_t scriptMenuCount { 0 };
if (!scriptDebugMenu) {
for (auto window : qApp->topLevelWidgets()) {
auto mainWindow = qobject_cast<QMainWindow*>(window);
if (mainWindow) {
menuBar = mainWindow->menuBar();
break;
}
}
if (menuBar) {
scriptDebugMenu = menuBar->addMenu("Script Debug");
}
}
init();
_isRunning = true;
_debuggable = true;
_debugger = new QScriptEngineDebugger(this);
_debugger->attachTo(this);
QMenu* parentMenu = scriptDebugMenu;
QMenu* scriptMenu { nullptr };
if (parentMenu) {
++scriptMenuCount;
scriptMenu = parentMenu->addMenu(_fileNameString);
scriptMenu->addMenu(_debugger->createStandardMenu(qApp->activeWindow()));
} else {
qWarning() << "Unable to add script debug menu";
}
QScriptValue result = evaluate(_scriptContents, _fileNameString);
_lastUpdate = usecTimestampNow();
QTimer* timer = new QTimer(this);
connect(this, &ScriptEngine::finished, [this, timer, parentMenu, scriptMenu] {
if (scriptMenu) {
parentMenu->removeAction(scriptMenu->menuAction());
--scriptMenuCount;
if (0 == scriptMenuCount) {
menuBar->removeAction(scriptDebugMenu->menuAction());
scriptDebugMenu = nullptr;
}
}
disconnect(timer);
});
connect(timer, &QTimer::timeout, [this, timer] {
if (_isFinished) {
if (!_isRunning) {
return;
}
stopAllTimers(); // make sure all our timers are stopped if the script is ending
emit scriptEnding();
emit finished(_fileNameString, qSharedPointerCast<ScriptEngine>(sharedFromThis()));
_isRunning = false;
emit runningStateChanged();
emit doneRunning();
timer->deleteLater();
return;
}
qint64 now = usecTimestampNow();
// we check for 'now' in the past in case people set their clock back
if (_lastUpdate < now) {
float deltaTime = (float)(now - _lastUpdate) / (float)USECS_PER_SECOND;
if (!(_isFinished || _isStopping)) {
emit update(deltaTime);
}
}
_lastUpdate = now;
// only clear exceptions if we are not in the middle of evaluating
if (!isEvaluating() && hasUncaughtException()) {
qCWarning(scriptengine) << __FUNCTION__ << "---------- UNCAUGHT EXCEPTION --------";
qCWarning(scriptengine) << "runDebuggable" << uncaughtException().toString();
logException(__FUNCTION__);
clearExceptions();
}
});
timer->start(10);
}
void ScriptEngine::runInThread() {
Q_ASSERT_X(!_isThreaded, "ScriptEngine::runInThread()", "runInThread should not be called more than once");
@ -588,12 +496,6 @@ void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) {
_scriptContents = scriptContents;
{
static const QString DEBUG_FLAG("#debug");
if (QRegularExpression(DEBUG_FLAG).match(scriptContents).hasMatch()) {
_debuggable = true;
}
}
emit scriptLoaded(url);
}, reload, maxRetries);
}

View file

@ -50,8 +50,6 @@
#include "SettingHandle.h"
#include "Profile.h"
class QScriptEngineDebugger;
static const QString NO_SCRIPT("");
static const int SCRIPT_FPS = 60;
@ -167,8 +165,6 @@ public:
/// services before calling this.
void runInThread();
void runDebuggable();
/// run the script in the callers thread, exit when stop() is called.
void run();
@ -667,8 +663,6 @@ public:
// this is used by code in ScriptEngines.cpp during the "reload all" operation
bool isStopping() const { return _isStopping; }
bool isDebuggable() const { return _debuggable; }
void disconnectNonEssentialSignals();
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -982,8 +976,6 @@ protected:
EntityScriptContentAvailableMap _contentAvailableQueue;
bool _isThreaded { false };
QScriptEngineDebugger* _debugger { nullptr };
bool _debuggable { false };
qint64 _lastUpdate;
QString _fileNameString;

View file

@ -26,7 +26,6 @@
#define __LOC__ __FILE__ "(" __STR1__(__LINE__) ") : Warning Msg: "
static const QString DESKTOP_LOCATION = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
static const bool HIFI_SCRIPT_DEBUGGABLES { true };
static const QString SETTINGS_KEY { "RunningScripts" };
static const QUrl DEFAULT_SCRIPTS_LOCATION { "file:///~//defaultScripts.js" };
@ -589,17 +588,7 @@ void ScriptEngines::launchScriptEngine(ScriptEnginePointer scriptEngine) {
// register our application services and set it off on its own thread
runScriptInitializers(scriptEngine);
// FIXME disabling 'shift key' debugging for now. If you start up the application with
// the shift key held down, it triggers a deadlock because of script interfaces running
// on the main thread
auto const wantDebug = scriptEngine->isDebuggable(); // || (qApp->queryKeyboardModifiers() & Qt::ShiftModifier);
if (HIFI_SCRIPT_DEBUGGABLES && wantDebug) {
scriptEngine->runDebuggable();
} else {
scriptEngine->runInThread();
}
scriptEngine->runInThread();
}
void ScriptEngines::onScriptFinished(const QString& rawScriptURL, ScriptEnginePointer engine) {