summaryrefslogtreecommitdiffstats
path: root/src/script/api/qscriptengine.cpp
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-08-18 11:44:53 (GMT)
committerKent Hansen <khansen@trolltech.com>2009-08-18 11:46:15 (GMT)
commita2af6621a00cf0be03077132a271b2620a725bee (patch)
tree2489c6e6d7da146150ce53bb728ccff6adf73f6e /src/script/api/qscriptengine.cpp
parentf21797769e5dc53ed3f5380a362dd975721aac71 (diff)
downloadQt-a2af6621a00cf0be03077132a271b2620a725bee.zip
Qt-a2af6621a00cf0be03077132a271b2620a725bee.tar.gz
Qt-a2af6621a00cf0be03077132a271b2620a725bee.tar.bz2
adopt same ownership relationship of scriptengine agents as in old back-end
The engine owns its agents, and also knows when they are deleted.
Diffstat (limited to 'src/script/api/qscriptengine.cpp')
-rw-r--r--src/script/api/qscriptengine.cpp34
1 files changed, 27 insertions, 7 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp
index 63041db..02293ea 100644
--- a/src/script/api/qscriptengine.cpp
+++ b/src/script/api/qscriptengine.cpp
@@ -828,12 +828,14 @@ QScriptEnginePrivate::QScriptEnginePrivate() : idGenerator(1)
currentFrame = exec;
originalGlobalObjectProxy = 0;
- agent = 0;
+ activeAgent = 0;
processEventsInterval = -1;
}
QScriptEnginePrivate::~QScriptEnginePrivate()
{
+ while (!ownedAgents.isEmpty())
+ delete ownedAgents.takeFirst();
detachAllRegisteredScriptValues();
qDeleteAll(m_qobjectData);
qDeleteAll(m_typeInfos);
@@ -1189,6 +1191,15 @@ QScript::TimeoutCheckerProxy *QScriptEnginePrivate::timeoutChecker() const
return static_cast<QScript::TimeoutCheckerProxy*>(globalData->timeoutChecker);
}
+void QScriptEnginePrivate::agentDeleted(QScriptEngineAgent *agent)
+{
+ ownedAgents.removeOne(agent);
+ if (activeAgent == agent) {
+ QScriptEngineAgentPrivate::get(agent)->detach();
+ activeAgent = 0;
+ }
+}
+
#ifndef QT_NO_QOBJECT
JSC::JSValue QScriptEnginePrivate::newQObject(
@@ -3603,11 +3614,20 @@ QT_END_INCLUDE_NAMESPACE
void QScriptEngine::setAgent(QScriptEngineAgent *agent)
{
Q_D(QScriptEngine);
- if (d->agent)
- QScriptEngineAgentPrivate::get(d->agent)->detach();
- d->agent = agent;
- if (agent)
- QScriptEngineAgentPrivate::get(d->agent)->attach();
+ if (agent && (agent->engine() != this)) {
+ qWarning("QScriptEngine::setAgent(): "
+ "cannot set agent belonging to different engine");
+ return;
+ }
+ if (d->activeAgent)
+ QScriptEngineAgentPrivate::get(d->activeAgent)->detach();
+ d->activeAgent = agent;
+ if (agent) {
+ int index = d->ownedAgents.indexOf(agent);
+ if (index == -1)
+ d->ownedAgents.append(agent);
+ QScriptEngineAgentPrivate::get(agent)->attach();
+ }
}
/*!
@@ -3621,7 +3641,7 @@ void QScriptEngine::setAgent(QScriptEngineAgent *agent)
QScriptEngineAgent *QScriptEngine::agent() const
{
Q_D(const QScriptEngine);
- return d->agent;
+ return d->activeAgent;
}
/*!