Skip to content

Commit 9467940

Browse files
committed
Convert more JS code to use string template literals
Here are some of the vim commands I used to create this PR: ``` :%s/'\([^']\+\)' + \([^']\+\) + '\([^']\+\)'/`\1${\2}\3`/c :%s/'\([^']\+\)' + \([^']\+\)/`\1${\2}`/c :%s/'\([^']\+\)' + \([^')]\+\)/`\1${\2}`/c :%s/\([^']\+\)" + \([^')]\+\)/`\1${\2}`/c :%s/"\([^']\+\)" + \([^')]\+\)/`\1${\2}`/c :%s/`\([^`]\+\)` + \([^']\+\) + '\([^']\+\)'/`\1${\2}\3`/c :%s/`\([^`]\+\)` + \([^' ]\+\) + '\([^']\+\)'/`\1${\2}\3`/c :%s/`\([^`]\+\)` + \([^' ]\+\) + '\([^']\+\)'/`\1${\2}\3`/c :%s/`\([^`]\+\)` + \([^' ]\+\) + `\([^`]\+\)`/`\1${\2}\3`/c :%s/`\([^`]\+\)` + \([^' ]\+\) + `\([^`]\+\)`/`\1${\2}\3`/c :%s/`\([^`]\+\)` + \([^')]\+\)/`\1${\2}`/c ``` Followup to #19330
1 parent 90d76db commit 9467940

38 files changed

+324
-325
lines changed

src/Fetch.js

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var Fetch = {
2222
openDatabase: function(dbname, dbversion, onsuccess, onerror) {
2323
try {
2424
#if FETCH_DEBUG
25-
dbg('fetch: indexedDB.open(dbname="' + dbname + '", dbversion="' + dbversion + '");');
25+
dbg(`fetch: indexedDB.open(dbname="${dbname}", dbversion="${dbversion}");`);
2626
#endif
2727
var openRequest = indexedDB.open(dbname, dbversion);
2828
} catch (e) { return onerror(e); }
@@ -92,7 +92,7 @@ function fetchDeleteCachedData(db, fetch, onsuccess, onerror) {
9292
request.onsuccess = (event) => {
9393
var value = event.target.result;
9494
#if FETCH_DEBUG
95-
dbg('fetch: Deleted file ' + pathStr + ' from IndexedDB');
95+
dbg(`fetch: Deleted file ${pathStr} from IndexedDB`);
9696
#endif
9797
HEAPU32[fetch + {{{ C_STRUCTS.emscripten_fetch_t.data }}} >> 2] = 0;
9898
writeI53ToI64(fetch + {{{ C_STRUCTS.emscripten_fetch_t.numBytes }}}, 0);
@@ -105,7 +105,7 @@ function fetchDeleteCachedData(db, fetch, onsuccess, onerror) {
105105
};
106106
request.onerror = (error) => {
107107
#if FETCH_DEBUG
108-
dbg('fetch: Failed to delete file ' + pathStr + ' from IndexedDB! error: ' + error);
108+
dbg(`fetch: Failed to delete file ${pathStr} from IndexedDB! error: ${error}`);
109109
#endif
110110
HEAPU16[fetch + {{{ C_STRUCTS.emscripten_fetch_t.readyState }}} >> 1] = 4; // Mimic XHR readyState 4 === 'DONE: The operation is complete'
111111
HEAPU16[fetch + {{{ C_STRUCTS.emscripten_fetch_t.status }}} >> 1] = 404; // Mimic XHR HTTP status code 404 "Not Found"
@@ -114,7 +114,7 @@ function fetchDeleteCachedData(db, fetch, onsuccess, onerror) {
114114
};
115115
} catch(e) {
116116
#if FETCH_DEBUG
117-
dbg('fetch: Failed to load file ' + pathStr + ' from IndexedDB! Got exception ' + e);
117+
dbg(`fetch: Failed to load file ${pathStr} from IndexedDB! Got exception ${e}`);
118118
#endif
119119
onerror(fetch, 0, e);
120120
}
@@ -143,7 +143,7 @@ function fetchLoadCachedData(db, fetch, onsuccess, onerror) {
143143
var value = event.target.result;
144144
var len = value.byteLength || value.length;
145145
#if FETCH_DEBUG
146-
dbg('fetch: Loaded file ' + pathStr + ' from IndexedDB, length: ' + len);
146+
dbg(`fetch: Loaded file ${pathStr} from IndexedDB, length: ${len}`);
147147
#endif
148148
// The data pointer malloc()ed here has the same lifetime as the emscripten_fetch_t structure itself has, and is
149149
// freed when emscripten_fetch_close() is called.
@@ -160,7 +160,7 @@ function fetchLoadCachedData(db, fetch, onsuccess, onerror) {
160160
} else {
161161
// Succeeded to load, but the load came back with the value of undefined, treat that as an error since we never store undefined in db.
162162
#if FETCH_DEBUG
163-
dbg('fetch: File ' + pathStr + ' not found in IndexedDB');
163+
dbg(`fetch: File ${pathStr} not found in IndexedDB`);
164164
#endif
165165
HEAPU16[fetch + {{{ C_STRUCTS.emscripten_fetch_t.readyState }}} >> 1] = 4; // Mimic XHR readyState 4 === 'DONE: The operation is complete'
166166
HEAPU16[fetch + {{{ C_STRUCTS.emscripten_fetch_t.status }}} >> 1] = 404; // Mimic XHR HTTP status code 404 "Not Found"
@@ -170,7 +170,7 @@ function fetchLoadCachedData(db, fetch, onsuccess, onerror) {
170170
};
171171
getRequest.onerror = (error) => {
172172
#if FETCH_DEBUG
173-
dbg('fetch: Failed to load file ' + pathStr + ' from IndexedDB!');
173+
dbg(`fetch: Failed to load file ${pathStr} from IndexedDB!`);
174174
#endif
175175
HEAPU16[fetch + {{{ C_STRUCTS.emscripten_fetch_t.readyState }}} >> 1] = 4; // Mimic XHR readyState 4 === 'DONE: The operation is complete'
176176
HEAPU16[fetch + {{{ C_STRUCTS.emscripten_fetch_t.status }}} >> 1] = 404; // Mimic XHR HTTP status code 404 "Not Found"
@@ -179,7 +179,7 @@ function fetchLoadCachedData(db, fetch, onsuccess, onerror) {
179179
};
180180
} catch(e) {
181181
#if FETCH_DEBUG
182-
dbg('fetch: Failed to load file ' + pathStr + ' from IndexedDB! Got exception ' + e);
182+
dbg(`fetch: Failed to load file ${pathStr} from IndexedDB! Got exception ${e}`);
183183
#endif
184184
onerror(fetch, 0, e);
185185
}
@@ -205,7 +205,7 @@ function fetchCacheData(/** @type {IDBDatabase} */ db, fetch, data, onsuccess, o
205205
var putRequest = packages.put(data, destinationPathStr);
206206
putRequest.onsuccess = (event) => {
207207
#if FETCH_DEBUG
208-
dbg('fetch: Stored file "' + destinationPathStr + '" to IndexedDB cache.');
208+
dbg(`fetch: Stored file "${destinationPathStr}" to IndexedDB cache.`);
209209
#endif
210210
HEAPU16[fetch + {{{ C_STRUCTS.emscripten_fetch_t.readyState }}} >> 1] = 4; // Mimic XHR readyState 4 === 'DONE: The operation is complete'
211211
HEAPU16[fetch + {{{ C_STRUCTS.emscripten_fetch_t.status }}} >> 1] = 200; // Mimic XHR HTTP status code 200 "OK"
@@ -214,7 +214,7 @@ function fetchCacheData(/** @type {IDBDatabase} */ db, fetch, data, onsuccess, o
214214
};
215215
putRequest.onerror = (error) => {
216216
#if FETCH_DEBUG
217-
dbg('fetch: Failed to store file "' + destinationPathStr + '" to IndexedDB cache!');
217+
dbg(`fetch: Failed to store file "${destinationPathStr}" to IndexedDB cache!`);
218218
#endif
219219
// Most likely we got an error if IndexedDB is unwilling to store any more data for this page.
220220
// TODO: Can we identify and break down different IndexedDB-provided errors and convert those
@@ -226,7 +226,7 @@ function fetchCacheData(/** @type {IDBDatabase} */ db, fetch, data, onsuccess, o
226226
};
227227
} catch(e) {
228228
#if FETCH_DEBUG
229-
dbg('fetch: Failed to store file "' + destinationPathStr + '" to IndexedDB cache! Exception: ' + e);
229+
dbg(`fetch: Failed to store file "${destinationPathStr}" to IndexedDB cache! Exception: ${e}`);
230230
#endif
231231
onerror(fetch, 0, e);
232232
}
@@ -266,8 +266,8 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
266266
var xhr = new XMLHttpRequest();
267267
xhr.withCredentials = !!{{{ makeGetValue('fetch_attr', C_STRUCTS.emscripten_fetch_attr_t.withCredentials, 'u8') }}};;
268268
#if FETCH_DEBUG
269-
dbg('fetch: xhr.timeout: ' + xhr.timeout + ', xhr.withCredentials: ' + xhr.withCredentials);
270-
dbg('fetch: xhr.open(requestMethod="' + requestMethod + '", url: "' + url_ +'", userName: ' + userNameStr + ', password: ' + passwordStr + ');');
269+
dbg(`fetch: xhr.timeout: ${xhr.timeout}, xhr.withCredentials: ${xhr.withCredentials}`);
270+
dbg(`fetch: xhr.open(requestMethod="${requestMethod}", url: "${url}", userName: ${userNameStr}, password: ${passwordStr}`);
271271
#endif
272272
xhr.open(requestMethod, url_, !fetchAttrSynchronous, userNameStr, passwordStr);
273273
if (!fetchAttrSynchronous) xhr.timeout = timeoutMsecs; // XHR timeout field is only accessible in async XHRs, and must be set after .open() but before .send().
@@ -280,7 +280,7 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
280280
if (overriddenMimeType) {
281281
var overriddenMimeTypeStr = UTF8ToString(overriddenMimeType);
282282
#if FETCH_DEBUG
283-
dbg('fetch: xhr.overrideMimeType("' + overriddenMimeTypeStr + '");');
283+
dbg(`fetch: xhr.overrideMimeType("${overriddenMimeTypeStr}");`);
284284
#endif
285285
xhr.overrideMimeType(overriddenMimeTypeStr);
286286
}
@@ -294,15 +294,15 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
294294
var keyStr = UTF8ToString(key);
295295
var valueStr = UTF8ToString(value);
296296
#if FETCH_DEBUG
297-
dbg('fetch: xhr.setRequestHeader("' + keyStr + '", "' + valueStr + '");');
297+
dbg(`fetch: xhr.setRequestHeader("${keyStr}", "${valueStr}");`);
298298
#endif
299299
xhr.setRequestHeader(keyStr, valueStr);
300300
}
301301
}
302302

303303
var id = Fetch.xhrs.allocate(xhr);
304304
#if FETCH_DEBUG
305-
dbg('fetch: id=' + id);
305+
dbg(`fetch: id=${id}`);
306306
#endif
307307
{{{ makeSetValue('fetch', C_STRUCTS.emscripten_fetch_t.id, 'id', 'u32') }}};
308308
var data = (dataPtr && dataLength) ? HEAPU8.slice(dataPtr, dataPtr + dataLength) : null;
@@ -320,7 +320,7 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
320320
}
321321
if (ptrLen > 0) {
322322
#if FETCH_DEBUG
323-
dbg('fetch: allocating ' + ptrLen + ' bytes in Emscripten heap for xhr data');
323+
dbg(`fetch: allocating ${ptrLen} bytes in Emscripten heap for xhr data`);
324324
#endif
325325
// The data pointer malloc()ed here has the same lifetime as the emscripten_fetch_t structure itself has, and is
326326
// freed when emscripten_fetch_close() is called.
@@ -350,12 +350,12 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
350350
saveResponseAndStatus();
351351
if (xhr.status >= 200 && xhr.status < 300) {
352352
#if FETCH_DEBUG
353-
dbg('fetch: xhr of URL "' + xhr.url_ + '" / responseURL "' + xhr.responseURL + '" succeeded with status ' + xhr.status);
353+
dbg(`fetch: xhr of URL "${xhr.url_}" / responseURL "${xhr.responseURL}" succeeded with status ${xhr.status}`);
354354
#endif
355355
if (onsuccess) onsuccess(fetch, xhr, e);
356356
} else {
357357
#if FETCH_DEBUG
358-
dbg('fetch: xhr of URL "' + xhr.url_ + '" / responseURL "' + xhr.responseURL + '" failed with status ' + xhr.status);
358+
dbg(`fetch: xhr of URL "${xhr.url_}" / responseURL "${xhr.responseURL}" failed with status ${xhr.status}`);
359359
#endif
360360
if (onerror) onerror(fetch, xhr, e);
361361
}
@@ -366,7 +366,7 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
366366
return;
367367
}
368368
#if FETCH_DEBUG
369-
dbg('fetch: xhr of URL "' + xhr.url_ + '" / responseURL "' + xhr.responseURL + '" finished with error, readyState ' + xhr.readyState + ' and status ' + xhr.status);
369+
dbg(`fetch: xhr of URL "${xhr.url_}" / responseURL "${xhr.responseURL}" finished with error, readyState ${xhr.readyState} and status ${xhr.status}`);
370370
#endif
371371
saveResponseAndStatus();
372372
if (onerror) onerror(fetch, xhr, e);
@@ -377,7 +377,7 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
377377
return;
378378
}
379379
#if FETCH_DEBUG
380-
dbg('fetch: xhr of URL "' + xhr.url_ + '" / responseURL "' + xhr.responseURL + '" timed out, readyState ' + xhr.readyState + ' and status ' + xhr.status);
380+
dbg(`fetch: xhr of URL "${xhr.url_}" / responseURL "${xhr.responseURL}" timed out, readyState ${xhr.readyState} and status ${xhr.status}`);
381381
#endif
382382
if (onerror) onerror(fetch, xhr, e);
383383
};
@@ -390,7 +390,7 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
390390
var ptr = 0;
391391
if (ptrLen > 0 && fetchAttrLoadToMemory && fetchAttrStreamData) {
392392
#if FETCH_DEBUG
393-
dbg('fetch: allocating ' + ptrLen + ' bytes in Emscripten heap for xhr data');
393+
dbg(`fetch: allocating ${ptrLen} bytes in Emscripten heap for xhr data`);
394394
#endif
395395
#if ASSERTIONS
396396
assert(onprogress, 'When doing a streaming fetch, you should have an onprogress handler registered to receive the chunks!');
@@ -426,13 +426,13 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
426426
if (onreadystatechange) onreadystatechange(fetch, xhr, e);
427427
};
428428
#if FETCH_DEBUG
429-
dbg('fetch: xhr.send(data=' + data + ')');
429+
dbg(`fetch: xhr.send(data=${data})`);
430430
#endif
431431
try {
432432
xhr.send(data);
433433
} catch(e) {
434434
#if FETCH_DEBUG
435-
dbg('fetch: xhr failed with exception: ' + e);
435+
dbg(`fetch: xhr failed with exception: ${e}`);
436436
#endif
437437
if (onerror) onerror(fetch, xhr, e);
438438
}
@@ -467,7 +467,7 @@ function startFetch(fetch, successcb, errorcb, progresscb, readystatechangecb) {
467467

468468
var reportSuccess = (fetch, xhr, e) => {
469469
#if FETCH_DEBUG
470-
dbg('fetch: operation success. e: ' + e);
470+
dbg(`fetch: operation success. e: ${e}`);
471471
#endif
472472
{{{ runtimeKeepalivePop() }}}
473473
doCallback(() => {
@@ -485,7 +485,7 @@ function startFetch(fetch, successcb, errorcb, progresscb, readystatechangecb) {
485485

486486
var reportError = (fetch, xhr, e) => {
487487
#if FETCH_DEBUG
488-
dbg('fetch: operation failed: ' + e);
488+
dbg(`fetch: operation failed: ${e}`);
489489
#endif
490490
{{{ runtimeKeepalivePop() }}}
491491
doCallback(() => {
@@ -496,7 +496,7 @@ function startFetch(fetch, successcb, errorcb, progresscb, readystatechangecb) {
496496

497497
var reportReadyStateChange = (fetch, xhr, e) => {
498498
#if FETCH_DEBUG
499-
dbg('fetch: ready state change. e: ' + e);
499+
dbg(`fetch: ready state change. e: ${e}`);
500500
#endif
501501
doCallback(() => {
502502
if (onreadystatechange) {{{ makeDynCall('vp', 'onreadystatechange') }}}(fetch);
@@ -506,15 +506,15 @@ function startFetch(fetch, successcb, errorcb, progresscb, readystatechangecb) {
506506

507507
var performUncachedXhr = (fetch, xhr, e) => {
508508
#if FETCH_DEBUG
509-
dbg('fetch: starting (uncached) XHR: ' + e);
509+
dbg(`fetch: starting (uncached) XHR: ${e}`);
510510
#endif
511511
fetchXHR(fetch, reportSuccess, reportError, reportProgress, reportReadyStateChange);
512512
};
513513

514514
#if FETCH_SUPPORT_INDEXEDDB
515515
var cacheResultAndReportSuccess = (fetch, xhr, e) => {
516516
#if FETCH_DEBUG
517-
dbg('fetch: operation success. Caching result.. e: ' + e);
517+
dbg(`fetch: operation success. Caching result.. e: ${e}`);
518518
#endif
519519
var storeSuccess = (fetch, xhr, e) => {
520520
#if FETCH_DEBUG
@@ -541,7 +541,7 @@ function startFetch(fetch, successcb, errorcb, progresscb, readystatechangecb) {
541541

542542
var performCachedXhr = (fetch, xhr, e) => {
543543
#if FETCH_DEBUG
544-
dbg('fetch: starting (cached) XHR: ' + e);
544+
dbg(`fetch: starting (cached) XHR: ${e}`);
545545
#endif
546546
fetchXHR(fetch, cacheResultAndReportSuccess, reportError, reportProgress, reportReadyStateChange);
547547
};
@@ -583,7 +583,7 @@ function fetchGetResponseHeaders(id, dst, dstSizeBytes) {
583583
//Delete the xhr JS object, allowing it to be garbage collected.
584584
function fetchFree(id) {
585585
#if FETCH_DEBUG
586-
dbg("fetch: fetchFree id:" + id);
586+
dbg(`fetch: fetchFree id:${id}`);
587587
#endif
588588
if (Fetch.xhrs.has(id)) {
589589
var xhr = Fetch.xhrs.get(id);

src/IDBStore.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
req.onsuccess = (event) => {
7070
var result = event.target.result;
7171
if (!result) {
72-
return callback('file ' + id + ' not found');
72+
return callback(`file ${id} not found`);
7373
}
7474
return callback(null, result);
7575
};

src/arrayUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function intArrayToString(array) {
1919
var chr = array[i];
2020
if (chr > 0xFF) {
2121
#if ASSERTIONS
22-
assert(false, 'Character code ' + chr + ' (' + String.fromCharCode(chr) + ') at offset ' + i + ' not in 0x00-0xFF.');
22+
assert(false, `Character code ${chr} (${String.fromCharCode(chr)}) at offset ${i} not in 0x00-0xFF.`);
2323
#endif
2424
chr &= 0xFF;
2525
}

0 commit comments

Comments
 (0)