diff options
author | Joerg Bornemann <joerg.bornemann@qt.io> | 2017-09-01 10:14:17 +0200 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@qt.io> | 2017-09-27 13:27:53 +0000 |
commit | 1ce209edce33b36c1c9ca8aaff4c44aa8afca80f (patch) | |
tree | ea188881e2f7b0807b2177eb3105d76bf55f056f /src/lib/corelib | |
parent | 0a2e0c3880a7d76a65399854b15031c8e9c8dde8 (diff) | |
download | qbs-1ce209edce33b36c1c9ca8aaff4c44aa8afca80f.tar.gz |
Remove the need for calling Process.close()
Remove the need for explicitly calling Process.close() by making sure we
automatically close and destroy the object when we finish evaluating a
chunk of JavaScript.
[ChangeLog] Process objects are automatically closed after the current
script execution is finished.
Change-Id: I997b989c50d08e2da3141b1c9ae8f999a38c7eb9
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/lib/corelib')
-rw-r--r-- | src/lib/corelib/jsextensions/process.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/lib/corelib/jsextensions/process.cpp b/src/lib/corelib/jsextensions/process.cpp index cf9c8d645..fd8448132 100644 --- a/src/lib/corelib/jsextensions/process.cpp +++ b/src/lib/corelib/jsextensions/process.cpp @@ -58,7 +58,7 @@ namespace qbs { namespace Internal { -class Process : public QObject, public QScriptable +class Process : public QObject, public QScriptable, public ResourceAcquiringScriptObject { Q_OBJECT public: @@ -97,6 +97,9 @@ public: private: QString findExecutable(const QString &filePath) const; + // ResourceAcquiringScriptObject implementation + void releaseResources() override; + QProcess *m_qProcess; QProcessEnvironment m_environment; QString m_workingDirectory; @@ -125,12 +128,13 @@ QScriptValue Process::ctor(QScriptContext *context, QScriptEngine *engine) } ScriptEngine * const se = static_cast<ScriptEngine *>(engine); + se->addResourceAcquiringScriptObject(t); const DubiousContextList dubiousContexts ({ DubiousContext(EvalContext::PropertyEvaluation, DubiousContext::SuggestMoving) }); se->checkContext(QLatin1String("qbs.Process"), dubiousContexts); - QScriptValue obj = engine->newQObject(t, QScriptEngine::ScriptOwnership); + QScriptValue obj = engine->newQObject(t, QScriptEngine::QtOwnership); // Get environment QVariant v = engine->property("_qbs_procenv"); @@ -230,6 +234,8 @@ int Process::exec(const QString &program, const QStringList &arguments, bool thr void Process::close() { + if (!m_qProcess) + return; Q_ASSERT(thisObject().engine() == engine()); delete m_textStream; m_textStream = 0; @@ -294,6 +300,12 @@ QString Process::findExecutable(const QString &filePath) const return exeFinder.findExecutable(filePath, m_workingDirectory); } +void Process::releaseResources() +{ + close(); + deleteLater(); +} + void Process::write(const QString &str) { (*m_textStream) << str; |