aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/corelib/buildgraph/rulesevaluationcontext.cpp
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@theqtcompany.com>2016-05-09 17:46:44 +0200
committerJoerg Bornemann <joerg.bornemann@qt.io>2016-05-10 10:15:06 +0000
commit54199588ce3c73dea6b6684ffc1b5a19fe343c22 (patch)
treec9d3df638989002a12b9d3a6bd02a3c4a8e65540 /src/lib/corelib/buildgraph/rulesevaluationcontext.cpp
parentcb467cf08eb38a0d21d01d8afae571d78793d254 (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/rulesevaluationcontext.cpp')
-rw-r--r--src/lib/corelib/buildgraph/rulesevaluationcontext.cpp7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/lib/corelib/buildgraph/rulesevaluationcontext.cpp b/src/lib/corelib/buildgraph/rulesevaluationcontext.cpp
index 1b7efb33c..47088eb17 100644
--- a/src/lib/corelib/buildgraph/rulesevaluationcontext.cpp
+++ b/src/lib/corelib/buildgraph/rulesevaluationcontext.cpp
@@ -49,6 +49,7 @@ RulesEvaluationContext::RulesEvaluationContext(const Logger &logger)
: m_engine(new ScriptEngine(logger)), m_observer(0), m_initScopeCalls(0)
{
m_prepareScriptScope = m_engine->newObject();
+ m_prepareScriptScope.setPrototype(m_engine->globalObject());
ProcessCommand::setupForJavaScript(m_prepareScriptScope);
JavaScriptCommand::setupForJavaScript(m_prepareScriptScope);
}
@@ -87,10 +88,9 @@ void RulesEvaluationContext::initScope()
return;
m_engine->clearImportsCache();
- m_engine->pushContext();
m_scope = m_engine->newObject();
m_scope.setPrototype(m_prepareScriptScope);
- m_engine->currentContext()->pushScope(m_scope);
+ m_engine->setGlobalObject(m_scope);
}
void RulesEvaluationContext::cleanupScope()
@@ -100,8 +100,7 @@ void RulesEvaluationContext::cleanupScope()
return;
m_scope = QScriptValue();
- m_engine->currentContext()->popScope();
- m_engine->popContext();
+ m_engine->setGlobalObject(m_prepareScriptScope.prototype());
}
RulesEvaluationContext::Scope::Scope(RulesEvaluationContext *evalContext)