| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/tools/qmljs/qmljs.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||
| 6 | ** This file is part of the V4VM module of the Qt Toolkit. | - | ||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ | - | ||||||||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||||||||
| 16 | ** | - | ||||||||||||||||||
| 17 | ** GNU General Public License Usage | - | ||||||||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||||||||
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT | - | ||||||||||||||||||
| 21 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||
| 22 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||
| 24 | ** | - | ||||||||||||||||||
| 25 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 26 | ** | - | ||||||||||||||||||
| 27 | ****************************************************************************/ | - | ||||||||||||||||||
| 28 | - | |||||||||||||||||||
| 29 | #include "private/qv4object_p.h" | - | ||||||||||||||||||
| 30 | #include "private/qv4runtime_p.h" | - | ||||||||||||||||||
| 31 | #include "private/qv4functionobject_p.h" | - | ||||||||||||||||||
| 32 | #include "private/qv4errorobject_p.h" | - | ||||||||||||||||||
| 33 | #include "private/qv4globalobject_p.h" | - | ||||||||||||||||||
| 34 | #include "private/qv4codegen_p.h" | - | ||||||||||||||||||
| 35 | #include "private/qv4objectproto_p.h" | - | ||||||||||||||||||
| 36 | #include "private/qv4mm_p.h" | - | ||||||||||||||||||
| 37 | #include "private/qv4context_p.h" | - | ||||||||||||||||||
| 38 | #include "private/qv4script_p.h" | - | ||||||||||||||||||
| 39 | #include "private/qv4string_p.h" | - | ||||||||||||||||||
| 40 | #include "private/qqmlbuiltinfunctions_p.h" | - | ||||||||||||||||||
| 41 | - | |||||||||||||||||||
| 42 | #include <QtCore/QCoreApplication> | - | ||||||||||||||||||
| 43 | #include <QtCore/QFile> | - | ||||||||||||||||||
| 44 | #include <QtCore/QFileInfo> | - | ||||||||||||||||||
| 45 | #include <QtCore/QDateTime> | - | ||||||||||||||||||
| 46 | #include <private/qqmljsengine_p.h> | - | ||||||||||||||||||
| 47 | #include <private/qqmljslexer_p.h> | - | ||||||||||||||||||
| 48 | #include <private/qqmljsparser_p.h> | - | ||||||||||||||||||
| 49 | #include <private/qqmljsast_p.h> | - | ||||||||||||||||||
| 50 | - | |||||||||||||||||||
| 51 | #include <iostream> | - | ||||||||||||||||||
| 52 | - | |||||||||||||||||||
| 53 | static void showException(QV4::ExecutionContext *ctx, const QV4::Value &exception, const QV4::StackTrace &trace) | - | ||||||||||||||||||
| 54 | { | - | ||||||||||||||||||
| 55 | QV4::Scope scope(ctx); | - | ||||||||||||||||||
| 56 | QV4::ScopedValue ex(scope, exception); | - | ||||||||||||||||||
| 57 | QV4::ErrorObject *e = ex->as<QV4::ErrorObject>(); | - | ||||||||||||||||||
| 58 | if (!e) {
| 0 | ||||||||||||||||||
| 59 | std::cerr << "Uncaught exception: " << qPrintable(ex->toQString()) << std::endl; | - | ||||||||||||||||||
| 60 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 61 | std::cerr << "Uncaught exception: " << qPrintable(e->toQStringNoThrow()) << std::endl; | - | ||||||||||||||||||
| 62 | } never executed: end of block | 0 | ||||||||||||||||||
| 63 | - | |||||||||||||||||||
| 64 | for (const QV4::StackFrame &frame : trace) { | - | ||||||||||||||||||
| 65 | std::cerr << " at " << qPrintable(frame.function) << " (" << qPrintable(frame.source); | - | ||||||||||||||||||
| 66 | if (frame.line >= 0)
| 0 | ||||||||||||||||||
| 67 | std::cerr << ':' << frame.line; never executed: std::cerr << ':' << frame.line; | 0 | ||||||||||||||||||
| 68 | std::cerr << ')' << std::endl; | - | ||||||||||||||||||
| 69 | } never executed: end of block | 0 | ||||||||||||||||||
| 70 | } never executed: end of block | 0 | ||||||||||||||||||
| 71 | - | |||||||||||||||||||
| 72 | int main(int argc, char *argv[]) | - | ||||||||||||||||||
| 73 | { | - | ||||||||||||||||||
| 74 | QCoreApplication app(argc, argv); | - | ||||||||||||||||||
| 75 | QCoreApplication::setApplicationVersion(QLatin1String(QT_VERSION_STR)); | - | ||||||||||||||||||
| 76 | QStringList args = app.arguments(); | - | ||||||||||||||||||
| 77 | args.removeFirst(); | - | ||||||||||||||||||
| 78 | - | |||||||||||||||||||
| 79 | bool runAsQml = false; | - | ||||||||||||||||||
| 80 | bool cache = false; | - | ||||||||||||||||||
| 81 | - | |||||||||||||||||||
| 82 | if (!args.isEmpty()) {
| 0-2 | ||||||||||||||||||
| 83 | if (args.constFirst() == QLatin1String("--jit")) {
| 0-2 | ||||||||||||||||||
| 84 | qputenv("QV4_JIT_CALL_THRESHOLD", QByteArray("0")); | - | ||||||||||||||||||
| 85 | args.removeFirst(); | - | ||||||||||||||||||
| 86 | } never executed: end of block | 0 | ||||||||||||||||||
| 87 | if (args.constFirst() == QLatin1String("--interpret")) {
| 0-2 | ||||||||||||||||||
| 88 | qputenv("QV4_FORCE_INTERPRETER", QByteArray("1")); | - | ||||||||||||||||||
| 89 | args.removeFirst(); | - | ||||||||||||||||||
| 90 | } never executed: end of block | 0 | ||||||||||||||||||
| 91 | - | |||||||||||||||||||
| 92 | if (args.constFirst() == QLatin1String("--qml")) {
| 0-2 | ||||||||||||||||||
| 93 | runAsQml = true; | - | ||||||||||||||||||
| 94 | args.removeFirst(); | - | ||||||||||||||||||
| 95 | } never executed: end of block | 0 | ||||||||||||||||||
| 96 | - | |||||||||||||||||||
| 97 | if (args.constFirst() == QLatin1String("--cache")) {
| 0-2 | ||||||||||||||||||
| 98 | cache = true; | - | ||||||||||||||||||
| 99 | args.removeFirst(); | - | ||||||||||||||||||
| 100 | } never executed: end of block | 0 | ||||||||||||||||||
| 101 | - | |||||||||||||||||||
| 102 | if (args.constFirst() == QLatin1String("--help")) {
| 0-2 | ||||||||||||||||||
| 103 | std::cerr << "Usage: qmljs [|--jit|--interpret|--qml] file..." << std::endl; | - | ||||||||||||||||||
| 104 | return EXIT_SUCCESS; never executed: return 0 ; | 0 | ||||||||||||||||||
| 105 | } | - | ||||||||||||||||||
| 106 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 107 | - | |||||||||||||||||||
| 108 | QV4::ExecutionEngine vm; | - | ||||||||||||||||||
| 109 | - | |||||||||||||||||||
| 110 | QV4::Scope scope(&vm); | - | ||||||||||||||||||
| 111 | QV4::ScopedContext ctx(scope, vm.rootContext()); | - | ||||||||||||||||||
| 112 | - | |||||||||||||||||||
| 113 | QV4::GlobalExtensions::init(vm.globalObject, QJSEngine::ConsoleExtension | QJSEngine::GarbageCollectionExtension); | - | ||||||||||||||||||
| 114 | - | |||||||||||||||||||
| 115 | for (const QString &fn : qAsConst(args)) { | - | ||||||||||||||||||
| 116 | QFile file(fn); | - | ||||||||||||||||||
| 117 | if (file.open(QFile::ReadOnly)) {
| 0-2 | ||||||||||||||||||
| 118 | QScopedPointer<QV4::Script> script; | - | ||||||||||||||||||
| 119 | if (cache && QFile::exists(fn + QLatin1Char('c'))) {
| 0-2 | ||||||||||||||||||
| 120 | QQmlRefPointer<QV4::CompiledData::CompilationUnit> unit = QV4::Compiler::Codegen::createUnitForLoading(); | - | ||||||||||||||||||
| 121 | QString error; | - | ||||||||||||||||||
| 122 | if (unit->loadFromDisk(QUrl::fromLocalFile(fn), QFileInfo(fn).lastModified(), &error)) {
| 0 | ||||||||||||||||||
| 123 | script.reset(new QV4::Script(&vm, nullptr, unit)); | - | ||||||||||||||||||
| 124 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 125 | std::cout << "Error loading" << qPrintable(fn) << "from disk cache:" << qPrintable(error) << std::endl; | - | ||||||||||||||||||
| 126 | } never executed: end of block | 0 | ||||||||||||||||||
| 127 | } | - | ||||||||||||||||||
| 128 | if (!script) {
| 0-2 | ||||||||||||||||||
| 129 | const QString code = QString::fromUtf8(file.readAll()); | - | ||||||||||||||||||
| 130 | file.close(); | - | ||||||||||||||||||
| 131 | - | |||||||||||||||||||
| 132 | script.reset(new QV4::Script(ctx, QV4::Compiler::ContextType::Global, code, fn)); | - | ||||||||||||||||||
| 133 | script->parseAsBinding = runAsQml; | - | ||||||||||||||||||
| 134 | script->parse(); | - | ||||||||||||||||||
| 135 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 136 | QV4::ScopedValue result(scope); | - | ||||||||||||||||||
| 137 | if (!scope.engine->hasException) {
| 0-2 | ||||||||||||||||||
| 138 | const auto unit = script->compilationUnit; | - | ||||||||||||||||||
| 139 | if (cache && unit && !(unit->data->flags & QV4::CompiledData::Unit::StaticData)) {
| 0-2 | ||||||||||||||||||
| 140 | if (unit->data->sourceTimeStamp == 0) {
| 0 | ||||||||||||||||||
| 141 | const_cast<QV4::CompiledData::Unit*>(unit->data)->sourceTimeStamp = QFileInfo(fn).lastModified().toMSecsSinceEpoch(); | - | ||||||||||||||||||
| 142 | } never executed: end of block | 0 | ||||||||||||||||||
| 143 | QString saveError; | - | ||||||||||||||||||
| 144 | if (!unit->saveToDisk(QUrl::fromLocalFile(fn), &saveError)) {
| 0 | ||||||||||||||||||
| 145 | std::cout << "Error saving JS cache file: " << qPrintable(saveError) << std::endl; | - | ||||||||||||||||||
| 146 | } never executed: end of block | 0 | ||||||||||||||||||
| 147 | } never executed: end of block | 0 | ||||||||||||||||||
| 148 | // QElapsedTimer t; t.start(); | - | ||||||||||||||||||
| 149 | result = script->run(); | - | ||||||||||||||||||
| 150 | // std::cout << t.elapsed() << " ms. elapsed" << std::endl; | - | ||||||||||||||||||
| 151 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 152 | if (scope.engine->hasException) {
| 0-2 | ||||||||||||||||||
| 153 | QV4::StackTrace trace; | - | ||||||||||||||||||
| 154 | QV4::ScopedValue ex(scope, scope.engine->catchException(&trace)); | - | ||||||||||||||||||
| 155 | showException(ctx, ex, trace); | - | ||||||||||||||||||
| 156 | return EXIT_FAILURE; never executed: return 1 ; | 0 | ||||||||||||||||||
| 157 | } | - | ||||||||||||||||||
| 158 | if (!result->isUndefined()) {
| 0-2 | ||||||||||||||||||
| 159 | if (! qgetenv("SHOW_EXIT_VALUE").isEmpty())
| 0-2 | ||||||||||||||||||
| 160 | std::cout << "exit value: " << qPrintable(result->toQString()) << std::endl; never executed: std::cout << "exit value: " << QtPrivate::asString(result->toQString()).toLocal8Bit().constData() << std::endl; | 0 | ||||||||||||||||||
| 161 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 162 | } else { executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 163 | std::cerr << "Error: cannot open file " << fn.toUtf8().constData() << std::endl; | - | ||||||||||||||||||
| 164 | return EXIT_FAILURE; never executed: return 1 ; | 0 | ||||||||||||||||||
| 165 | } | - | ||||||||||||||||||
| 166 | } | - | ||||||||||||||||||
| 167 | - | |||||||||||||||||||
| 168 | return EXIT_SUCCESS; executed 2 times by 1 test: return 0 ;Executed by:
| 2 | ||||||||||||||||||
| 169 | } | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |