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
25#include "ResourceRequestObserver.h"25#include "ResourceRequestObserver.h"
26#include "ScriptContext.h"26#include "ScriptContext.h"
27#include "ScriptEngine.h"27#include "ScriptEngine.h"
28#include "ScriptEngineCast.h"
28#include "ScriptValue.h"29#include "ScriptValue.h"
29 30
30Q_DECLARE_METATYPE(QByteArray*)31Q_DECLARE_METATYPE(QByteArray*)
@@ -43,15 +44,15 @@ XMLHttpRequestClass::~XMLHttpRequestClass() { · 12 unmodified lines
43 if (_reply) { _reply->deleteLater(); }44 if (_reply) { _reply->deleteLater(); }
44}45}
45 46
46ScriptValuePointer XMLHttpRequestClass::constructor(ScriptContext* context, ScriptEngine* engine) {47ScriptValue XMLHttpRequestClass::constructor(ScriptContext* context, ScriptEngine* engine) {
47 return engine->newQObject(new XMLHttpRequestClass(engine), ScriptEngine::ScriptOwnership);48 return engine->newQObject(new XMLHttpRequestClass(engine), ScriptEngine::ScriptOwnership);
48}49}
49 50
50ScriptValuePointer XMLHttpRequestClass::getStatus() const {51ScriptValue XMLHttpRequestClass::getStatus() const {
51 if (_reply) {52 if (_reply) {
52 return _engine->newValue(_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt());53 return _engine->newValue(_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt());
53 } 54 }
54 return ScriptValuePointer(0);55 return ScriptValue(_engine->newValue(0));
55}56}
56 57
57QString XMLHttpRequestClass::getStatusText() const {58QString XMLHttpRequestClass::getStatusText() const {
@@ -91,7 +92,7 @@ void XMLHttpRequestClass::requestDownloadProgress(qint64 bytesReceived, qint64 b · 33 unmodified lines
91 }92 }
92}93}
93 94
94ScriptValuePointer XMLHttpRequestClass::getAllResponseHeaders() const {95ScriptValue XMLHttpRequestClass::getAllResponseHeaders() const {
95 if (_reply) {96 if (_reply) {
96 QList<QNetworkReply::RawHeaderPair> headerList = _reply->rawHeaderPairs();97 QList<QNetworkReply::RawHeaderPair> headerList = _reply->rawHeaderPairs();
97 QByteArray headers;98 QByteArray headers;
@@ -106,7 +107,7 @@ ScriptValuePointer XMLHttpRequestClass::getAllResponseHeaders() const { · 8 unmodified lines
106 return _engine->newValue("");107 return _engine->newValue("");
107}108}
108 109
109ScriptValuePointer XMLHttpRequestClass::getResponseHeader(const QString& name) const {110ScriptValue XMLHttpRequestClass::getResponseHeader(const QString& name) const {
110 if (_reply && _reply->hasRawHeader(name.toLatin1())) {111 if (_reply && _reply->hasRawHeader(name.toLatin1())) {
111 return _engine->newValue(QString(_reply->rawHeader(name.toLatin1())));112 return _engine->newValue(QString(_reply->rawHeader(name.toLatin1())));
112 }113 }
@@ -120,8 +121,8 @@ ScriptValuePointer XMLHttpRequestClass::getResponseHeader(const QString& name) c · 7 unmodified lines
120void XMLHttpRequestClass::setReadyState(ReadyState readyState) {121void XMLHttpRequestClass::setReadyState(ReadyState readyState) {
121 if (readyState != _readyState) {122 if (readyState != _readyState) {
122 _readyState = readyState;123 _readyState = readyState;
123 if (_onReadyStateChange->isFunction()) {124 if (_onReadyStateChange.isFunction()) {
124 _onReadyStateChange->call(_onReadyStateChange->engine()->nullValue());125 _onReadyStateChange.call(_onReadyStateChange.engine()->nullValue());
125 }126 }
126 }127 }
127}128}
@@ -160,14 +161,14 @@ void XMLHttpRequestClass::send() { · 32 unmodified lines
160 send(_engine->nullValue());161 send(_engine->nullValue());
161}162}
162 163
163void XMLHttpRequestClass::send(const ScriptValuePointer& data) {164void XMLHttpRequestClass::send(const ScriptValue& data) {
164 if (_readyState == OPENED && !_reply) {165 if (_readyState == OPENED && !_reply) {
165 166
166 if (!data.isNull()) {167 if (!data.isNull()) {
167 if (data->isObject()) {168 if (data.isObject()) {
168 _sendData = scriptvalue_cast<QByteArray>(data);169 _sendData = scriptvalue_cast<QByteArray>(data);
169 } else {170 } else {
170 _sendData = data->toString().toUtf8();171 _sendData = data.toString().toUtf8();
171 }172 }
172 }173 }
173 174
@@ -197,8 +198,8 @@ void XMLHttpRequestClass::doSend() { · 23 unmodified lines
197 * @callback XMLHttpRequest~onTimeoutCallback 198 * @callback XMLHttpRequest~onTimeoutCallback
198 */199 */
199void XMLHttpRequestClass::requestTimeout() {200void XMLHttpRequestClass::requestTimeout() {
200 if (_onTimeout->isFunction()) {201 if (_onTimeout.isFunction()) {
201 _onTimeout->call(_engine->nullValue());202 _onTimeout.call(_engine->nullValue());
202 }203 }
203 abortRequest();204 abortRequest();
204 _errorCode = QNetworkReply::TimeoutError;205 _errorCode = QNetworkReply::TimeoutError;
@@ -219,7 +220,7 @@ void XMLHttpRequestClass::requestFinished() { · 14 unmodified lines
219 220
220 if (_responseType == "json") {221 if (_responseType == "json") {
221 _responseData = _engine->evaluate("(" + QString(_rawResponseData.data()) + ")");222 _responseData = _engine->evaluate("(" + QString(_rawResponseData.data()) + ")");
222 if (_responseData->isError()) {223 if (_responseData.isError()) {
223 _engine->clearExceptions();224 _engine->clearExceptions();
224 _responseData = _engine->nullValue();225 _responseData = _engine->nullValue();
225 }226 }