Showing the changes to libraries/script-engine/src/XMLHttpRequestClass.cpp (1 of 170 files). Show all
Unified · Split
| @@ -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 | ||
| 30 | Q_DECLARE_METATYPE(QByteArray*) | 31 | Q_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 | ||
| 46 | ScriptValuePointer XMLHttpRequestClass::constructor(ScriptContext* context, ScriptEngine* engine) { | 47 | ScriptValue 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 | ||
| 50 | ScriptValuePointer XMLHttpRequestClass::getStatus() const { | 51 | ScriptValue 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 | ||
| 57 | QString XMLHttpRequestClass::getStatusText() const { | 58 | QString XMLHttpRequestClass::getStatusText() const { |
| @@ -91,7 +92,7 @@ void XMLHttpRequestClass::requestDownloadProgress(qint64 bytesReceived, qint64 b · 33 unmodified lines | |||
| 91 | } | 92 | } |
| 92 | } | 93 | } |
| 93 | 94 | ||
| 94 | ScriptValuePointer XMLHttpRequestClass::getAllResponseHeaders() const { | 95 | ScriptValue 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 | ||
| 109 | ScriptValuePointer XMLHttpRequestClass::getResponseHeader(const QString& name) const { | 110 | ScriptValue 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 | |||
| 120 | void XMLHttpRequestClass::setReadyState(ReadyState readyState) { | 121 | void 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 | ||
| 163 | void XMLHttpRequestClass::send(const ScriptValuePointer& data) { | 164 | void 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 | */ |
| 199 | void XMLHttpRequestClass::requestTimeout() { | 200 | void 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 | } |