diff options
author | Joerg Bornemann <joerg.bornemann@theqtcompany.com> | 2016-05-09 17:46:44 +0200 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@qt.io> | 2016-05-10 10:15:06 +0000 |
commit | 54199588ce3c73dea6b6684ffc1b5a19fe343c22 (patch) | |
tree | c9d3df638989002a12b9d3a6bd02a3c4a8e65540 /src/lib/corelib/buildgraph/depscanner.cpp | |
parent | cb467cf08eb38a0d21d01d8afae571d78793d254 (diff) |
Do not use QScriptEngine::push/popScope in rule evaluation
This functionality is undocumented, has its flaws and is unavailable in
other JS engines. Use the following pattern instead to inject global
variables without polluting the global namespace:
QScriptValue g = engine.newObject();
g.setPrototype(engine.globalObject());
// set properties on g
engine.setGlobalObject(g);
engine.evaluate(...);
engine.setGlobalObject(g.prototype());
Change-Id: I5f92da8cccfa23c3722740c1852a71fd50e8eb8a
Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
Diffstat (limited to 'src/lib/corelib/buildgraph/depscanner.cpp')
-rw-r--r-- | src/lib/corelib/buildgraph/depscanner.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/lib/corelib/buildgraph/depscanner.cpp b/src/lib/corelib/buildgraph/depscanner.cpp index 311793f98..9673295e8 100644 --- a/src/lib/corelib/buildgraph/depscanner.cpp +++ b/src/lib/corelib/buildgraph/depscanner.cpp @@ -131,6 +131,7 @@ UserDependencyScanner::UserDependencyScanner(const ResolvedScannerConstPtr &scan { m_engine->setProcessEventsInterval(-1); // QBS-782 m_global = m_engine->newObject(); + m_global.setPrototype(m_engine->globalObject()); setupScriptEngineForFile(m_engine, m_scanner->scanScript->fileContext, m_global); } @@ -184,8 +185,7 @@ QStringList UserDependencyScanner::evaluate(Artifact *artifact, const ScriptFunc args.append(m_global.property(QString::fromLatin1("product"))); args.append(artifactConfig); - QScriptContext *ctx = m_engine->currentContext(); - ctx->pushScope(m_global); + m_engine->setGlobalObject(m_global); QScriptValue &function = script->scriptFunction; if (!function.isValid() || function.engine() != m_engine) { function = m_engine->evaluate(script->sourceCode); @@ -193,7 +193,7 @@ QStringList UserDependencyScanner::evaluate(Artifact *artifact, const ScriptFunc throw ErrorInfo(Tr::tr("Invalid scan script."), script->location); } QScriptValue result = function.call(QScriptValue(), args); - ctx->popScope(); + m_engine->setGlobalObject(m_global.prototype()); m_engine->clearRequestedProperties(); if (Q_UNLIKELY(m_engine->hasErrorOrException(result))) { QString msg = Tr::tr("evaluating scan script: ") + m_engine->lastErrorString(result); |