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/processcommandexecutor.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/processcommandexecutor.cpp')
-rw-r--r-- | src/lib/corelib/buildgraph/processcommandexecutor.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/lib/corelib/buildgraph/processcommandexecutor.cpp b/src/lib/corelib/buildgraph/processcommandexecutor.cpp index 34d63c0ba..a08428aa0 100644 --- a/src/lib/corelib/buildgraph/processcommandexecutor.cpp +++ b/src/lib/corelib/buildgraph/processcommandexecutor.cpp @@ -167,17 +167,17 @@ QString ProcessCommandExecutor::filterProcessOutput(const QByteArray &_output, return output; QScriptValue scope = scriptEngine()->newObject(); + scope.setPrototype(scriptEngine()->globalObject()); for (QVariantMap::const_iterator it = command()->properties().constBegin(); it != command()->properties().constEnd(); ++it) { scope.setProperty(it.key(), scriptEngine()->toScriptValue(it.value())); } - ScriptContextScopePusher scopePusher(scriptEngine()->currentContext(), scope); - Q_UNUSED(scopePusher); - + scriptEngine()->setGlobalObject(scope); QScriptValue filterFunction = scriptEngine()->evaluate(QLatin1String("var f = ") + filterFunctionSource + QLatin1String("; f")); + scriptEngine()->setGlobalObject(scope.prototype()); if (!filterFunction.isFunction()) { logger().printWarning(ErrorInfo(Tr::tr("Error in filter function: %1.\n%2") .arg(filterFunctionSource, filterFunction.toString()))); |