aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/v8/qv8contextwrapper.cpp
diff options
context:
space:
mode:
authorPhilip Lorenz <philip@bithub.de>2012-12-01 12:58:39 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-12-10 18:09:27 +0100
commitc18e04b2e61f174a4883f6884cf9a0712c5725e3 (patch)
tree1be41c4bd81b01519b0cf3d54fcbd17a10842fc7 /src/qml/qml/v8/qv8contextwrapper.cpp
parent22924ac4fe1962022ec12f40c66bf5cb988515b3 (diff)
Only free context if the owning QV8ContextResource gets destroyed
Since fdeee38b781376012c4f086276c3c376726c8839 QQmlXMLHttpRequest stores the calling context for later use. This leads to issues after the first request completes and the wrapping QV8ContextResource gets freed by garbage collection and therefore removes the associated QQmlDataContext which may still be required for later calls (e.g. if the calling context is part of a stateless library). This patch introduces an ownership flag for QV8ContextResource which indicates if the associated context should be cleared when the object is destroyed. Task-number: QTBUG-28351 Change-Id: I552ebb5c55b889eb33f3884283c8fdf037ac33be Reviewed-by: Alan Alpert <aalpert@rim.com>
Diffstat (limited to 'src/qml/qml/v8/qv8contextwrapper.cpp')
-rw-r--r--src/qml/qml/v8/qv8contextwrapper.cpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/qml/qml/v8/qv8contextwrapper.cpp b/src/qml/qml/v8/qv8contextwrapper.cpp
index 9f18afc5cb..bc64189cbd 100644
--- a/src/qml/qml/v8/qv8contextwrapper.cpp
+++ b/src/qml/qml/v8/qv8contextwrapper.cpp
@@ -55,7 +55,7 @@ class QV8ContextResource : public QV8ObjectResource
V8_RESOURCE_TYPE(ContextType);
public:
- QV8ContextResource(QV8Engine *engine, QQmlContextData *context, QObject *scopeObject);
+ QV8ContextResource(QV8Engine *engine, QQmlContextData *context, QObject *scopeObject, bool ownsContext = false);
~QV8ContextResource();
inline QQmlContextData *getContext() const;
@@ -64,7 +64,8 @@ public:
quint32 isSharedContext:1;
quint32 hasSubContexts:1;
quint32 readOnly:1;
- quint32 dummy:29;
+ quint32 ownsContext:1;
+ quint32 dummy:28;
// This is a pretty horrible hack, and an abuse of external strings. When we create a
// sub-context (a context created by a Qt.include() in an external javascript file),
@@ -86,15 +87,15 @@ private:
};
-QV8ContextResource::QV8ContextResource(QV8Engine *engine, QQmlContextData *context, QObject *scopeObject)
-: QV8ObjectResource(engine), isSharedContext(false), hasSubContexts(false), readOnly(true),
- context(context), scopeObject(scopeObject)
+QV8ContextResource::QV8ContextResource(QV8Engine *engine, QQmlContextData *context, QObject *scopeObject, bool ownsContext)
+: QV8ObjectResource(engine), isSharedContext(false), hasSubContexts(false), readOnly(true),
+ ownsContext(ownsContext), context(context), scopeObject(scopeObject)
{
}
QV8ContextResource::~QV8ContextResource()
{
- if (context && context->isJSContext)
+ if (context && ownsContext)
context->destroy();
}
@@ -186,7 +187,7 @@ v8::Local<v8::Object> QV8ContextWrapper::urlScope(const QUrl &url)
// XXX NewInstance() should be optimized
v8::Local<v8::Object> rv = m_urlConstructor->NewInstance();
- QV8ContextResource *r = new QV8ContextResource(m_engine, context, 0);
+ QV8ContextResource *r = new QV8ContextResource(m_engine, context, 0, true);
rv->SetExternalResource(r);
return rv;
}
@@ -226,6 +227,12 @@ QQmlContextData *QV8ContextWrapper::context(v8::Handle<v8::Value> value)
return r?r->getContext():0;
}
+void QV8ContextWrapper::takeContextOwnership(v8::Handle<v8::Object> qmlglobal)
+{
+ QV8ContextResource *r = v8_resource_cast<QV8ContextResource>(qmlglobal);
+ r->ownsContext = true;
+}
+
v8::Handle<v8::Value> QV8ContextWrapper::NullGetter(v8::Local<v8::String>,
const v8::AccessorInfo &)
{