aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-11-03 11:01:45 +0100
committerJ-P Nurmi <jpnurmi@qt.io>2016-11-03 11:01:45 +0100
commitda5083c11df4d9a6decd8d724098b6f108c4ab35 (patch)
treeee331004123ef2795025637c2905d9719f95f317 /tools
parent462904396454ed0ee931c2a8f2b02c8a6508965a (diff)
parentef502bd71a0d81f1428263a11c38cd7c893ac515 (diff)
Merge remote-tracking branch 'origin/5.8' into dev
Conflicts: tools/qmljs/qmljs.cpp Change-Id: Ifa9e74bdb780eaff22fbc9ba1c514d0078a3fb29
Diffstat (limited to 'tools')
-rw-r--r--tools/qmljs/qmljs.cpp45
1 files changed, 38 insertions, 7 deletions
diff --git a/tools/qmljs/qmljs.cpp b/tools/qmljs/qmljs.cpp
index 93276c1574..d09d2f7d0c 100644
--- a/tools/qmljs/qmljs.cpp
+++ b/tools/qmljs/qmljs.cpp
@@ -51,6 +51,8 @@ QT_REQUIRE_CONFIG(qml_interpreter);
#include <QtCore/QCoreApplication>
#include <QtCore/QFile>
+#include <QtCore/QFileInfo>
+#include <QtCore/QDateTime>
#include <private/qqmljsengine_p.h>
#include <private/qqmljslexer_p.h>
#include <private/qqmljsparser_p.h>
@@ -147,6 +149,7 @@ int main(int argc, char *argv[])
#endif
bool runAsQml = false;
+ bool cache = false;
if (!args.isEmpty()) {
if (args.constFirst() == QLatin1String("--jit")) {
@@ -166,6 +169,11 @@ int main(int argc, char *argv[])
args.removeFirst();
}
+ if (args.constFirst() == QLatin1String("--cache")) {
+ cache = true;
+ args.removeFirst();
+ }
+
if (args.constFirst() == QLatin1String("--help")) {
std::cerr << "Usage: qmljs [|--jit|--interpret|--qml] file..." << std::endl;
return EXIT_SUCCESS;
@@ -199,15 +207,38 @@ int main(int argc, char *argv[])
for (const QString &fn : qAsConst(args)) {
QFile file(fn);
if (file.open(QFile::ReadOnly)) {
- const QString code = QString::fromUtf8(file.readAll());
- file.close();
+ QScopedPointer<QV4::Script> script;
+ if (cache && QFile::exists(fn + QLatin1Char('c'))) {
+ QQmlRefPointer<QV4::CompiledData::CompilationUnit> unit = iSelFactory->createUnitForLoading();
+ QString error;
+ if (unit->loadFromDisk(QUrl::fromLocalFile(fn), iSelFactory, &error)) {
+ script.reset(new QV4::Script(&vm, nullptr, unit));
+ } else {
+ std::cout << "Error loading" << qPrintable(fn) << "from disk cache:" << qPrintable(error) << std::endl;
+ }
+ }
+ if (!script) {
+ const QString code = QString::fromUtf8(file.readAll());
+ file.close();
+ script.reset(new QV4::Script(ctx, code, fn));
+ script->parseAsBinding = runAsQml;
+ script->parse();
+ }
QV4::ScopedValue result(scope);
- QV4::Script script(ctx, code, fn);
- script.parseAsBinding = runAsQml;
- script.parse();
- if (!scope.engine->hasException)
- result = script.run();
+ if (!scope.engine->hasException) {
+ const auto unit = script->compilationUnit;
+ if (cache && unit && !(unit->data->flags & QV4::CompiledData::Unit::StaticData)) {
+ if (unit->data->sourceTimeStamp == 0) {
+ const_cast<QV4::CompiledData::Unit*>(unit->data)->sourceTimeStamp = QFileInfo(fn).lastModified().toMSecsSinceEpoch();
+ }
+ QString saveError;
+ if (!unit->saveToDisk(QUrl::fromLocalFile(fn), &saveError)) {
+ std::cout << "Error saving JS cache file: " << qPrintable(saveError) << std::endl;
+ }
+ }
+ result = script->run();
+ }
if (scope.engine->hasException) {
QV4::StackTrace trace;
QV4::ScopedValue ex(scope, scope.engine->catchException(&trace));