| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/tools/qmljs/qmljs.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | - | |||||||||||||||||||
| 4 | - | |||||||||||||||||||
| 5 | static void showException(QV4::ExecutionContext *ctx, const QV4::Value &exception, const QV4::StackTrace &trace) | - | ||||||||||||||||||
| 6 | { | - | ||||||||||||||||||
| 7 | QV4::Scope scope(ctx); | - | ||||||||||||||||||
| 8 | QV4::ScopedValue ex(scope, exception); | - | ||||||||||||||||||
| 9 | QV4::ErrorObject *e = ex->as<QV4::ErrorObject>(); | - | ||||||||||||||||||
| 10 | if (!e
| 0 | ||||||||||||||||||
| 11 | std::cerr << "Uncaught exception: " << QtPrivate::asString(ex->toQString()).toLocal8Bit().constData() << std::endl; | - | ||||||||||||||||||
| 12 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 13 | std::cerr << "Uncaught exception: " << QtPrivate::asString(e->toQStringNoThrow()).toLocal8Bit().constData() << std::endl; | - | ||||||||||||||||||
| 14 | } never executed: end of block | 0 | ||||||||||||||||||
| 15 | - | |||||||||||||||||||
| 16 | for (const QV4::StackFrame &frame : trace) { | - | ||||||||||||||||||
| 17 | std::cerr << " at " << QtPrivate::asString(frame.function).toLocal8Bit().constData() << " (" << QtPrivate::asString(frame.source).toLocal8Bit().constData(); | - | ||||||||||||||||||
| 18 | if (frame.line >= 0
| 0 | ||||||||||||||||||
| 19 | std::cerr << ':' << frame.line; never executed: std::cerr << ':' << frame.line; | 0 | ||||||||||||||||||
| 20 | std::cerr << ')' << std::endl; | - | ||||||||||||||||||
| 21 | } never executed: end of block | 0 | ||||||||||||||||||
| 22 | } never executed: end of block | 0 | ||||||||||||||||||
| 23 | - | |||||||||||||||||||
| 24 | int main(int argc, char *argv[]) | - | ||||||||||||||||||
| 25 | { | - | ||||||||||||||||||
| 26 | QCoreApplication app(argc, argv); | - | ||||||||||||||||||
| 27 | QCoreApplication::setApplicationVersion(QLatin1String("5.12.0")); | - | ||||||||||||||||||
| 28 | QStringList args = app.arguments(); | - | ||||||||||||||||||
| 29 | args.removeFirst(); | - | ||||||||||||||||||
| 30 | - | |||||||||||||||||||
| 31 | bool runAsQml = false; | - | ||||||||||||||||||
| 32 | bool cache = false; | - | ||||||||||||||||||
| 33 | - | |||||||||||||||||||
| 34 | if (!args.isEmpty()
| 0-2 | ||||||||||||||||||
| 35 | if (args.constFirst() == QLatin1String("--jit")
| 0-2 | ||||||||||||||||||
| 36 | qputenv("QV4_JIT_CALL_THRESHOLD", QByteArray("0")); | - | ||||||||||||||||||
| 37 | args.removeFirst(); | - | ||||||||||||||||||
| 38 | } never executed: end of block | 0 | ||||||||||||||||||
| 39 | if (args.constFirst() == QLatin1String("--interpret")
| 0-2 | ||||||||||||||||||
| 40 | qputenv("QV4_FORCE_INTERPRETER", QByteArray("1")); | - | ||||||||||||||||||
| 41 | args.removeFirst(); | - | ||||||||||||||||||
| 42 | } never executed: end of block | 0 | ||||||||||||||||||
| 43 | - | |||||||||||||||||||
| 44 | if (args.constFirst() == QLatin1String("--qml")
| 0-2 | ||||||||||||||||||
| 45 | runAsQml = true; | - | ||||||||||||||||||
| 46 | args.removeFirst(); | - | ||||||||||||||||||
| 47 | } never executed: end of block | 0 | ||||||||||||||||||
| 48 | - | |||||||||||||||||||
| 49 | if (args.constFirst() == QLatin1String("--cache")
| 0-2 | ||||||||||||||||||
| 50 | cache = true; | - | ||||||||||||||||||
| 51 | args.removeFirst(); | - | ||||||||||||||||||
| 52 | } never executed: end of block | 0 | ||||||||||||||||||
| 53 | - | |||||||||||||||||||
| 54 | if (args.constFirst() == QLatin1String("--help")
| 0-2 | ||||||||||||||||||
| 55 | std::cerr << "Usage: qmljs [|--jit|--interpret|--qml] file..." << std::endl; | - | ||||||||||||||||||
| 56 | return never executed: return 0 ;never executed: return 0 ; | 0 | ||||||||||||||||||
| 57 | 0 never executed: return 0 ; | 0 | ||||||||||||||||||
| 58 | ; never executed: return 0 ; | 0 | ||||||||||||||||||
| 59 | } | - | ||||||||||||||||||
| 60 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 61 | - | |||||||||||||||||||
| 62 | QV4::ExecutionEngine vm; | - | ||||||||||||||||||
| 63 | - | |||||||||||||||||||
| 64 | QV4::Scope scope(&vm); | - | ||||||||||||||||||
| 65 | QV4::ScopedContext ctx(scope, vm.rootContext()); | - | ||||||||||||||||||
| 66 | - | |||||||||||||||||||
| 67 | QV4::GlobalExtensions::init(vm.globalObject, QJSEngine::ConsoleExtension | QJSEngine::GarbageCollectionExtension); | - | ||||||||||||||||||
| 68 | - | |||||||||||||||||||
| 69 | for (const QString &fn : qAsConst(args)) { | - | ||||||||||||||||||
| 70 | QFile file(fn); | - | ||||||||||||||||||
| 71 | if (file.open(QFile::ReadOnly)
| 0-2 | ||||||||||||||||||
| 72 | QScopedPointer<QV4::Script> script; | - | ||||||||||||||||||
| 73 | if (cache
| 0-2 | ||||||||||||||||||
| 74 | QQmlRefPointer<QV4::CompiledData::CompilationUnit> unit = QV4::Compiler::Codegen::createUnitForLoading(); | - | ||||||||||||||||||
| 75 | QString error; | - | ||||||||||||||||||
| 76 | if (unit->loadFromDisk(QUrl::fromLocalFile(fn), QFileInfo(fn).lastModified(), &error)
| 0 | ||||||||||||||||||
| 77 | script.reset(new QV4::Script(&vm, nullptr, unit)); | - | ||||||||||||||||||
| 78 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 79 | std::cout << "Error loading" << QtPrivate::asString(fn).toLocal8Bit().constData() << "from disk cache:" << QtPrivate::asString(error).toLocal8Bit().constData() << std::endl; | - | ||||||||||||||||||
| 80 | } never executed: end of block | 0 | ||||||||||||||||||
| 81 | } | - | ||||||||||||||||||
| 82 | if (!script
| 0-2 | ||||||||||||||||||
| 83 | const QString code = QString::fromUtf8(file.readAll()); | - | ||||||||||||||||||
| 84 | file.close(); | - | ||||||||||||||||||
| 85 | - | |||||||||||||||||||
| 86 | script.reset(new QV4::Script(ctx, QV4::Compiler::ContextType::Global, code, fn)); | - | ||||||||||||||||||
| 87 | script->parseAsBinding = runAsQml; | - | ||||||||||||||||||
| 88 | script->parse(); | - | ||||||||||||||||||
| 89 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 90 | QV4::ScopedValue result(scope); | - | ||||||||||||||||||
| 91 | if (!scope.engine->hasException
| 0-2 | ||||||||||||||||||
| 92 | const auto unit = script->compilationUnit; | - | ||||||||||||||||||
| 93 | if (cache
| 0-2 | ||||||||||||||||||
| 94 | if (unit->data->sourceTimeStamp == 0
| 0 | ||||||||||||||||||
| 95 | const_cast<QV4::CompiledData::Unit*>(unit->data)->sourceTimeStamp = QFileInfo(fn).lastModified().toMSecsSinceEpoch(); | - | ||||||||||||||||||
| 96 | } never executed: end of block | 0 | ||||||||||||||||||
| 97 | QString saveError; | - | ||||||||||||||||||
| 98 | if (!unit->saveToDisk(QUrl::fromLocalFile(fn), &saveError)
| 0 | ||||||||||||||||||
| 99 | std::cout << "Error saving JS cache file: " << QtPrivate::asString(saveError).toLocal8Bit().constData() << std::endl; | - | ||||||||||||||||||
| 100 | } never executed: end of block | 0 | ||||||||||||||||||
| 101 | } never executed: end of block | 0 | ||||||||||||||||||
| 102 | - | |||||||||||||||||||
| 103 | result = script->run(); | - | ||||||||||||||||||
| 104 | - | |||||||||||||||||||
| 105 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 106 | if (scope.engine->hasException
| 0-2 | ||||||||||||||||||
| 107 | QV4::StackTrace trace; | - | ||||||||||||||||||
| 108 | QV4::ScopedValue ex(scope, scope.engine->catchException(&trace)); | - | ||||||||||||||||||
| 109 | showException(ctx, ex, trace); | - | ||||||||||||||||||
| 110 | return never executed: return 1 ;never executed: return 1 ; | 0 | ||||||||||||||||||
| 111 | 1 never executed: return 1 ; | 0 | ||||||||||||||||||
| 112 | ; never executed: return 1 ; | 0 | ||||||||||||||||||
| 113 | } | - | ||||||||||||||||||
| 114 | if (!result->isUndefined()
| 0-2 | ||||||||||||||||||
| 115 | if (! qgetenv("SHOW_EXIT_VALUE").isEmpty()
| 0-2 | ||||||||||||||||||
| 116 | std::cout << "exit value: " << QtPrivate::asString(result->toQString()).toLocal8Bit().constData() << std::endl; never executed: std::cout << "exit value: " << QtPrivate::asString(result->toQString()).toLocal8Bit().constData() << std::endl; | 0 | ||||||||||||||||||
| 117 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 118 | } executed 2 times by 1 test: else {end of blockExecuted by:
| 2 | ||||||||||||||||||
| 119 | std::cerr << "Error: cannot open file " << fn.toUtf8().constData() << std::endl; | - | ||||||||||||||||||
| 120 | return never executed: return 1 ;never executed: return 1 ; | 0 | ||||||||||||||||||
| 121 | 1 never executed: return 1 ; | 0 | ||||||||||||||||||
| 122 | ; never executed: return 1 ; | 0 | ||||||||||||||||||
| 123 | } | - | ||||||||||||||||||
| 124 | } | - | ||||||||||||||||||
| 125 | - | |||||||||||||||||||
| 126 | return executed 2 times by 1 test: return 0 ;Executed by:
executed 2 times by 1 test: return 0 ;Executed by:
| 2 | ||||||||||||||||||
| 127 | 0 executed 2 times by 1 test: return 0 ;Executed by:
| 2 | ||||||||||||||||||
| 128 | ; executed 2 times by 1 test: return 0 ;Executed by:
| 2 | ||||||||||||||||||
| 129 | } | - | ||||||||||||||||||
| Switch to Source code | Preprocessed file |