Showing the changes to libraries/script-engine/src/XMLHttpRequestClass.cpp (1 of 260 files). Show all
Unified · Split
| @@ -23,12 +23,16 @@ · 22 unmodified lines | |||
| 23 | #include <MetaverseAPI.h> | 23 | #include <MetaverseAPI.h> |
| 24 | 24 | ||
| 25 | #include "ResourceRequestObserver.h" | 25 | #include "ResourceRequestObserver.h" |
| 26 | #include "ScriptContext.h" | ||
| 26 | #include "ScriptEngine.h" | 27 | #include "ScriptEngine.h" |
| 28 | #include "ScriptValue.h" | ||
| 27 | 29 | ||
| 28 | Q_DECLARE_METATYPE(QByteArray*) | 30 | Q_DECLARE_METATYPE(QByteArray*) |
| 29 | 31 | ||
| 30 | XMLHttpRequestClass::XMLHttpRequestClass(QScriptEngine* engine) : | 32 | XMLHttpRequestClass::XMLHttpRequestClass(ScriptEngine* engine) : |
| 31 | _engine(engine), | 33 | _engine(engine), |
| 34 | _onTimeout(engine->nullValue()), | ||
| 35 | _onReadyStateChange(engine->nullValue()), | ||
| 32 | _timer(this) { | 36 | _timer(this) { |
| 33 | 37 | ||
| 34 | _request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true); | 38 | _request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true); |
| @@ -39,15 +43,15 @@ XMLHttpRequestClass::~XMLHttpRequestClass() { · 4 unmodified lines | |||
| 39 | if (_reply) { _reply->deleteLater(); } | 43 | if (_reply) { _reply->deleteLater(); } |
| 40 | } | 44 | } |
| 41 | 45 | ||
| 42 | QScriptValue XMLHttpRequestClass::constructor(QScriptContext* context, QScriptEngine* engine) { | 46 | ScriptValuePointer XMLHttpRequestClass::constructor(ScriptContext* context, ScriptEngine* engine) { |
| 43 | return engine->newQObject(new XMLHttpRequestClass(engine), QScriptEngine::ScriptOwnership); | 47 | return engine->newQObject(new XMLHttpRequestClass(engine), ScriptEngine::ScriptOwnership); |
| 44 | } | 48 | } |
| 45 | 49 | ||
| 46 | QScriptValue XMLHttpRequestClass::getStatus() const { | 50 | ScriptValuePointer XMLHttpRequestClass::getStatus() const { |
| 47 | if (_reply) { | 51 | if (_reply) { |
| 48 | return QScriptValue(_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt()); | 52 | return _engine->newValue(_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt()); |
| 49 | } | 53 | } |
| 50 | return QScriptValue(0); | 54 | return ScriptValuePointer(0); |
| 51 | } | 55 | } |
| 52 | 56 | ||
| 53 | QString XMLHttpRequestClass::getStatusText() const { | 57 | QString XMLHttpRequestClass::getStatusText() const { |
| @@ -87,7 +91,7 @@ void XMLHttpRequestClass::requestDownloadProgress(qint64 bytesReceived, qint64 b · 33 unmodified lines | |||
| 87 | } | 91 | } |
| 88 | } | 92 | } |
| 89 | 93 | ||
| 90 | QScriptValue XMLHttpRequestClass::getAllResponseHeaders() const { | 94 | ScriptValuePointer XMLHttpRequestClass::getAllResponseHeaders() const { |
| 91 | if (_reply) { | 95 | if (_reply) { |
| 92 | QList<QNetworkReply::RawHeaderPair> headerList = _reply->rawHeaderPairs(); | 96 | QList<QNetworkReply::RawHeaderPair> headerList = _reply->rawHeaderPairs(); |
| 93 | QByteArray headers; | 97 | QByteArray headers; |
| @@ -97,16 +101,16 @@ QScriptValue XMLHttpRequestClass::getAllResponseHeaders() const { · 3 unmodified lines | |||
| 97 | headers.append(headerList[i].second); | 101 | headers.append(headerList[i].second); |
| 98 | headers.append("\n"); | 102 | headers.append("\n"); |
| 99 | } | 103 | } |
| 100 | return QString(headers.data()); | 104 | return _engine->newValue(QString(headers.data())); |
| 101 | } | 105 | } |
| 102 | return QScriptValue(""); | 106 | return _engine->newValue(""); |
| 103 | } | 107 | } |
| 104 | 108 | ||
| 105 | QScriptValue XMLHttpRequestClass::getResponseHeader(const QString& name) const { | 109 | ScriptValuePointer XMLHttpRequestClass::getResponseHeader(const QString& name) const { |
| 106 | if (_reply && _reply->hasRawHeader(name.toLatin1())) { | 110 | if (_reply && _reply->hasRawHeader(name.toLatin1())) { |
| 107 | return QScriptValue(QString(_reply->rawHeader(name.toLatin1()))); | 111 | return _engine->newValue(QString(_reply->rawHeader(name.toLatin1()))); |
| 108 | } | 112 | } |
| 109 | return QScriptValue::NullValue; | 113 | return _engine->nullValue(); |
| 110 | } | 114 | } |
| 111 | 115 | ||
| 112 | /*@jsdoc | 116 | /*@jsdoc |
| @@ -116,8 +120,8 @@ QScriptValue XMLHttpRequestClass::getResponseHeader(const QString& name) const { · 3 unmodified lines | |||
| 116 | void XMLHttpRequestClass::setReadyState(ReadyState readyState) { | 120 | void XMLHttpRequestClass::setReadyState(ReadyState readyState) { |
| 117 | if (readyState != _readyState) { | 121 | if (readyState != _readyState) { |
| 118 | _readyState = readyState; | 122 | _readyState = readyState; |
| 119 | if (_onReadyStateChange.isFunction()) { | 123 | if (_onReadyStateChange->isFunction()) { |
| 120 | _onReadyStateChange.call(QScriptValue::NullValue); | 124 | _onReadyStateChange->call(_onReadyStateChange->engine()->nullValue()); |
| 121 | } | 125 | } |
| 122 | } | 126 | } |
| 123 | } | 127 | } |
| @@ -153,17 +157,17 @@ void XMLHttpRequestClass::open(const QString& method, const QString& url, bool a · 29 unmodified lines | |||
| 153 | } | 157 | } |
| 154 | 158 | ||
| 155 | void XMLHttpRequestClass::send() { | 159 | void XMLHttpRequestClass::send() { |
| 156 | send(QScriptValue::NullValue); | 160 | send(_engine->nullValue()); |
| 157 | } | 161 | } |
| 158 | 162 | ||
| 159 | void XMLHttpRequestClass::send(const QScriptValue& data) { | 163 | void XMLHttpRequestClass::send(const ScriptValuePointer& data) { |
| 160 | if (_readyState == OPENED && !_reply) { | 164 | if (_readyState == OPENED && !_reply) { |
| 161 | 165 | ||
| 162 | if (!data.isNull()) { | 166 | if (!data.isNull()) { |
| 163 | if (data.isObject()) { | 167 | if (data->isObject()) { |
| 164 | _sendData = qscriptvalue_cast<QByteArray>(data); | 168 | _sendData = scriptvalue_cast<QByteArray>(data); |
| 165 | } else { | 169 | } else { |
| 166 | _sendData = data.toString().toUtf8(); | 170 | _sendData = data->toString().toUtf8(); |
| 167 | } | 171 | } |
| 168 | } | 172 | } |
| 169 | 173 | ||
| @@ -193,8 +197,8 @@ void XMLHttpRequestClass::doSend() { · 23 unmodified lines | |||
| 193 | * @callback XMLHttpRequest~onTimeoutCallback | 197 | * @callback XMLHttpRequest~onTimeoutCallback |
| 194 | */ | 198 | */ |
| 195 | void XMLHttpRequestClass::requestTimeout() { | 199 | void XMLHttpRequestClass::requestTimeout() { |
| 196 | if (_onTimeout.isFunction()) { | 200 | if (_onTimeout->isFunction()) { |
| 197 | _onTimeout.call(QScriptValue::NullValue); | 201 | _onTimeout->call(_engine->nullValue()); |
| 198 | } | 202 | } |
| 199 | abortRequest(); | 203 | abortRequest(); |
| 200 | _errorCode = QNetworkReply::TimeoutError; | 204 | _errorCode = QNetworkReply::TimeoutError; |
| @@ -215,15 +219,14 @@ void XMLHttpRequestClass::requestFinished() { · 14 unmodified lines | |||
| 215 | 219 | ||
| 216 | if (_responseType == "json") { | 220 | if (_responseType == "json") { |
| 217 | _responseData = _engine->evaluate("(" + QString(_rawResponseData.data()) + ")"); | 221 | _responseData = _engine->evaluate("(" + QString(_rawResponseData.data()) + ")"); |
| 218 | if (_responseData.isError()) { | 222 | if (_responseData->isError()) { |
| 219 | _engine->clearExceptions(); | 223 | _engine->clearExceptions(); |
| 220 | _responseData = QScriptValue::NullValue; | 224 | _responseData = _engine->nullValue(); |
| 221 | } | 225 | } |
| 222 | } else if (_responseType == "arraybuffer") { | 226 | } else if (_responseType == "arraybuffer") { |
| 223 | QScriptValue data = _engine->newVariant(QVariant::fromValue(_rawResponseData)); | 227 | _responseData = _engine->newArrayBuffer(_rawResponseData); |
| 224 | _responseData = _engine->newObject(reinterpret_cast<ScriptEngine*>(_engine)->getArrayBufferClass(), data); | ||
| 225 | } else { | 228 | } else { |
| 226 | _responseData = QScriptValue(QString(_rawResponseData.data())); | 229 | _responseData = _engine->newValue(QString(_rawResponseData.data())); |
| 227 | } | 230 | } |
| 228 | } | 231 | } |
| 229 | 232 | ||