Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/jsruntime/qv4include.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | - | |||||||||||||
5 | - | |||||||||||||
6 | - | |||||||||||||
7 | - | |||||||||||||
8 | QV4Include::QV4Include(const QUrl &url, QV4::ExecutionEngine *engine, | - | ||||||||||||
9 | QV4::QmlContext *qmlContext, const QV4::Value &callback) | - | ||||||||||||
10 | : v4(engine), m_url(url) | - | ||||||||||||
11 | - | |||||||||||||
12 | , m_redirectCount(0), m_network(nullptr) , m_reply(nullptr) | - | ||||||||||||
13 | - | |||||||||||||
14 | { | - | ||||||||||||
15 | if (qmlContext
| 0-6 | ||||||||||||
16 | m_qmlContext.set(engine, *qmlContext); executed 6 times by 1 test: m_qmlContext.set(engine, *qmlContext); Executed by:
| 6 | ||||||||||||
17 | if (callback.as<QV4::FunctionObject>()
| 0-6 | ||||||||||||
18 | m_callbackFunction.set(engine, callback); executed 6 times by 1 test: m_callbackFunction.set(engine, callback); Executed by:
| 6 | ||||||||||||
19 | - | |||||||||||||
20 | m_resultObject.set(v4, resultValue(v4)); | - | ||||||||||||
21 | - | |||||||||||||
22 | - | |||||||||||||
23 | m_network = engine->v8Engine->networkAccessManager(); | - | ||||||||||||
24 | - | |||||||||||||
25 | QNetworkRequest request; | - | ||||||||||||
26 | request.setUrl(url); | - | ||||||||||||
27 | - | |||||||||||||
28 | m_reply = m_network->get(request); | - | ||||||||||||
29 | QObject::connect(m_reply, qFlagLocation("2""finished()" "\0" __FILE__ ":" "81"), this, qFlagLocation("1""finished()" "\0" __FILE__ ":" "81")); | - | ||||||||||||
30 | - | |||||||||||||
31 | - | |||||||||||||
32 | - | |||||||||||||
33 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||
34 | - | |||||||||||||
35 | QV4Include::~QV4Include() | - | ||||||||||||
36 | { | - | ||||||||||||
37 | - | |||||||||||||
38 | delete m_reply; | - | ||||||||||||
39 | m_reply = nullptr; | - | ||||||||||||
40 | - | |||||||||||||
41 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||
42 | - | |||||||||||||
43 | QV4::ReturnedValue QV4Include::resultValue(QV4::ExecutionEngine *v4, Status status, | - | ||||||||||||
44 | const QString &statusText) | - | ||||||||||||
45 | { | - | ||||||||||||
46 | QV4::Scope scope(v4); | - | ||||||||||||
47 | - | |||||||||||||
48 | - | |||||||||||||
49 | QV4::ScopedObject o(scope, v4->newObject()); | - | ||||||||||||
50 | QV4::ScopedString s(scope); | - | ||||||||||||
51 | QV4::ScopedValue v(scope); | - | ||||||||||||
52 | o->put((s = v4->newString(([]() noexcept -> QString { enum { Size = sizeof(u"" "OK")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "OK" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 30 times by 3 tests: qstring_literal_temp;return qstring_literal_temp; Executed by:
executed 30 times by 3 tests: }()))), (v = QV4::Primitive::fromInt32(Ok)));return qstring_literal_temp; Executed by:
| 30 | ||||||||||||
53 | o->put((s = v4->newString(([]() noexcept -> QString { enum { Size = sizeof(u"" "LOADING")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "LOADING" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 30 times by 3 tests: qstring_literal_temp;return qstring_literal_temp; Executed by:
executed 30 times by 3 tests: }()))), (v = QV4::Primitive::fromInt32(Loading)));return qstring_literal_temp; Executed by:
| 30 | ||||||||||||
54 | o->put((s = v4->newString(([]() noexcept -> QString { enum { Size = sizeof(u"" "NETWORK_ERROR")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "NETWORK_ERROR" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 30 times by 3 tests: qstring_literal_temp;return qstring_literal_temp; Executed by:
executed 30 times by 3 tests: }()))), (v = QV4::Primitive::fromInt32(NetworkError)));return qstring_literal_temp; Executed by:
| 30 | ||||||||||||
55 | o->put((s = v4->newString(([]() noexcept -> QString { enum { Size = sizeof(u"" "EXCEPTION")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "EXCEPTION" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 30 times by 3 tests: qstring_literal_temp;return qstring_literal_temp; Executed by:
executed 30 times by 3 tests: }()))), (v = QV4::Primitive::fromInt32(Exception)));return qstring_literal_temp; Executed by:
| 30 | ||||||||||||
56 | o->put((s = v4->newString(([]() noexcept -> QString { enum { Size = sizeof(u"" "status")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "status" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 30 times by 3 tests: qstring_literal_temp;return qstring_literal_temp; Executed by:
executed 30 times by 3 tests: }()))), (v = QV4::Primitive::fromInt32(status)));return qstring_literal_temp; Executed by:
| 30 | ||||||||||||
57 | if (!statusText.isEmpty()
| 2-28 | ||||||||||||
58 | o->put((s = v4->newString(([]() noexcept -> QString { enum { Size = sizeof(u"" "statusText")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "statusText" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 2 times by 1 test: qstring_literal_temp;return qstring_literal_temp; Executed by:
executed 2 times by 1 test: }()))), (v = v4->newString(statusText)));return qstring_literal_temp; Executed by:
executed 2 times by 1 test: o->put((s = v4->newString(([]() noexcept -> QString { enum { Size = sizeof(u"" "statusText")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "statusText" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()))), (v = v4->newString(statusText))); Executed by:
| 2 | ||||||||||||
59 | - | |||||||||||||
60 | return executed 30 times by 3 tests: o.asReturnedValue();return o.asReturnedValue(); Executed by:
executed 30 times by 3 tests: return o.asReturnedValue(); Executed by:
| 30 | ||||||||||||
61 | } | - | ||||||||||||
62 | - | |||||||||||||
63 | void QV4Include::callback(const QV4::Value &callback, const QV4::Value &status) | - | ||||||||||||
64 | { | - | ||||||||||||
65 | if (!callback.isObject()
| 12-18 | ||||||||||||
66 | return; executed 18 times by 3 tests: return; Executed by:
| 18 | ||||||||||||
67 | QV4::ExecutionEngine *v4 = callback.as<QV4::Object>()->engine(); | - | ||||||||||||
68 | QV4::Scope scope(v4); | - | ||||||||||||
69 | QV4::ScopedFunctionObject f(scope, callback); | - | ||||||||||||
70 | if (!f
| 0-12 | ||||||||||||
71 | return; never executed: return; | 0 | ||||||||||||
72 | - | |||||||||||||
73 | QV4::JSCallData jsCallData(scope, 1); | - | ||||||||||||
74 | *jsCallData->thisObject = v4->globalObject->asReturnedValue(); | - | ||||||||||||
75 | jsCallData->args[0] = status; | - | ||||||||||||
76 | f->call(jsCallData); | - | ||||||||||||
77 | if (scope.hasException()
| 0-12 | ||||||||||||
78 | scope.engine->catchException(); never executed: scope.engine->catchException(); | 0 | ||||||||||||
79 | } executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||||||||
80 | - | |||||||||||||
81 | QV4::ReturnedValue QV4Include::result() | - | ||||||||||||
82 | { | - | ||||||||||||
83 | return executed 6 times by 1 test: m_resultObject.value();return m_resultObject.value(); Executed by:
executed 6 times by 1 test: return m_resultObject.value(); Executed by:
| 6 | ||||||||||||
84 | } | - | ||||||||||||
85 | - | |||||||||||||
86 | - | |||||||||||||
87 | void QV4Include::finished() | - | ||||||||||||
88 | { | - | ||||||||||||
89 | - | |||||||||||||
90 | m_redirectCount++; | - | ||||||||||||
91 | - | |||||||||||||
92 | if (m_redirectCount < 15
| 0-6 | ||||||||||||
93 | QVariant redirect = m_reply->attribute(QNetworkRequest::RedirectionTargetAttribute); | - | ||||||||||||
94 | if (redirect.isValid()
| 0-6 | ||||||||||||
95 | m_url = m_url.resolved(redirect.toUrl()); | - | ||||||||||||
96 | delete m_reply; | - | ||||||||||||
97 | - | |||||||||||||
98 | QNetworkRequest request; | - | ||||||||||||
99 | request.setUrl(m_url); | - | ||||||||||||
100 | - | |||||||||||||
101 | m_reply = m_network->get(request); | - | ||||||||||||
102 | QObject::connect(m_reply, qFlagLocation("2""finished()" "\0" __FILE__ ":" "154"), this, qFlagLocation("1""finished()" "\0" __FILE__ ":" "154")); | - | ||||||||||||
103 | return; never executed: return; | 0 | ||||||||||||
104 | } | - | ||||||||||||
105 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||
106 | - | |||||||||||||
107 | QV4::Scope scope(v4); | - | ||||||||||||
108 | QV4::ScopedObject resultObj(scope, m_resultObject.value()); | - | ||||||||||||
109 | QV4::ScopedString status(scope, v4->newString(([]() noexcept -> QString { enum { Size = sizeof(u"" "status")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "status" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 6 times by 1 test: qstring_literal_temp;return qstring_literal_temp; Executed by:
executed 6 times by 1 test: }())));return qstring_literal_temp; Executed by:
| 6 | ||||||||||||
110 | if (m_reply->error() == QNetworkReply::NoError
| 2-4 | ||||||||||||
111 | QByteArray data = m_reply->readAll(); | - | ||||||||||||
112 | - | |||||||||||||
113 | QString code = QString::fromUtf8(data); | - | ||||||||||||
114 | QmlIR::Document::removeScriptPragmas(code); | - | ||||||||||||
115 | - | |||||||||||||
116 | QV4::Scoped<QV4::QmlContext> qml(scope, m_qmlContext.value()); | - | ||||||||||||
117 | QV4::Script script(v4, qml, code, m_url.toString()); | - | ||||||||||||
118 | - | |||||||||||||
119 | script.parse(); | - | ||||||||||||
120 | if (!scope.engine->hasException
| 0-4 | ||||||||||||
121 | script.run(); executed 4 times by 1 test: script.run(); Executed by:
| 4 | ||||||||||||
122 | if (scope.engine->hasException
| 2 | ||||||||||||
123 | QV4::ScopedValue ex(scope, scope.engine->catchException()); | - | ||||||||||||
124 | resultObj->put(status, QV4::ScopedValue(scope, QV4::Primitive::fromInt32(Exception))); | - | ||||||||||||
125 | QV4::ScopedString exception(scope, v4->newString(([]() noexcept -> QString { enum { Size = sizeof(u"" "exception")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "exception" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 2 times by 1 test: qstring_literal_temp;return qstring_literal_temp; Executed by:
executed 2 times by 1 test: }())));return qstring_literal_temp; Executed by:
| 2 | ||||||||||||
126 | resultObj->put(exception, ex); | - | ||||||||||||
127 | } executed 2 times by 1 test: else {end of block Executed by:
| 2 | ||||||||||||
128 | resultObj->put(status, QV4::ScopedValue(scope, QV4::Primitive::fromInt32(Ok))); | - | ||||||||||||
129 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
130 | } else { | - | ||||||||||||
131 | resultObj->put(status, QV4::ScopedValue(scope, QV4::Primitive::fromInt32(NetworkError))); | - | ||||||||||||
132 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
133 | - | |||||||||||||
134 | - | |||||||||||||
135 | - | |||||||||||||
136 | - | |||||||||||||
137 | - | |||||||||||||
138 | - | |||||||||||||
139 | - | |||||||||||||
140 | QV4::ScopedValue cb(scope, m_callbackFunction.value()); | - | ||||||||||||
141 | callback(cb, resultObj); | - | ||||||||||||
142 | - | |||||||||||||
143 | disconnect(); | - | ||||||||||||
144 | deleteLater(); | - | ||||||||||||
145 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||
146 | - | |||||||||||||
147 | - | |||||||||||||
148 | - | |||||||||||||
149 | - | |||||||||||||
150 | QV4::ReturnedValue QV4Include::method_include(const QV4::FunctionObject *b, const QV4::Value *, const QV4::Value *argv, int argc) | - | ||||||||||||
151 | { | - | ||||||||||||
152 | QV4::Scope scope(b); | - | ||||||||||||
153 | if (!argc
| 0-30 | ||||||||||||
154 | return never executed: QV4::Encode::undefined();return QV4::Encode::undefined(); never executed: return QV4::Encode::undefined(); | 0 | ||||||||||||
155 | - | |||||||||||||
156 | QQmlContextData *context = scope.engine->callingQmlContext(); | - | ||||||||||||
157 | - | |||||||||||||
158 | if (!context
| 0-30 | ||||||||||||
159 | return never executed: QV4::Encode(scope.engine->throwError(QString::fromUtf8("Qt.include(): Can only be called from JavaScript files")));return QV4::Encode(scope.engine->throwError(QString::fromUtf8("Qt.include(): Can only be called from JavaScript files"))); never executed: return QV4::Encode(scope.engine->throwError(QString::fromUtf8("Qt.include(): Can only be called from JavaScript files"))); | 0 | ||||||||||||
160 | - | |||||||||||||
161 | QV4::ScopedValue callbackFunction(scope, QV4::Primitive::undefinedValue()); | - | ||||||||||||
162 | if (argc >= 2
| 0-18 | ||||||||||||
163 | callbackFunction = argv[1]; executed 12 times by 1 test: callbackFunction = argv[1]; Executed by:
| 12 | ||||||||||||
164 | - | |||||||||||||
165 | - | |||||||||||||
166 | QUrl url(scope.engine->resolvedUrl(argv[0].toQStringNoThrow())); | - | ||||||||||||
167 | if (scope.engine->qmlEngine()
| 0-28 | ||||||||||||
168 | url = scope.engine->qmlEngine()->urlInterceptor()->intercept(url, QQmlAbstractUrlInterceptor::JavaScriptFile); never executed: url = scope.engine->qmlEngine()->urlInterceptor()->intercept(url, QQmlAbstractUrlInterceptor::JavaScriptFile); | 0 | ||||||||||||
169 | - | |||||||||||||
170 | QString localFile = QQmlFile::urlToLocalFileOrQrc(url); | - | ||||||||||||
171 | - | |||||||||||||
172 | QV4::ScopedValue result(scope); | - | ||||||||||||
173 | QV4::Scoped<QV4::QmlContext> qmlcontext(scope, scope.engine->qmlContext()); | - | ||||||||||||
174 | - | |||||||||||||
175 | if (localFile.isEmpty()
| 6-24 | ||||||||||||
176 | QV4Include *i = new QV4Include(url, scope.engine, qmlcontext, callbackFunction); | - | ||||||||||||
177 | result = i->result(); | - | ||||||||||||
178 | - | |||||||||||||
179 | } executed 6 times by 1 test: else {end of block Executed by:
| 6 | ||||||||||||
180 | QScopedPointer<QV4::Script> script; | - | ||||||||||||
181 | QString error; | - | ||||||||||||
182 | script.reset(QV4::Script::createFromFileOrCache(scope.engine, qmlcontext, localFile, url, &error)); | - | ||||||||||||
183 | - | |||||||||||||
184 | if (!script.isNull()
| 2-22 | ||||||||||||
185 | script->parse(); | - | ||||||||||||
186 | if (!scope.engine->hasException
| 0-22 | ||||||||||||
187 | script->run(); executed 22 times by 3 tests: script->run(); Executed by:
| 22 | ||||||||||||
188 | if (scope.engine->hasException
| 2-20 | ||||||||||||
189 | QV4::ScopedValue ex(scope, scope.engine->catchException()); | - | ||||||||||||
190 | result = resultValue(scope.engine, Exception); | - | ||||||||||||
191 | QV4::ScopedString exception(scope, scope.engine->newString(([]() noexcept -> QString { enum { Size = sizeof(u"" "exception")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "exception" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 2 times by 1 test: qstring_literal_temp;return qstring_literal_temp; Executed by:
executed 2 times by 1 test: }())));return qstring_literal_temp; Executed by:
| 2 | ||||||||||||
192 | result->as<QV4::Object>()->put(exception, ex); | - | ||||||||||||
193 | } executed 2 times by 1 test: else {end of block Executed by:
| 2 | ||||||||||||
194 | result = resultValue(scope.engine, Ok); | - | ||||||||||||
195 | } executed 20 times by 3 tests: end of block Executed by:
| 20 | ||||||||||||
196 | } else { | - | ||||||||||||
197 | result = resultValue(scope.engine, NetworkError, error); | - | ||||||||||||
198 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
199 | - | |||||||||||||
200 | callback(callbackFunction, result); | - | ||||||||||||
201 | } executed 24 times by 3 tests: end of block Executed by:
| 24 | ||||||||||||
202 | - | |||||||||||||
203 | - | |||||||||||||
204 | - | |||||||||||||
205 | - | |||||||||||||
206 | - | |||||||||||||
207 | - | |||||||||||||
208 | - | |||||||||||||
209 | return executed 30 times by 3 tests: result->asReturnedValue();return result->asReturnedValue(); Executed by:
executed 30 times by 3 tests: return result->asReturnedValue(); Executed by:
| 30 | ||||||||||||
210 | } | - | ||||||||||||
211 | - | |||||||||||||
212 | - | |||||||||||||
213 | - | |||||||||||||
Switch to Source code | Preprocessed file |