| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/jsruntime/qv4script.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | - | |||||||||||||
| 6 | - | |||||||||||||
| 7 | - | |||||||||||||
| 8 | using namespace QV4; | - | ||||||||||||
| 9 | - | |||||||||||||
| 10 | Script::Script(ExecutionEngine *v4, QmlContext *qml, const QQmlRefPointer<CompiledData::CompilationUnit> &compilationUnit) | - | ||||||||||||
| 11 | : line(1), column(0), context(v4->rootContext()), strictMode(false), inheritContext(true), parsed(false) | - | ||||||||||||
| 12 | , compilationUnit(compilationUnit), vmFunction(nullptr), parseAsBinding(true) | - | ||||||||||||
| 13 | { | - | ||||||||||||
| 14 | if (qml
| 2-250 | ||||||||||||
| 15 | qmlContext.set(v4, *qml); executed 2 times by 1 test: qmlContext.set(v4, *qml);Executed by:
| 2 | ||||||||||||
| 16 | - | |||||||||||||
| 17 | parsed = true; | - | ||||||||||||
| 18 | - | |||||||||||||
| 19 | vmFunction = compilationUnit
| 0-252 | ||||||||||||
| 20 | } executed 252 times by 13 tests: end of blockExecuted by:
| 252 | ||||||||||||
| 21 | - | |||||||||||||
| 22 | Script::~Script() | - | ||||||||||||
| 23 | { | - | ||||||||||||
| 24 | } | - | ||||||||||||
| 25 | - | |||||||||||||
| 26 | void Script::parse() | - | ||||||||||||
| 27 | { | - | ||||||||||||
| 28 | if (parsed
| 22-2818282 | ||||||||||||
| 29 | return; executed 22 times by 3 tests: return;Executed by:
| 22 | ||||||||||||
| 30 | - | |||||||||||||
| 31 | using namespace QV4::Compiler; | - | ||||||||||||
| 32 | - | |||||||||||||
| 33 | parsed = true; | - | ||||||||||||
| 34 | - | |||||||||||||
| 35 | ExecutionEngine *v4 = context->engine(); | - | ||||||||||||
| 36 | Scope valueScope(v4); | - | ||||||||||||
| 37 | - | |||||||||||||
| 38 | Module module(v4->debugger() != nullptr); | - | ||||||||||||
| 39 | - | |||||||||||||
| 40 | if (sourceCode.startsWith(QLatin1String("function("))
| 0-2817831 | ||||||||||||
| 41 | static const int snippetLength = 70; | - | ||||||||||||
| 42 | QMessageLogger(__FILE__, 95, __PRETTY_FUNCTION__).warning() << "Warning: Using function expressions as statements in scripts is not compliant with the ECMAScript specification:\n" | - | ||||||||||||
| 43 | << (sourceCode.leftRef(snippetLength) + QLatin1String("...")) | - | ||||||||||||
| 44 | << "\nThis will throw a syntax error in Qt 5.12. If you want a function expression, surround it by parentheses."; | - | ||||||||||||
| 45 | } never executed: end of block | 0 | ||||||||||||
| 46 | - | |||||||||||||
| 47 | Engine ee, *engine = ⅇ | - | ||||||||||||
| 48 | Lexer lexer(engine); | - | ||||||||||||
| 49 | lexer.setCode(sourceCode, line, parseAsBinding); | - | ||||||||||||
| 50 | Parser parser(engine); | - | ||||||||||||
| 51 | - | |||||||||||||
| 52 | const bool parsed = parser.parseProgram(); | - | ||||||||||||
| 53 | - | |||||||||||||
| 54 | const auto diagnosticMessages = parser.diagnosticMessages(); | - | ||||||||||||
| 55 | for (const DiagnosticMessage &m : diagnosticMessages) { | - | ||||||||||||
| 56 | if (m.isError()
| 0-4804 | ||||||||||||
| 57 | valueScope.engine->throwSyntaxError(m.message, sourceFile, m.loc.startLine, m.loc.startColumn); | - | ||||||||||||
| 58 | return; executed 4782 times by 7 tests: return;Executed by:
| 4782 | ||||||||||||
| 59 | } else { | - | ||||||||||||
| 60 | QMessageLogger(__FILE__, 113, __PRETTY_FUNCTION__).warning() << sourceFile << ':' << m.loc.startLine << ':' << m.loc.startColumn | - | ||||||||||||
| 61 | << ": warning: " << m.message; | - | ||||||||||||
| 62 | } never executed: end of block | 0 | ||||||||||||
| 63 | } | - | ||||||||||||
| 64 | - | |||||||||||||
| 65 | if (parsed
| 316-2813723 | ||||||||||||
| 66 | using namespace AST; | - | ||||||||||||
| 67 | Program *program = AST::cast<Program *>(parser.rootNode()); | - | ||||||||||||
| 68 | if (!program
| 523002-2288635 | ||||||||||||
| 69 | - | |||||||||||||
| 70 | - | |||||||||||||
| 71 | return; executed 522737 times by 3 tests: return;Executed by:
| 522737 | ||||||||||||
| 72 | } | - | ||||||||||||
| 73 | - | |||||||||||||
| 74 | QV4::Compiler::JSUnitGenerator jsGenerator(&module); | - | ||||||||||||
| 75 | RuntimeCodegen cg(v4, &jsGenerator, strictMode); | - | ||||||||||||
| 76 | if (inheritContext
| 611236-1677898 | ||||||||||||
| 77 | cg.setUseFastLookups(false); executed 1677898 times by 29 tests: cg.setUseFastLookups(false);Executed by:
| 1677898 | ||||||||||||
| 78 | cg.generateFromProgram(sourceFile, sourceFile, sourceCode, program, &module, contextType); | - | ||||||||||||
| 79 | if (v4->hasException
| 1212-2286334 | ||||||||||||
| 80 | return; executed 1205 times by 3 tests: return;Executed by:
| 1205 | ||||||||||||
| 81 | - | |||||||||||||
| 82 | compilationUnit = cg.generateCompilationUnit(); | - | ||||||||||||
| 83 | vmFunction = compilationUnit->linkToEngine(v4); | - | ||||||||||||
| 84 | } executed 2288281 times by 31 tests: end of blockExecuted by:
| 2288281 | ||||||||||||
| 85 | - | |||||||||||||
| 86 | if (!vmFunction
| 316-2288254 | ||||||||||||
| 87 | - | |||||||||||||
| 88 | ScopedObject error(valueScope, v4->newSyntaxErrorObject(([]() noexcept -> QString { enum { Size = sizeof(u"" "Syntax error")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Syntax error" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 316 times by 1 test: qstring_literal_temp;return qstring_literal_temp;Executed by:
executed 316 times by 1 test: }())));return qstring_literal_temp;Executed by:
| 316 | ||||||||||||
| 89 | v4->throwError(error); | - | ||||||||||||
| 90 | } executed 317 times by 1 test: end of blockExecuted by:
| 317 | ||||||||||||
| 91 | } executed 2288656 times by 31 tests: end of blockExecuted by:
| 2288656 | ||||||||||||
| 92 | - | |||||||||||||
| 93 | ReturnedValue Script::run(const QV4::Value *thisObject) | - | ||||||||||||
| 94 | { | - | ||||||||||||
| 95 | if (!parsed
| 2374-118459 | ||||||||||||
| 96 | parse(); executed 2374 times by 5 tests: parse();Executed by:
| 2374 | ||||||||||||
| 97 | if (!vmFunction
| 12-121381 | ||||||||||||
| 98 | return executed 12 times by 2 tests: Encode::undefined();return Encode::undefined();Executed by:
executed 12 times by 2 tests: return Encode::undefined();Executed by:
| 12 | ||||||||||||
| 99 | - | |||||||||||||
| 100 | QV4::ExecutionEngine *engine = context->engine(); | - | ||||||||||||
| 101 | QV4::Scope valueScope(engine); | - | ||||||||||||
| 102 | - | |||||||||||||
| 103 | if (qmlContext.isUndefined()
| 1498-119455 | ||||||||||||
| 104 | TemporaryAssignment<Function*> savedGlobalCode(engine->globalCode, vmFunction); | - | ||||||||||||
| 105 | - | |||||||||||||
| 106 | return executed 119728 times by 14 tests: vmFunction->call(thisObject ? thisObject : engine->globalObject, nullptr, 0,return vmFunction->call(thisObject ? thisObject : engine->globalObject, nullptr, 0, context);Executed by:
executed 119728 times by 14 tests: return vmFunction->call(thisObject ? thisObject : engine->globalObject, nullptr, 0, context);Executed by:
| 119728 | ||||||||||||
| 107 | context); executed 119728 times by 14 tests: return vmFunction->call(thisObject ? thisObject : engine->globalObject, nullptr, 0, context);Executed by:
| 119728 | ||||||||||||
| 108 | } else { | - | ||||||||||||
| 109 | Scoped<QmlContext> qml(valueScope, qmlContext.value()); | - | ||||||||||||
| 110 | return executed 1498 times by 17 tests: vmFunction->call(thisObject, nullptr, 0, qml);return vmFunction->call(thisObject, nullptr, 0, qml);Executed by:
executed 1498 times by 17 tests: return vmFunction->call(thisObject, nullptr, 0, qml);Executed by:
| 1498 | ||||||||||||
| 111 | } | - | ||||||||||||
| 112 | } | - | ||||||||||||
| 113 | - | |||||||||||||
| 114 | Function *Script::function() | - | ||||||||||||
| 115 | { | - | ||||||||||||
| 116 | if (!parsed
| 0-1577457 | ||||||||||||
| 117 | parse(); never executed: parse(); | 0 | ||||||||||||
| 118 | return executed 1577049 times by 7 tests: vmFunction;return vmFunction;Executed by:
executed 1577049 times by 7 tests: return vmFunction;Executed by:
| 1577049 | ||||||||||||
| 119 | } | - | ||||||||||||
| 120 | - | |||||||||||||
| 121 | QQmlRefPointer<QV4::CompiledData::CompilationUnit> Script::precompile(QV4::Compiler::Module *module, QQmlJS::Engine *jsEngine, Compiler::JSUnitGenerator *unitGenerator, | - | ||||||||||||
| 122 | const QString &fileName, const QString &finalUrl, const QString &source, | - | ||||||||||||
| 123 | QList<QQmlError> *reportedErrors) | - | ||||||||||||
| 124 | { | - | ||||||||||||
| 125 | using namespace QV4::Compiler; | - | ||||||||||||
| 126 | using namespace QQmlJS::AST; | - | ||||||||||||
| 127 | - | |||||||||||||
| 128 | Lexer lexer(jsEngine); | - | ||||||||||||
| 129 | lexer.setCode(source, 1, false); | - | ||||||||||||
| 130 | Parser parser(jsEngine); | - | ||||||||||||
| 131 | - | |||||||||||||
| 132 | parser.parseProgram(); | - | ||||||||||||
| 133 | - | |||||||||||||
| 134 | QList<QQmlError> errors; | - | ||||||||||||
| 135 | - | |||||||||||||
| 136 | const auto diagnosticMessages = parser.diagnosticMessages(); | - | ||||||||||||
| 137 | for (const DiagnosticMessage &m : diagnosticMessages) { | - | ||||||||||||
| 138 | if (m.isWarning()
| 0-26 | ||||||||||||
| 139 | QMessageLogger(__FILE__, 192, __PRETTY_FUNCTION__).warning("%s:%d : %s", QtPrivate::asString(fileName).toLocal8Bit().constData(), m.loc.startLine, QtPrivate::asString(m.message).toLocal8Bit().constData()); | - | ||||||||||||
| 140 | continue; never executed: continue; | 0 | ||||||||||||
| 141 | } | - | ||||||||||||
| 142 | - | |||||||||||||
| 143 | QQmlError error; | - | ||||||||||||
| 144 | error.setUrl(QUrl(fileName)); | - | ||||||||||||
| 145 | error.setDescription(m.message); | - | ||||||||||||
| 146 | error.setLine(m.loc.startLine); | - | ||||||||||||
| 147 | error.setColumn(m.loc.startColumn); | - | ||||||||||||
| 148 | errors << error; | - | ||||||||||||
| 149 | } executed 26 times by 1 test: end of blockExecuted by:
| 26 | ||||||||||||
| 150 | - | |||||||||||||
| 151 | if (!errors.isEmpty()
| 26-90 | ||||||||||||
| 152 | if (reportedErrors
| 0-26 | ||||||||||||
| 153 | * executed 26 times by 1 test: reportedErrors << errors;*reportedErrors << errors;Executed by:
executed 26 times by 1 test: *reportedErrors << errors;Executed by:
| 26 | ||||||||||||
| 154 | return executed 26 times by 1 test: nullptr;return nullptr;Executed by:
executed 26 times by 1 test: return nullptr;Executed by:
| 26 | ||||||||||||
| 155 | } | - | ||||||||||||
| 156 | - | |||||||||||||
| 157 | Program *program = AST::cast<Program *>(parser.rootNode()); | - | ||||||||||||
| 158 | if (!program
| 0-90 | ||||||||||||
| 159 | - | |||||||||||||
| 160 | - | |||||||||||||
| 161 | return never executed: nullptr;return nullptr;never executed: return nullptr; | 0 | ||||||||||||
| 162 | } | - | ||||||||||||
| 163 | - | |||||||||||||
| 164 | Codegen cg(unitGenerator, false); | - | ||||||||||||
| 165 | cg.setUseFastLookups(false); | - | ||||||||||||
| 166 | cg.generateFromProgram(fileName, finalUrl, source, program, module, ContextType::Global); | - | ||||||||||||
| 167 | errors = cg.qmlErrors(); | - | ||||||||||||
| 168 | if (!errors.isEmpty()
| 0-90 | ||||||||||||
| 169 | if (reportedErrors
| 0 | ||||||||||||
| 170 | * never executed: reportedErrors << errors;*reportedErrors << errors;never executed: *reportedErrors << errors; | 0 | ||||||||||||
| 171 | return never executed: nullptr;return nullptr;never executed: return nullptr; | 0 | ||||||||||||
| 172 | } | - | ||||||||||||
| 173 | - | |||||||||||||
| 174 | return executed 90 times by 12 tests: cg.generateCompilationUnit( false);return cg.generateCompilationUnit( false);Executed by:
executed 90 times by 12 tests: return cg.generateCompilationUnit( false);Executed by:
| 90 | ||||||||||||
| 175 | } | - | ||||||||||||
| 176 | - | |||||||||||||
| 177 | Script *Script::createFromFileOrCache(ExecutionEngine *engine, QmlContext *qmlContext, const QString &fileName, const QUrl &originalUrl, QString *error) | - | ||||||||||||
| 178 | { | - | ||||||||||||
| 179 | if (error
| 0-1178 | ||||||||||||
| 180 | error->clear(); executed 1178 times by 5 tests: error->clear();Executed by:
| 1178 | ||||||||||||
| 181 | - | |||||||||||||
| 182 | QQmlMetaType::CachedUnitLookupError cacheError = QQmlMetaType::CachedUnitLookupError::NoError; | - | ||||||||||||
| 183 | if (const
| 2-1176 | ||||||||||||
| 184 | QQmlRefPointer<QV4::CompiledData::CompilationUnit> jsUnit; | - | ||||||||||||
| 185 | jsUnit.adopt(new QV4::CompiledData::CompilationUnit(cachedUnit)); | - | ||||||||||||
| 186 | return executed 2 times by 1 test: new QV4::Script(engine, qmlContext, jsUnit);return new QV4::Script(engine, qmlContext, jsUnit);Executed by:
executed 2 times by 1 test: return new QV4::Script(engine, qmlContext, jsUnit);Executed by:
| 2 | ||||||||||||
| 187 | } | - | ||||||||||||
| 188 | - | |||||||||||||
| 189 | QFile f(fileName); | - | ||||||||||||
| 190 | if (!f.open(QIODevice::ReadOnly)
| 2-1174 | ||||||||||||
| 191 | if (error
| 0-2 | ||||||||||||
| 192 | if (cacheError == QQmlMetaType::CachedUnitLookupError::VersionMismatch
| 0-2 | ||||||||||||
| 193 | * never executed: error = originalUrl.toString() + QString::fromUtf8(" was compiled ahead of time with an incompatible version of Qt and the original source code cannot be found. Please recompile");*error = originalUrl.toString() + QString::fromUtf8(" was compiled ahead of time with an incompatible version of Qt and the original source code cannot be found. Please recompile");never executed: *error = originalUrl.toString() + QString::fromUtf8(" was compiled ahead of time with an incompatible version of Qt and the original source code cannot be found. Please recompile"); | 0 | ||||||||||||
| 194 | else | - | ||||||||||||
| 195 | * executed 2 times by 1 test: error = QString::fromUtf8("Error opening source file %1: %2").arg(originalUrl.toString()).arg(f.errorString());*error = QString::fromUtf8("Error opening source file %1: %2").arg(originalUrl.toString()).arg(f.errorString());Executed by:
executed 2 times by 1 test: *error = QString::fromUtf8("Error opening source file %1: %2").arg(originalUrl.toString()).arg(f.errorString());Executed by:
| 2 | ||||||||||||
| 196 | } | - | ||||||||||||
| 197 | return executed 2 times by 1 test: nullptr;return nullptr;Executed by:
executed 2 times by 1 test: return nullptr;Executed by:
| 2 | ||||||||||||
| 198 | } | - | ||||||||||||
| 199 | - | |||||||||||||
| 200 | QByteArray data = f.readAll(); | - | ||||||||||||
| 201 | QString sourceCode = QString::fromUtf8(data); | - | ||||||||||||
| 202 | QmlIR::Document::removeScriptPragmas(sourceCode); | - | ||||||||||||
| 203 | - | |||||||||||||
| 204 | auto result = new QV4::Script(engine, qmlContext, sourceCode, originalUrl.toString()); | - | ||||||||||||
| 205 | result->parse(); | - | ||||||||||||
| 206 | return executed 1174 times by 4 tests: result;return result;Executed by:
executed 1174 times by 4 tests: return result;Executed by:
| 1174 | ||||||||||||
| 207 | } | - | ||||||||||||
| 208 | - | |||||||||||||
| 209 | QV4::ReturnedValue Script::evaluate(ExecutionEngine *engine, const QString &script, QmlContext *qmlContext) | - | ||||||||||||
| 210 | { | - | ||||||||||||
| 211 | QV4::Scope scope(engine); | - | ||||||||||||
| 212 | QV4::Script qmlScript(engine, qmlContext, script, QString()); | - | ||||||||||||
| 213 | - | |||||||||||||
| 214 | qmlScript.parse(); | - | ||||||||||||
| 215 | QV4::ScopedValue result(scope); | - | ||||||||||||
| 216 | if (!scope.engine->hasException
| 0 | ||||||||||||
| 217 | result = qmlScript.run(); never executed: result = qmlScript.run(); | 0 | ||||||||||||
| 218 | if (scope.engine->hasException
| 0 | ||||||||||||
| 219 | scope.engine->catchException(); | - | ||||||||||||
| 220 | return never executed: Encode::undefined();return Encode::undefined();never executed: return Encode::undefined(); | 0 | ||||||||||||
| 221 | } | - | ||||||||||||
| 222 | return never executed: result->asReturnedValue();return result->asReturnedValue();never executed: return result->asReturnedValue(); | 0 | ||||||||||||
| 223 | } | - | ||||||||||||
| Switch to Source code | Preprocessed file |