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
1=== modified file 'rockworkd/libpebble/jskit/jskitxmlhttprequest.cpp'
2--- rockworkd/libpebble/jskit/jskitxmlhttprequest.cpp 2016-01-17 05:55:21 +0000
3+++ rockworkd/libpebble/jskit/jskitxmlhttprequest.cpp 2016-02-08 06:49:39 +0000
4@@ -1,5 +1,6 @@
5 #include <QBuffer>
6 #include <QAuthenticator>
7+#include <QEventLoop>
8
9 #include "jskitxmlhttprequest.h"
10 #include "jskitmanager.h"
11@@ -27,9 +28,9 @@
12 m_password = password;
13 m_request = QNetworkRequest(QUrl(url));
14 m_verb = method;
15- Q_UNUSED(async);
16+ m_async = async;
17
18- qCDebug(l) << "opened to URL" << m_request.url().toString();
19+ qCDebug(l) << "opened to URL" << m_request.url().toString() << "Async:" << async;
20 }
21
22 void JSKitXMLHttpRequest::setRequestHeader(const QString &header, const QString &value)
23@@ -95,6 +96,17 @@
24 // So that it gets deleted alongside the reply object.
25 buffer->setParent(m_reply);
26 }
27+
28+ if (!m_async) {
29+ QEventLoop loop; //Hacky way to get QNetworkReply be synchronous
30+
31+ connect(m_reply, &QNetworkReply::finished,
32+ &loop, &QEventLoop::quit);
33+ connect(m_reply, static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error),
34+ &loop, &QEventLoop::quit);
35+
36+ loop.exec();
37+ }
38 }
39
40 void JSKitXMLHttpRequest::abort()
41@@ -229,7 +241,7 @@
42 }
43
44 m_response = m_reply->readAll();
45- qCDebug(l) << "reply finished, reply text:" << QString::fromUtf8(m_response);
46+ qCDebug(l) << "reply finished, reply text:" << QString::fromUtf8(m_response) << "status:" << status();
47
48 emit readyStateChanged();
49 emit statusChanged();
50
51=== modified file 'rockworkd/libpebble/jskit/jskitxmlhttprequest.h'
52--- rockworkd/libpebble/jskit/jskitxmlhttprequest.h 2016-01-17 05:55:21 +0000
53+++ rockworkd/libpebble/jskit/jskitxmlhttprequest.h 2016-02-08 06:49:39 +0000
54@@ -34,7 +34,7 @@
55 };
56 Q_ENUMS(ReadyStates)
57
58- Q_INVOKABLE void open(const QString &method, const QString &url, bool async = false, const QString &username = QString(), const QString &password = QString());
59+ Q_INVOKABLE void open(const QString &method, const QString &url, bool async = true, const QString &username = QString(), const QString &password = QString());
60 Q_INVOKABLE void setRequestHeader(const QString &header, const QString &value);
61 Q_INVOKABLE void send(const QJSValue &data = QJSValue(QJSValue::NullValue));
62 Q_INVOKABLE void abort();
63@@ -76,6 +76,7 @@
64 QJSEngine *m_engine;
65 QNetworkAccessManager *m_net;
66 QString m_verb;
67+ bool m_async = true;
68 uint m_timeout;
69 QString m_username;
70 QString m_password;
71
72=== modified file 'rockworkd/libpebble/jskit/typedarray.js'
73--- rockworkd/libpebble/jskit/typedarray.js 2016-02-06 04:27:09 +0000
74+++ rockworkd/libpebble/jskit/typedarray.js 2016-02-08 06:49:39 +0000
75@@ -61,7 +61,7 @@
76 return Object(v);
77 }
78 function ToInt32(v) { return v >> 0; }
79- function ToUint32(v) { return v >>> 0; }
80+ 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)
81
82 // Snapshot intrinsics
83 var LN2 = Math.LN2,
84@@ -135,23 +135,21 @@
85
86 function packU8Clamped(n) { n = round(Number(n)); return [n < 0 ? 0 : n > 0xff ? 0xff : n & 0xff]; }
87
88- function packI16(n) { return [(n >> 8) & 0xff, n & 0xff]; }
89- function unpackI16(bytes) { return as_signed(bytes[0] << 8 | bytes[1], 16); }
90-
91- function packU16(n) { return [(n >> 8) & 0xff, n & 0xff]; }
92- function unpackU16(bytes) { return as_unsigned(bytes[0] << 8 | bytes[1], 16); }
93-
94- function packI32(n) { return [(n >> 24) & 0xff, (n >> 16) & 0xff, (n >> 8) & 0xff, n & 0xff]; }
95- function unpackI32(bytes) { return as_signed(bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3], 32); }
96-
97- function packU32(n) { return [(n >> 24) & 0xff, (n >> 16) & 0xff, (n >> 8) & 0xff, n & 0xff]; }
98- function unpackU32(bytes) { return as_unsigned(bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3], 32); }
99+ function packI16(n) { return [n & 0xff, (n >> 8) & 0xff]; }
100+ function unpackI16(bytes) { return as_signed(bytes[1] << 8 | bytes[0], 16); }
101+
102+ function packU16(n) { return [n & 0xff, (n >> 8) & 0xff]; }
103+ function unpackU16(bytes) { return as_unsigned(bytes[1] << 8 | bytes[0], 16); }
104+
105+ function packI32(n) { return [n & 0xff, (n >> 8) & 0xff, (n >> 16) & 0xff, (n >> 24) & 0xff]; }
106+ function unpackI32(bytes) { return as_signed(bytes[3] << 24 | bytes[2] << 16 | bytes[1] << 8 | bytes[0], 32); }
107+
108+ function packU32(n) { return [n & 0xff, (n >> 8) & 0xff, (n >> 16) & 0xff, (n >> 24) & 0xff]; }
109+ function unpackU32(bytes) { return as_unsigned(bytes[3] << 24 | bytes[2] << 16 | bytes[1] << 8 | bytes[0], 32); }
110
111 function packIEEE754(v, ebits, fbits) {
112
113- var bias = (1 << (ebits - 1)) - 1,
114- s, e, f, ln,
115- i, bits, str, bytes;
116+ var bias = (1 << (ebits - 1)) - 1;
117
118 function roundToEven(n) {
119 var w = floor(n), f = n - w;
120@@ -163,6 +161,7 @@
121 }
122
123 // Compute sign, exponent, fraction
124+ var s, e, f;
125 if (v !== v) {
126 // NaN
127 // http://dev.w3.org/2006/webapi/WebIDL/#es-type-mapping
128@@ -176,20 +175,28 @@
129 v = abs(v);
130
131 if (v >= pow(2, 1 - bias)) {
132+ // Normalized
133 e = min(floor(log(v) / LN2), 1023);
134- f = roundToEven(v / pow(2, e) * pow(2, fbits));
135- if (f / pow(2, fbits) >= 2) {
136- e = e + 1;
137- f = 1;
138- }
139- if (e > bias) {
140+ var significand = v / pow(2, e);
141+ if (significand < 1) {
142+ e -= 1;
143+ significand *= 2;
144+ }
145+ if (significand >= 2) {
146+ e += 1;
147+ significand /= 2;
148+ }
149+ var d = pow(2, fbits);
150+ f = roundToEven(significand * d) - d;
151+ e += bias;
152+ if (f / d >= 1) {
153+ e += 1;
154+ f = 0;
155+ }
156+ if (e > 2 * bias) {
157 // Overflow
158 e = (1 << ebits) - 1;
159 f = 0;
160- } else {
161- // Normalized
162- e = e + bias;
163- f = f - pow(2, fbits);
164 }
165 } else {
166 // Denormalized
167@@ -199,17 +206,17 @@
168 }
169
170 // Pack sign, exponent, fraction
171- bits = [];
172+ var bits = [], i;
173 for (i = fbits; i; i -= 1) { bits.push(f % 2 ? 1 : 0); f = floor(f / 2); }
174 for (i = ebits; i; i -= 1) { bits.push(e % 2 ? 1 : 0); e = floor(e / 2); }
175 bits.push(s ? 1 : 0);
176 bits.reverse();
177- str = bits.join('');
178+ var str = bits.join('');
179
180 // Bits to bytes
181- bytes = [];
182+ var bytes = [];
183 while (str.length) {
184- bytes.push(parseInt(str.substring(0, 8), 2));
185+ bytes.unshift(parseInt(str.substring(0, 8), 2));
186 str = str.substring(8);
187 }
188 return bytes;
189@@ -220,8 +227,8 @@
190 var bits = [], i, j, b, str,
191 bias, s, e, f;
192
193- for (i = bytes.length; i; i -= 1) {
194- b = bytes[i - 1];
195+ for (i = 0; i < bytes.length; ++i) {
196+ b = bytes[i];
197 for (j = 8; j; j -= 1) {
198 bits.push(b % 2 ? 1 : 0); b = b >> 1;
199 }

Subscribers

People subscribed via source and target branches