Merge lp:~bhdouglass/rockwork/xmlhttprequest-fixes into lp:rockwork

Proposed by Brian Douglass
Status: Merged
Merged at revision: 73
Proposed branch: lp:~bhdouglass/rockwork/xmlhttprequest-fixes
Merge into: lp:rockwork
Diff against target: 199 lines (+55/-35)
3 files modified
rockworkd/libpebble/jskit/jskitxmlhttprequest.cpp (+15/-3)
rockworkd/libpebble/jskit/jskitxmlhttprequest.h (+2/-1)
rockworkd/libpebble/jskit/typedarray.js (+38/-31)
To merge this branch: bzr merge lp:~bhdouglass/rockwork/xmlhttprequest-fixes
Reviewer Review Type Date Requested Status
Michael Zanetti Pending
Review via email: mp+285303@code.launchpad.net

Description of the change

Fixes issues in the JSKit's XMLHttpRequest object and addes synchronous request support.
This fixes the Evernote and Huebble (and possibly the Rockodi app, but it was untested).

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'rockworkd/libpebble/jskit/jskitxmlhttprequest.cpp'
--- rockworkd/libpebble/jskit/jskitxmlhttprequest.cpp 2016-01-17 05:55:21 +0000
+++ rockworkd/libpebble/jskit/jskitxmlhttprequest.cpp 2016-02-08 06:49:39 +0000
@@ -1,5 +1,6 @@
1#include <QBuffer>1#include <QBuffer>
2#include <QAuthenticator>2#include <QAuthenticator>
3#include <QEventLoop>
34
4#include "jskitxmlhttprequest.h"5#include "jskitxmlhttprequest.h"
5#include "jskitmanager.h"6#include "jskitmanager.h"
@@ -27,9 +28,9 @@
27 m_password = password;28 m_password = password;
28 m_request = QNetworkRequest(QUrl(url));29 m_request = QNetworkRequest(QUrl(url));
29 m_verb = method;30 m_verb = method;
30 Q_UNUSED(async);31 m_async = async;
3132
32 qCDebug(l) << "opened to URL" << m_request.url().toString();33 qCDebug(l) << "opened to URL" << m_request.url().toString() << "Async:" << async;
33}34}
3435
35void JSKitXMLHttpRequest::setRequestHeader(const QString &header, const QString &value)36void JSKitXMLHttpRequest::setRequestHeader(const QString &header, const QString &value)
@@ -95,6 +96,17 @@
95 // So that it gets deleted alongside the reply object.96 // So that it gets deleted alongside the reply object.
96 buffer->setParent(m_reply);97 buffer->setParent(m_reply);
97 }98 }
99
100 if (!m_async) {
101 QEventLoop loop; //Hacky way to get QNetworkReply be synchronous
102
103 connect(m_reply, &QNetworkReply::finished,
104 &loop, &QEventLoop::quit);
105 connect(m_reply, static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error),
106 &loop, &QEventLoop::quit);
107
108 loop.exec();
109 }
98}110}
99111
100void JSKitXMLHttpRequest::abort()112void JSKitXMLHttpRequest::abort()
@@ -229,7 +241,7 @@
229 }241 }
230242
231 m_response = m_reply->readAll();243 m_response = m_reply->readAll();
232 qCDebug(l) << "reply finished, reply text:" << QString::fromUtf8(m_response);244 qCDebug(l) << "reply finished, reply text:" << QString::fromUtf8(m_response) << "status:" << status();
233245
234 emit readyStateChanged();246 emit readyStateChanged();
235 emit statusChanged();247 emit statusChanged();
236248
=== modified file 'rockworkd/libpebble/jskit/jskitxmlhttprequest.h'
--- rockworkd/libpebble/jskit/jskitxmlhttprequest.h 2016-01-17 05:55:21 +0000
+++ rockworkd/libpebble/jskit/jskitxmlhttprequest.h 2016-02-08 06:49:39 +0000
@@ -34,7 +34,7 @@
34 };34 };
35 Q_ENUMS(ReadyStates)35 Q_ENUMS(ReadyStates)
3636
37 Q_INVOKABLE void open(const QString &method, const QString &url, bool async = false, const QString &username = QString(), const QString &password = QString());37 Q_INVOKABLE void open(const QString &method, const QString &url, bool async = true, const QString &username = QString(), const QString &password = QString());
38 Q_INVOKABLE void setRequestHeader(const QString &header, const QString &value);38 Q_INVOKABLE void setRequestHeader(const QString &header, const QString &value);
39 Q_INVOKABLE void send(const QJSValue &data = QJSValue(QJSValue::NullValue));39 Q_INVOKABLE void send(const QJSValue &data = QJSValue(QJSValue::NullValue));
40 Q_INVOKABLE void abort();40 Q_INVOKABLE void abort();
@@ -76,6 +76,7 @@
76 QJSEngine *m_engine;76 QJSEngine *m_engine;
77 QNetworkAccessManager *m_net;77 QNetworkAccessManager *m_net;
78 QString m_verb;78 QString m_verb;
79 bool m_async = true;
79 uint m_timeout;80 uint m_timeout;
80 QString m_username;81 QString m_username;
81 QString m_password;82 QString m_password;
8283
=== modified file 'rockworkd/libpebble/jskit/typedarray.js'
--- rockworkd/libpebble/jskit/typedarray.js 2016-02-06 04:27:09 +0000
+++ rockworkd/libpebble/jskit/typedarray.js 2016-02-08 06:49:39 +0000
@@ -61,7 +61,7 @@
61 return Object(v);61 return Object(v);
62 }62 }
63 function ToInt32(v) { return v >> 0; }63 function ToInt32(v) { return v >> 0; }
64 function ToUint32(v) { return v >>> 0; }64 function ToUint32(v) { return v >> 0; } //ROCKWORK HACK ALERT: it appears that QT doesn't do the >>> properly, using >> here instead (should be close enough)
6565
66 // Snapshot intrinsics66 // Snapshot intrinsics
67 var LN2 = Math.LN2,67 var LN2 = Math.LN2,
@@ -135,23 +135,21 @@
135135
136 function packU8Clamped(n) { n = round(Number(n)); return [n < 0 ? 0 : n > 0xff ? 0xff : n & 0xff]; }136 function packU8Clamped(n) { n = round(Number(n)); return [n < 0 ? 0 : n > 0xff ? 0xff : n & 0xff]; }
137137
138 function packI16(n) { return [(n >> 8) & 0xff, n & 0xff]; }138 function packI16(n) { return [n & 0xff, (n >> 8) & 0xff]; }
139 function unpackI16(bytes) { return as_signed(bytes[0] << 8 | bytes[1], 16); }139 function unpackI16(bytes) { return as_signed(bytes[1] << 8 | bytes[0], 16); }
140140
141 function packU16(n) { return [(n >> 8) & 0xff, n & 0xff]; }141 function packU16(n) { return [n & 0xff, (n >> 8) & 0xff]; }
142 function unpackU16(bytes) { return as_unsigned(bytes[0] << 8 | bytes[1], 16); }142 function unpackU16(bytes) { return as_unsigned(bytes[1] << 8 | bytes[0], 16); }
143143
144 function packI32(n) { return [(n >> 24) & 0xff, (n >> 16) & 0xff, (n >> 8) & 0xff, n & 0xff]; }144 function packI32(n) { return [n & 0xff, (n >> 8) & 0xff, (n >> 16) & 0xff, (n >> 24) & 0xff]; }
145 function unpackI32(bytes) { return as_signed(bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3], 32); }145 function unpackI32(bytes) { return as_signed(bytes[3] << 24 | bytes[2] << 16 | bytes[1] << 8 | bytes[0], 32); }
146146
147 function packU32(n) { return [(n >> 24) & 0xff, (n >> 16) & 0xff, (n >> 8) & 0xff, n & 0xff]; }147 function packU32(n) { return [n & 0xff, (n >> 8) & 0xff, (n >> 16) & 0xff, (n >> 24) & 0xff]; }
148 function unpackU32(bytes) { return as_unsigned(bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3], 32); }148 function unpackU32(bytes) { return as_unsigned(bytes[3] << 24 | bytes[2] << 16 | bytes[1] << 8 | bytes[0], 32); }
149149
150 function packIEEE754(v, ebits, fbits) {150 function packIEEE754(v, ebits, fbits) {
151151
152 var bias = (1 << (ebits - 1)) - 1,152 var bias = (1 << (ebits - 1)) - 1;
153 s, e, f, ln,
154 i, bits, str, bytes;
155153
156 function roundToEven(n) {154 function roundToEven(n) {
157 var w = floor(n), f = n - w;155 var w = floor(n), f = n - w;
@@ -163,6 +161,7 @@
163 }161 }
164162
165 // Compute sign, exponent, fraction163 // Compute sign, exponent, fraction
164 var s, e, f;
166 if (v !== v) {165 if (v !== v) {
167 // NaN166 // NaN
168 // http://dev.w3.org/2006/webapi/WebIDL/#es-type-mapping167 // http://dev.w3.org/2006/webapi/WebIDL/#es-type-mapping
@@ -176,20 +175,28 @@
176 v = abs(v);175 v = abs(v);
177176
178 if (v >= pow(2, 1 - bias)) {177 if (v >= pow(2, 1 - bias)) {
178 // Normalized
179 e = min(floor(log(v) / LN2), 1023);179 e = min(floor(log(v) / LN2), 1023);
180 f = roundToEven(v / pow(2, e) * pow(2, fbits));180 var significand = v / pow(2, e);
181 if (f / pow(2, fbits) >= 2) {181 if (significand < 1) {
182 e = e + 1;182 e -= 1;
183 f = 1;183 significand *= 2;
184 }184 }
185 if (e > bias) {185 if (significand >= 2) {
186 e += 1;
187 significand /= 2;
188 }
189 var d = pow(2, fbits);
190 f = roundToEven(significand * d) - d;
191 e += bias;
192 if (f / d >= 1) {
193 e += 1;
194 f = 0;
195 }
196 if (e > 2 * bias) {
186 // Overflow197 // Overflow
187 e = (1 << ebits) - 1;198 e = (1 << ebits) - 1;
188 f = 0;199 f = 0;
189 } else {
190 // Normalized
191 e = e + bias;
192 f = f - pow(2, fbits);
193 }200 }
194 } else {201 } else {
195 // Denormalized202 // Denormalized
@@ -199,17 +206,17 @@
199 }206 }
200207
201 // Pack sign, exponent, fraction208 // Pack sign, exponent, fraction
202 bits = [];209 var bits = [], i;
203 for (i = fbits; i; i -= 1) { bits.push(f % 2 ? 1 : 0); f = floor(f / 2); }210 for (i = fbits; i; i -= 1) { bits.push(f % 2 ? 1 : 0); f = floor(f / 2); }
204 for (i = ebits; i; i -= 1) { bits.push(e % 2 ? 1 : 0); e = floor(e / 2); }211 for (i = ebits; i; i -= 1) { bits.push(e % 2 ? 1 : 0); e = floor(e / 2); }
205 bits.push(s ? 1 : 0);212 bits.push(s ? 1 : 0);
206 bits.reverse();213 bits.reverse();
207 str = bits.join('');214 var str = bits.join('');
208215
209 // Bits to bytes216 // Bits to bytes
210 bytes = [];217 var bytes = [];
211 while (str.length) {218 while (str.length) {
212 bytes.push(parseInt(str.substring(0, 8), 2));219 bytes.unshift(parseInt(str.substring(0, 8), 2));
213 str = str.substring(8);220 str = str.substring(8);
214 }221 }
215 return bytes;222 return bytes;
@@ -220,8 +227,8 @@
220 var bits = [], i, j, b, str,227 var bits = [], i, j, b, str,
221 bias, s, e, f;228 bias, s, e, f;
222229
223 for (i = bytes.length; i; i -= 1) {230 for (i = 0; i < bytes.length; ++i) {
224 b = bytes[i - 1];231 b = bytes[i];
225 for (j = 8; j; j -= 1) {232 for (j = 8; j; j -= 1) {
226 bits.push(b % 2 ? 1 : 0); b = b >> 1;233 bits.push(b % 2 ? 1 : 0); b = b >> 1;
227 }234 }

Subscribers

People subscribed via source and target branches