From 2121de6d8762ec2fc90a07e207824090e8447291 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 4 Aug 2014 15:27:24 +0200 Subject: Fix Qt.include with cached compilation units and resources Similar to the worker scripts we also need to do a lookup for cached scripts here. Added also a test to ensure that Qt.include works correctly from Qt resources. Change-Id: Idb67af3da4b0cc91edbd3d2746d074fd68ed8bf0 Reviewed-by: Lars Knoll --- src/qml/jsruntime/qv4include.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/qml/jsruntime/qv4include.cpp') diff --git a/src/qml/jsruntime/qv4include.cpp b/src/qml/jsruntime/qv4include.cpp index d5bae0e35e..2661ecc346 100644 --- a/src/qml/jsruntime/qv4include.cpp +++ b/src/qml/jsruntime/qv4include.cpp @@ -210,20 +210,28 @@ QV4::ReturnedValue QV4Include::method_include(QV4::CallContext *ctx) result = i->result(); } else { + QScopedPointer script; - QFile f(localFile); + if (const QQmlPrivate::CachedQmlUnit *cachedUnit = QQmlMetaType::findCachedCompilationUnit(url)) { + QV4::CompiledData::CompilationUnit *jsUnit = cachedUnit->createCompilationUnit(); + script.reset(new QV4::Script(v4, qmlcontextobject, jsUnit)); + } else { + QFile f(localFile); - if (f.open(QIODevice::ReadOnly)) { - QByteArray data = f.readAll(); - QString code = QString::fromUtf8(data); - QmlIR::Document::removeScriptPragmas(code); + if (f.open(QIODevice::ReadOnly)) { + QByteArray data = f.readAll(); + QString code = QString::fromUtf8(data); + QmlIR::Document::removeScriptPragmas(code); - QV4::Script script(v4, qmlcontextobject, code, url.toString()); + script.reset(new QV4::Script(v4, qmlcontextobject, code, url.toString())); + } + } + if (!script.isNull()) { QV4::ExecutionContext *ctx = v4->currentContext(); - script.parse(); + script->parse(); if (!v4->hasException) - script.run(); + script->run(); if (v4->hasException) { QV4::ScopedValue ex(scope, ctx->catchException()); result = resultValue(v4, Exception); -- cgit v1.2.3