aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChris Adams <christopher.adams@nokia.com>2011-09-23 11:58:39 +1000
committerQt by Nokia <qt-info@nokia.com>2011-10-04 01:25:05 +0200
commit4c01174b63e049eeb945081e1e6cc7b09514fc6b (patch)
treecc3a555a7bc7e19cab2b80a20b74e6c823813def /src
parent61e7c0b9383998525f5df39a3596eb0cf39a270d (diff)
Allow .pragma library scripts to import other scripts
Previously, a .pragma library script would have a new context which did not have an engine set. If the script then imported other scripts a crash would occur due to dereferencing the (null) engine ptr. This commit ensures that even if no parent context is used (eg, for shared scripts which don't import the parent context) the engine from the parent context is used as the engine in the new context. Finally, unit tests for the .pragma library import with imports cases were added to tst_qdeclarativeecmascript. Task-number: QTBUG-21620 Change-Id: I671ffc9eee98a69cce7c169ce5b9d5aae4d1ff0d Reviewed-on: http://codereview.qt-project.org/5421 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/declarative/qml/qdeclarativevme.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/declarative/qml/qdeclarativevme.cpp b/src/declarative/qml/qdeclarativevme.cpp
index bf8bd29c34..8cc8fa0247 100644
--- a/src/declarative/qml/qdeclarativevme.cpp
+++ b/src/declarative/qml/qdeclarativevme.cpp
@@ -1174,6 +1174,7 @@ v8::Persistent<v8::Object> QDeclarativeVME::run(QDeclarativeContextData *parentC
if (script->m_loaded)
return qPersistentNew<v8::Object>(script->m_value);
+ Q_ASSERT(parentCtxt && parentCtxt->engine);
QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(parentCtxt->engine);
QV8Engine *v8engine = ep->v8engine();
@@ -1208,8 +1209,11 @@ v8::Persistent<v8::Object> QDeclarativeVME::run(QDeclarativeContextData *parentC
ctxt->imports->addref();
}
- if (effectiveCtxt)
+ if (effectiveCtxt) {
ctxt->setParent(effectiveCtxt, true);
+ } else {
+ ctxt->engine = parentCtxt->engine; // Fix for QTBUG-21620
+ }
for (int ii = 0; ii < script->scripts.count(); ++ii) {
ctxt->importedScripts << run(ctxt, script->scripts.at(ii)->scriptData());