Skip to content

Commit cfa466c

Browse files
committed
Extend usage of ES6 arrow functions and default params. NFC
See #11984
1 parent 1934a98 commit cfa466c

23 files changed

+180
-213
lines changed

src/Fetch.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var Fetch = {
2828
var openRequest = indexedDB.open(dbname, dbversion);
2929
} catch (e) { return onerror(e); }
3030

31-
openRequest.onupgradeneeded = function(event) {
31+
openRequest.onupgradeneeded = (event) => {
3232
#if FETCH_DEBUG
3333
console.log('fetch: IndexedDB upgrade needed. Clearing database.');
3434
#endif
@@ -38,16 +38,16 @@ var Fetch = {
3838
}
3939
db.createObjectStore('FILES');
4040
};
41-
openRequest.onsuccess = function(event) { onsuccess(event.target.result); };
42-
openRequest.onerror = function(error) { onerror(error); };
41+
openRequest.onsuccess = (event) => onsuccess(event.target.result);
42+
openRequest.onerror = (error) => onerror(error);
4343
},
4444
#endif
4545

4646
staticInit: function() {
4747
var isMainThread = true;
4848

4949
#if FETCH_SUPPORT_INDEXEDDB
50-
var onsuccess = function(db) {
50+
var onsuccess = (db) => {
5151
#if FETCH_DEBUG
5252
console.log('fetch: IndexedDB successfully opened.');
5353
#endif
@@ -57,7 +57,7 @@ var Fetch = {
5757
removeRunDependency('library_fetch_init');
5858
}
5959
};
60-
var onerror = function() {
60+
var onerror = () => {
6161
#if FETCH_DEBUG
6262
console.error('fetch: IndexedDB open failed.');
6363
#endif
@@ -95,7 +95,7 @@ function fetchDeleteCachedData(db, fetch, onsuccess, onerror) {
9595
var transaction = db.transaction(['FILES'], 'readwrite');
9696
var packages = transaction.objectStore('FILES');
9797
var request = packages.delete(pathStr);
98-
request.onsuccess = function(event) {
98+
request.onsuccess = (event) => {
9999
var value = event.target.result;
100100
#if FETCH_DEBUG
101101
console.log('fetch: Deleted file ' + pathStr + ' from IndexedDB');
@@ -109,7 +109,7 @@ function fetchDeleteCachedData(db, fetch, onsuccess, onerror) {
109109
stringToUTF8("OK", fetch + {{{ C_STRUCTS.emscripten_fetch_t.statusText }}}, 64);
110110
onsuccess(fetch, 0, value);
111111
};
112-
request.onerror = function(error) {
112+
request.onerror = (error) => {
113113
#if FETCH_DEBUG
114114
console.error('fetch: Failed to delete file ' + pathStr + ' from IndexedDB! error: ' + error);
115115
#endif
@@ -144,7 +144,7 @@ function fetchLoadCachedData(db, fetch, onsuccess, onerror) {
144144
var transaction = db.transaction(['FILES'], 'readonly');
145145
var packages = transaction.objectStore('FILES');
146146
var getRequest = packages.get(pathStr);
147-
getRequest.onsuccess = function(event) {
147+
getRequest.onsuccess = (event) => {
148148
if (event.target.result) {
149149
var value = event.target.result;
150150
var len = value.byteLength || value.length;
@@ -174,7 +174,7 @@ function fetchLoadCachedData(db, fetch, onsuccess, onerror) {
174174
onerror(fetch, 0, 'no data');
175175
}
176176
};
177-
getRequest.onerror = function(error) {
177+
getRequest.onerror = (error) => {
178178
#if FETCH_DEBUG
179179
console.error('fetch: Failed to load file ' + pathStr + ' from IndexedDB!');
180180
#endif
@@ -209,7 +209,7 @@ function fetchCacheData(db, fetch, data, onsuccess, onerror) {
209209
var transaction = db.transaction(['FILES'], 'readwrite');
210210
var packages = transaction.objectStore('FILES');
211211
var putRequest = packages.put(data, destinationPathStr);
212-
putRequest.onsuccess = function(event) {
212+
putRequest.onsuccess = (event) => {
213213
#if FETCH_DEBUG
214214
console.log('fetch: Stored file "' + destinationPathStr + '" to IndexedDB cache.');
215215
#endif
@@ -218,7 +218,7 @@ function fetchCacheData(db, fetch, data, onsuccess, onerror) {
218218
stringToUTF8("OK", fetch + {{{ C_STRUCTS.emscripten_fetch_t.statusText }}}, 64);
219219
onsuccess(fetch, 0, destinationPathStr);
220220
};
221-
putRequest.onerror = function(error) {
221+
putRequest.onerror = (error) => {
222222
#if FETCH_DEBUG
223223
console.error('fetch: Failed to store file "' + destinationPathStr + '" to IndexedDB cache!');
224224
#endif
@@ -341,7 +341,7 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
341341
Fetch.setu64(fetch + {{{ C_STRUCTS.emscripten_fetch_t.numBytes }}}, ptrLen);
342342
}
343343

344-
xhr.onload = function(e) {
344+
xhr.onload = (e) => {
345345
saveResponse(fetchAttrLoadToMemory && !fetchAttrStreamData);
346346
var len = xhr.response ? xhr.response.byteLength : 0;
347347
Fetch.setu64(fetch + {{{ C_STRUCTS.emscripten_fetch_t.dataOffset }}}, 0);
@@ -366,7 +366,7 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
366366
if (onerror) onerror(fetch, xhr, e);
367367
}
368368
};
369-
xhr.onerror = function(e) {
369+
xhr.onerror = (e) => {
370370
saveResponse(fetchAttrLoadToMemory);
371371
var status = xhr.status; // XXX TODO: Overwriting xhr.status doesn't work here, so don't override anywhere else either.
372372
#if FETCH_DEBUG
@@ -378,13 +378,13 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
378378
HEAPU16[fetch + {{{ C_STRUCTS.emscripten_fetch_t.status }}} >> 1] = status;
379379
if (onerror) onerror(fetch, xhr, e);
380380
};
381-
xhr.ontimeout = function(e) {
381+
xhr.ontimeout = (e) => {
382382
#if FETCH_DEBUG
383383
console.error('fetch: xhr of URL "' + xhr.url_ + '" / responseURL "' + xhr.responseURL + '" timed out, readyState ' + xhr.readyState + ' and status ' + xhr.status);
384384
#endif
385385
if (onerror) onerror(fetch, xhr, e);
386386
};
387-
xhr.onprogress = function(e) {
387+
xhr.onprogress = (e) => {
388388
var ptrLen = (fetchAttrLoadToMemory && fetchAttrStreamData && xhr.response) ? xhr.response.byteLength : 0;
389389
var ptr = 0;
390390
if (fetchAttrLoadToMemory && fetchAttrStreamData) {
@@ -411,7 +411,7 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
411411
_free(ptr);
412412
}
413413
};
414-
xhr.onreadystatechange = function(e) {
414+
xhr.onreadystatechange = (e) => {
415415
HEAPU16[fetch + {{{ C_STRUCTS.emscripten_fetch_t.readyState }}} >> 1] = xhr.readyState;
416416
if (xhr.readyState >= 2) {
417417
HEAPU16[fetch + {{{ C_STRUCTS.emscripten_fetch_t.status }}} >> 1] = xhr.status;
@@ -453,7 +453,7 @@ function startFetch(fetch, successcb, errorcb, progresscb, readystatechangecb) {
453453
var fetchAttrReplace = !!(fetchAttributes & {{{ cDefine('EMSCRIPTEN_FETCH_REPLACE') }}});
454454
var fetchAttrSynchronous = !!(fetchAttributes & {{{ cDefine('EMSCRIPTEN_FETCH_SYNCHRONOUS') }}});
455455

456-
var reportSuccess = function(fetch, xhr, e) {
456+
var reportSuccess = (fetch, xhr, e) => {
457457
#if FETCH_DEBUG
458458
console.log('fetch: operation success. e: ' + e);
459459
#endif
@@ -464,14 +464,14 @@ function startFetch(fetch, successcb, errorcb, progresscb, readystatechangecb) {
464464
}, fetchAttrSynchronous);
465465
};
466466

467-
var reportProgress = function(fetch, xhr, e) {
467+
var reportProgress = (fetch, xhr, e) => {
468468
callUserCallback(function() {
469469
if (onprogress) {{{ makeDynCall('vi', 'onprogress') }}}(fetch);
470470
else if (progresscb) progresscb(fetch);
471471
}, fetchAttrSynchronous);
472472
};
473473

474-
var reportError = function(fetch, xhr, e) {
474+
var reportError = (fetch, xhr, e) => {
475475
#if FETCH_DEBUG
476476
console.error('fetch: operation failed: ' + e);
477477
#endif
@@ -482,7 +482,7 @@ function startFetch(fetch, successcb, errorcb, progresscb, readystatechangecb) {
482482
}, fetchAttrSynchronous);
483483
};
484484

485-
var reportReadyStateChange = function(fetch, xhr, e) {
485+
var reportReadyStateChange = (fetch, xhr, e) => {
486486
#if FETCH_DEBUG
487487
console.log('fetch: ready state change. e: ' + e);
488488
#endif
@@ -492,19 +492,19 @@ function startFetch(fetch, successcb, errorcb, progresscb, readystatechangecb) {
492492
}, fetchAttrSynchronous);
493493
};
494494

495-
var performUncachedXhr = function(fetch, xhr, e) {
495+
var performUncachedXhr = (fetch, xhr, e) => {
496496
#if FETCH_DEBUG
497497
console.error('fetch: starting (uncached) XHR: ' + e);
498498
#endif
499499
fetchXHR(fetch, reportSuccess, reportError, reportProgress, reportReadyStateChange);
500500
};
501501

502502
#if FETCH_SUPPORT_INDEXEDDB
503-
var cacheResultAndReportSuccess = function(fetch, xhr, e) {
503+
var cacheResultAndReportSuccess = (fetch, xhr, e) => {
504504
#if FETCH_DEBUG
505505
console.log('fetch: operation success. Caching result.. e: ' + e);
506506
#endif
507-
var storeSuccess = function(fetch, xhr, e) {
507+
var storeSuccess = (fetch, xhr, e) => {
508508
#if FETCH_DEBUG
509509
console.log('fetch: IndexedDB store succeeded.');
510510
#endif
@@ -514,7 +514,7 @@ function startFetch(fetch, successcb, errorcb, progresscb, readystatechangecb) {
514514
else if (successcb) successcb(fetch);
515515
}, fetchAttrSynchronous);
516516
};
517-
var storeError = function(fetch, xhr, e) {
517+
var storeError = (fetch, xhr, e) => {
518518
#if FETCH_DEBUG
519519
console.error('fetch: IndexedDB store failed.');
520520
#endif
@@ -527,7 +527,7 @@ function startFetch(fetch, successcb, errorcb, progresscb, readystatechangecb) {
527527
fetchCacheData(Fetch.dbInstance, fetch, xhr.response, storeSuccess, storeError);
528528
};
529529

530-
var performCachedXhr = function(fetch, xhr, e) {
530+
var performCachedXhr = (fetch, xhr, e) => {
531531
#if FETCH_DEBUG
532532
console.error('fetch: starting (cached) XHR: ' + e);
533533
#endif

0 commit comments

Comments
 (0)