History

rework ScriptValue to act like a stack variable rather than a pointer

Heather Anderson committed 5 years ago

Commit 85810221 parent f209c51170 files · +2837 −2594Browse files

Showing the changes to libraries/script-engine/src/XMLHttpRequestClass.cpp (1 of 170 files). Show all

Unified · Split

libraries/script-engine/src/XMLHttpRequestClass.cpp+14−13
@@ -25,6 +25,7 @@ · 24 unmodified lines
2525 #include "ResourceRequestObserver.h"
2626 #include "ScriptContext.h"
2727 #include "ScriptEngine.h"
28+#include "ScriptEngineCast.h"
2829 #include "ScriptValue.h"
2930
3031 Q_DECLARE_METATYPE(QByteArray*)
@@ -43,15 +44,15 @@ XMLHttpRequestClass::~XMLHttpRequestClass() { · 12 unmodified lines
4344 if (_reply) { _reply->deleteLater(); }
4445 }
4546
46−ScriptValuePointer XMLHttpRequestClass::constructor(ScriptContext* context, ScriptEngine* engine) {
47+ScriptValue XMLHttpRequestClass::constructor(ScriptContext* context, ScriptEngine* engine) {
4748 return engine->newQObject(new XMLHttpRequestClass(engine), ScriptEngine::ScriptOwnership);
4849 }
4950
50−ScriptValuePointer XMLHttpRequestClass::getStatus() const {
51+ScriptValue XMLHttpRequestClass::getStatus() const {
5152 if (_reply) {
5253 return _engine->newValue(_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt());
5354 }
54− return ScriptValuePointer(0);
55+ return ScriptValue(_engine->newValue(0));
5556 }
5657
5758 QString XMLHttpRequestClass::getStatusText() const {
@@ -91,7 +92,7 @@ void XMLHttpRequestClass::requestDownloadProgress(qint64 bytesReceived, qint64 b · 33 unmodified lines
9192 }
9293 }
9394
94−ScriptValuePointer XMLHttpRequestClass::getAllResponseHeaders() const {
95+ScriptValue XMLHttpRequestClass::getAllResponseHeaders() const {
9596 if (_reply) {
9697 QList<QNetworkReply::RawHeaderPair> headerList = _reply->rawHeaderPairs();
9798 QByteArray headers;
@@ -106,7 +107,7 @@ ScriptValuePointer XMLHttpRequestClass::getAllResponseHeaders() const { · 8 unmodified lines
106107 return _engine->newValue("");
107108 }
108109
109−ScriptValuePointer XMLHttpRequestClass::getResponseHeader(const QString& name) const {
110+ScriptValue XMLHttpRequestClass::getResponseHeader(const QString& name) const {
110111 if (_reply && _reply->hasRawHeader(name.toLatin1())) {
111112 return _engine->newValue(QString(_reply->rawHeader(name.toLatin1())));
112113 }
@@ -120,8 +121,8 @@ ScriptValuePointer XMLHttpRequestClass::getResponseHeader(const QString& name) c · 7 unmodified lines
120121 void XMLHttpRequestClass::setReadyState(ReadyState readyState) {
121122 if (readyState != _readyState) {
122123 _readyState = readyState;
123− if (_onReadyStateChange->isFunction()) {
124− _onReadyStateChange->call(_onReadyStateChange->engine()->nullValue());
124+ if (_onReadyStateChange.isFunction()) {
125+ _onReadyStateChange.call(_onReadyStateChange.engine()->nullValue());
125126 }
126127 }
127128 }
@@ -160,14 +161,14 @@ void XMLHttpRequestClass::send() { · 32 unmodified lines
160161 send(_engine->nullValue());
161162 }
162163
163−void XMLHttpRequestClass::send(const ScriptValuePointer& data) {
164+void XMLHttpRequestClass::send(const ScriptValue& data) {
164165 if (_readyState == OPENED && !_reply) {
165166
166167 if (!data.isNull()) {
167− if (data->isObject()) {
168+ if (data.isObject()) {
168169 _sendData = scriptvalue_cast<QByteArray>(data);
169170 } else {
170− _sendData = data->toString().toUtf8();
171+ _sendData = data.toString().toUtf8();
171172 }
172173 }
173174
@@ -197,8 +198,8 @@ void XMLHttpRequestClass::doSend() { · 23 unmodified lines
197198 * @callback XMLHttpRequest~onTimeoutCallback
198199 */
199200 void XMLHttpRequestClass::requestTimeout() {
200− if (_onTimeout->isFunction()) {
201− _onTimeout->call(_engine->nullValue());
201+ if (_onTimeout.isFunction()) {
202+ _onTimeout.call(_engine->nullValue());
202203 }
203204 abortRequest();
204205 _errorCode = QNetworkReply::TimeoutError;
@@ -219,7 +220,7 @@ void XMLHttpRequestClass::requestFinished() { · 14 unmodified lines
219220
220221 if (_responseType == "json") {
221222 _responseData = _engine->evaluate("(" + QString(_rawResponseData.data()) + ")");
222− if (_responseData->isError()) {
223+ if (_responseData.isError()) {
223224 _engine->clearExceptions();
224225 _responseData = _engine->nullValue();
225226 }