OpenCoverage

qmljs.cpp

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/tools/qmljs/qmljs.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
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-
53static 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) {
!eDescription
TRUEnever evaluated
FALSEnever evaluated
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)
frame.line >= 0Description
TRUEnever evaluated
FALSEnever evaluated
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-
72int 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()) {
!args.isEmpty()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qv4assembler
FALSEnever evaluated
0-2
83 if (args.constFirst() == QLatin1String("--jit")) {
args.constFirs...tring("--jit")Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qv4assembler
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")) {
args.constFirs..."--interpret")Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qv4assembler
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")) {
args.constFirs...tring("--qml")Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qv4assembler
0-2
93 runAsQml = true;-
94 args.removeFirst();-
95 }
never executed: end of block
0
96-
97 if (args.constFirst() == QLatin1String("--cache")) {
args.constFirs...ing("--cache")Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qv4assembler
0-2
98 cache = true;-
99 args.removeFirst();-
100 }
never executed: end of block
0
101-
102 if (args.constFirst() == QLatin1String("--help")) {
args.constFirs...ring("--help")Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qv4assembler
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 block
Executed by:
  • tst_qv4assembler
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)) {
file.open(QFile::ReadOnly)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qv4assembler
FALSEnever evaluated
0-2
118 QScopedPointer<QV4::Script> script;-
119 if (cache && QFile::exists(fn + QLatin1Char('c'))) {
cacheDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qv4assembler
QFile::exists(...tin1Char('c'))Description
TRUEnever evaluated
FALSEnever evaluated
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)) {
unit->loadFrom...ied(), &error)Description
TRUEnever evaluated
FALSEnever evaluated
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) {
!scriptDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qv4assembler
FALSEnever evaluated
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 block
Executed by:
  • tst_qv4assembler
2
136 QV4::ScopedValue result(scope);-
137 if (!scope.engine->hasException) {
!scope.engine->hasExceptionDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qv4assembler
FALSEnever evaluated
0-2
138 const auto unit = script->compilationUnit;-
139 if (cache && unit && !(unit->data->flags & QV4::CompiledData::Unit::StaticData)) {
cacheDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qv4assembler
unitDescription
TRUEnever evaluated
FALSEnever evaluated
!(unit->data->...t::StaticData)Description
TRUEnever evaluated
FALSEnever evaluated
0-2
140 if (unit->data->sourceTimeStamp == 0) {
unit->data->so...TimeStamp == 0Description
TRUEnever evaluated
FALSEnever evaluated
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)) {
!unit->saveToD...), &saveError)Description
TRUEnever evaluated
FALSEnever evaluated
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 block
Executed by:
  • tst_qv4assembler
2
152 if (scope.engine->hasException) {
scope.engine->hasExceptionDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qv4assembler
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()) {
!result->isUndefined()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qv4assembler
FALSEnever evaluated
0-2
159 if (! qgetenv("SHOW_EXIT_VALUE").isEmpty())
! qgetenv("SHO...UE").isEmpty()Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qv4assembler
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 block
Executed by:
  • tst_qv4assembler
2
162 } else {
executed 2 times by 1 test: end of block
Executed by:
  • tst_qv4assembler
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:
  • tst_qv4assembler
2
169}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.0