Skip to content

Commit

Permalink
Extend usage of ES6 arrow functions and default params. NFC (#15758)
Browse files Browse the repository at this point in the history
See #11984
  • Loading branch information
sbc100 authored Jan 8, 2022
1 parent df9c7d7 commit c0f1058
Show file tree
Hide file tree
Showing 50 changed files with 207 additions and 240 deletions.
50 changes: 25 additions & 25 deletions src/Fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var Fetch = {
var openRequest = indexedDB.open(dbname, dbversion);
} catch (e) { return onerror(e); }

openRequest.onupgradeneeded = function(event) {
openRequest.onupgradeneeded = (event) => {
#if FETCH_DEBUG
console.log('fetch: IndexedDB upgrade needed. Clearing database.');
#endif
Expand All @@ -38,16 +38,16 @@ var Fetch = {
}
db.createObjectStore('FILES');
};
openRequest.onsuccess = function(event) { onsuccess(event.target.result); };
openRequest.onerror = function(error) { onerror(error); };
openRequest.onsuccess = (event) => onsuccess(event.target.result);
openRequest.onerror = (error) => onerror(error);
},
#endif

staticInit: function() {
var isMainThread = true;

#if FETCH_SUPPORT_INDEXEDDB
var onsuccess = function(db) {
var onsuccess = (db) => {
#if FETCH_DEBUG
console.log('fetch: IndexedDB successfully opened.');
#endif
Expand All @@ -57,7 +57,7 @@ var Fetch = {
removeRunDependency('library_fetch_init');
}
};
var onerror = function() {
var onerror = () => {
#if FETCH_DEBUG
console.error('fetch: IndexedDB open failed.');
#endif
Expand Down Expand Up @@ -95,7 +95,7 @@ function fetchDeleteCachedData(db, fetch, onsuccess, onerror) {
var transaction = db.transaction(['FILES'], 'readwrite');
var packages = transaction.objectStore('FILES');
var request = packages.delete(pathStr);
request.onsuccess = function(event) {
request.onsuccess = (event) => {
var value = event.target.result;
#if FETCH_DEBUG
console.log('fetch: Deleted file ' + pathStr + ' from IndexedDB');
Expand All @@ -109,7 +109,7 @@ function fetchDeleteCachedData(db, fetch, onsuccess, onerror) {
stringToUTF8("OK", fetch + {{{ C_STRUCTS.emscripten_fetch_t.statusText }}}, 64);
onsuccess(fetch, 0, value);
};
request.onerror = function(error) {
request.onerror = (error) => {
#if FETCH_DEBUG
console.error('fetch: Failed to delete file ' + pathStr + ' from IndexedDB! error: ' + error);
#endif
Expand Down Expand Up @@ -144,7 +144,7 @@ function fetchLoadCachedData(db, fetch, onsuccess, onerror) {
var transaction = db.transaction(['FILES'], 'readonly');
var packages = transaction.objectStore('FILES');
var getRequest = packages.get(pathStr);
getRequest.onsuccess = function(event) {
getRequest.onsuccess = (event) => {
if (event.target.result) {
var value = event.target.result;
var len = value.byteLength || value.length;
Expand Down Expand Up @@ -174,7 +174,7 @@ function fetchLoadCachedData(db, fetch, onsuccess, onerror) {
onerror(fetch, 0, 'no data');
}
};
getRequest.onerror = function(error) {
getRequest.onerror = (error) => {
#if FETCH_DEBUG
console.error('fetch: Failed to load file ' + pathStr + ' from IndexedDB!');
#endif
Expand Down Expand Up @@ -209,7 +209,7 @@ function fetchCacheData(db, fetch, data, onsuccess, onerror) {
var transaction = db.transaction(['FILES'], 'readwrite');
var packages = transaction.objectStore('FILES');
var putRequest = packages.put(data, destinationPathStr);
putRequest.onsuccess = function(event) {
putRequest.onsuccess = (event) => {
#if FETCH_DEBUG
console.log('fetch: Stored file "' + destinationPathStr + '" to IndexedDB cache.');
#endif
Expand All @@ -218,7 +218,7 @@ function fetchCacheData(db, fetch, data, onsuccess, onerror) {
stringToUTF8("OK", fetch + {{{ C_STRUCTS.emscripten_fetch_t.statusText }}}, 64);
onsuccess(fetch, 0, destinationPathStr);
};
putRequest.onerror = function(error) {
putRequest.onerror = (error) => {
#if FETCH_DEBUG
console.error('fetch: Failed to store file "' + destinationPathStr + '" to IndexedDB cache!');
#endif
Expand Down Expand Up @@ -341,7 +341,7 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
Fetch.setu64(fetch + {{{ C_STRUCTS.emscripten_fetch_t.numBytes }}}, ptrLen);
}

xhr.onload = function(e) {
xhr.onload = (e) => {
saveResponse(fetchAttrLoadToMemory && !fetchAttrStreamData);
var len = xhr.response ? xhr.response.byteLength : 0;
Fetch.setu64(fetch + {{{ C_STRUCTS.emscripten_fetch_t.dataOffset }}}, 0);
Expand All @@ -366,7 +366,7 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
if (onerror) onerror(fetch, xhr, e);
}
};
xhr.onerror = function(e) {
xhr.onerror = (e) => {
saveResponse(fetchAttrLoadToMemory);
var status = xhr.status; // XXX TODO: Overwriting xhr.status doesn't work here, so don't override anywhere else either.
#if FETCH_DEBUG
Expand All @@ -378,13 +378,13 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
HEAPU16[fetch + {{{ C_STRUCTS.emscripten_fetch_t.status }}} >> 1] = status;
if (onerror) onerror(fetch, xhr, e);
};
xhr.ontimeout = function(e) {
xhr.ontimeout = (e) => {
#if FETCH_DEBUG
console.error('fetch: xhr of URL "' + xhr.url_ + '" / responseURL "' + xhr.responseURL + '" timed out, readyState ' + xhr.readyState + ' and status ' + xhr.status);
#endif
if (onerror) onerror(fetch, xhr, e);
};
xhr.onprogress = function(e) {
xhr.onprogress = (e) => {
var ptrLen = (fetchAttrLoadToMemory && fetchAttrStreamData && xhr.response) ? xhr.response.byteLength : 0;
var ptr = 0;
if (fetchAttrLoadToMemory && fetchAttrStreamData) {
Expand All @@ -411,7 +411,7 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
_free(ptr);
}
};
xhr.onreadystatechange = function(e) {
xhr.onreadystatechange = (e) => {
HEAPU16[fetch + {{{ C_STRUCTS.emscripten_fetch_t.readyState }}} >> 1] = xhr.readyState;
if (xhr.readyState >= 2) {
HEAPU16[fetch + {{{ C_STRUCTS.emscripten_fetch_t.status }}} >> 1] = xhr.status;
Expand Down Expand Up @@ -453,7 +453,7 @@ function startFetch(fetch, successcb, errorcb, progresscb, readystatechangecb) {
var fetchAttrReplace = !!(fetchAttributes & {{{ cDefine('EMSCRIPTEN_FETCH_REPLACE') }}});
var fetchAttrSynchronous = !!(fetchAttributes & {{{ cDefine('EMSCRIPTEN_FETCH_SYNCHRONOUS') }}});

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

var reportProgress = function(fetch, xhr, e) {
var reportProgress = (fetch, xhr, e) => {
callUserCallback(function() {
if (onprogress) {{{ makeDynCall('vi', 'onprogress') }}}(fetch);
else if (progresscb) progresscb(fetch);
}, fetchAttrSynchronous);
};

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

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

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

#if FETCH_SUPPORT_INDEXEDDB
var cacheResultAndReportSuccess = function(fetch, xhr, e) {
var cacheResultAndReportSuccess = (fetch, xhr, e) => {
#if FETCH_DEBUG
console.log('fetch: operation success. Caching result.. e: ' + e);
#endif
var storeSuccess = function(fetch, xhr, e) {
var storeSuccess = (fetch, xhr, e) => {
#if FETCH_DEBUG
console.log('fetch: IndexedDB store succeeded.');
#endif
Expand All @@ -514,7 +514,7 @@ function startFetch(fetch, successcb, errorcb, progresscb, readystatechangecb) {
else if (successcb) successcb(fetch);
}, fetchAttrSynchronous);
};
var storeError = function(fetch, xhr, e) {
var storeError = (fetch, xhr, e) => {
#if FETCH_DEBUG
console.error('fetch: IndexedDB store failed.');
#endif
Expand All @@ -527,7 +527,7 @@ function startFetch(fetch, successcb, errorcb, progresscb, readystatechangecb) {
fetchCacheData(Fetch.dbInstance, fetch, xhr.response, storeSuccess, storeError);
};

var performCachedXhr = function(fetch, xhr, e) {
var performCachedXhr = (fetch, xhr, e) => {
#if FETCH_DEBUG
console.error('fetch: starting (cached) XHR: ' + e);
#endif
Expand Down
Loading

0 comments on commit c0f1058

Please sign in to comment.