Skip to content

Commit d1f7fa6

Browse files
authored
Convert more JS strings to use template literals. NFC (#26543)
1 parent b8469d8 commit d1f7fa6

File tree

66 files changed

+240
-241
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+240
-241
lines changed

src/jsifier.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ function stringifyWithFunctions(obj) {
107107
if (typeof value === 'function' && (str.startsWith(key) || str.startsWith('async ' + key))) {
108108
rtn += str + ',\n';
109109
} else {
110-
rtn += escapeJSONKey(key) + ':' + str + ',\n';
110+
rtn += `${escapeJSONKey(key)}:${str},\n`;
111111
}
112112
}
113113
return rtn + '}';

src/lib/libbrowser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,8 @@ var LibraryBrowser = {
596596
emscripten_run_preload_plugins_data: (data, size, suffix, arg, onload, onerror) => {
597597
{{{ runtimeKeepalivePush() }}}
598598

599-
var _suffix = UTF8ToString(suffix);
600-
var name = 'prepare_data_' + (Browser_asyncPrepareDataCounter++) + '.' + _suffix;
599+
suffix = UTF8ToString(suffix);
600+
var name = `prepare_data_${Browser_asyncPrepareDataCounter++}.${suffix}`;
601601
var cname = stringToNewUTF8(name);
602602
FS.createPreloadedFile(
603603
'/',

src/lib/libccall.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ addToLibrary({
1313
$getCFunc: (ident) => {
1414
var func = Module['_' + ident]; // closure exported function
1515
#if ASSERTIONS
16-
assert(func, 'Cannot call unknown function ' + ident + ', make sure it is exported');
16+
assert(func, `Cannot call unknown function ${ident}, make sure it is exported`);
1717
#endif
1818
return func;
1919
},
@@ -112,7 +112,7 @@ addToLibrary({
112112
// We need to return a Promise that resolves the return value
113113
// once the stack is rewound and execution finishes.
114114
#if ASSERTIONS
115-
assert(asyncMode, 'The call to ' + ident + ' is running asynchronously. If this was intended, add the async option to the ccall/cwrap call.');
115+
assert(asyncMode, `The call to ${ident} is running asynchronously. If this was intended, add the async option to the ccall/cwrap call.`);
116116
#endif
117117
return Asyncify.whenDone().then(onDone);
118118
}

src/lib/libcore.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2593,7 +2593,7 @@ function wrapSyscallFunction(x, library, isWasi) {
25932593
t = modifyJSFunction(t, (args, body, async_) => `${async_}function (${args}) {\n${pre}${body}${post}}\n`);
25942594
}
25952595

2596-
library[x] = eval('(' + t + ')');
2596+
library[x] = eval(`(${t})`);
25972597
// Automatically add dependency on `$SYSCALLS`
25982598
if (!WASMFS && t.includes('SYSCALLS')) {
25992599
library[x + '__deps'].push('$SYSCALLS');

src/lib/libsdl.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,16 +1066,16 @@ var LibrarySDL = {
10661066
{{{ makeSetValue('ptr', C_STRUCTS.SDL_WindowEvent.event, 'visibilityEventID' , 'i8') }}};
10671067
break;
10681068
}
1069-
default: abort('Unhandled SDL event: ' + event.type);
1069+
default: abort(`Unhandled SDL event: ${event.type}`);
10701070
}
10711071
},
10721072

10731073
makeFontString(height, fontName) {
1074-
if (fontName.charAt(0) != "'" && fontName.charAt(0) != '"') {
1074+
if (fontName[0] != "'" && fontName[0] != '"') {
10751075
// https://developer.mozilla.org/ru/docs/Web/CSS/font-family
10761076
// Font family names containing whitespace should be quoted.
10771077
// BTW, quote all font names is easier than searching spaces
1078-
fontName = '"' + fontName + '"';
1078+
fontName = `"${fontName}"`;
10791079
}
10801080
return height + 'px ' + fontName + ', serif';
10811081
},
@@ -1222,7 +1222,7 @@ var LibrarySDL = {
12221222
for (var c = 0; c < numChannels; ++c) {
12231223
var channelData = dstAudioBuffer['getChannelData'](c);
12241224
if (channelData.length != sizeSamplesPerChannel) {
1225-
abort('Web Audio output buffer length mismatch! Destination size: ' + channelData.length + ' samples vs expected ' + sizeSamplesPerChannel + ' samples!');
1225+
abort(`Web Audio output buffer length mismatch! Destination size: ${channelData.length} samples vs expected ${sizeSamplesPerChannel} samples!`);
12261226
}
12271227
if (audio.format == {{{ cDefs.AUDIO_S16LSB }}}) {
12281228
for (var j = 0; j < sizeSamplesPerChannel; ++j) {
@@ -1238,7 +1238,7 @@ var LibrarySDL = {
12381238
channelData[j] = ({{{ makeGetValue('heapPtr', '(j*numChannels + c)*4', 'float') }}});
12391239
}
12401240
} else {
1241-
abort('Invalid SDL audio format ' + audio.format + '!');
1241+
abort(`Invalid SDL audio format ${audio.format}!`);
12421242
}
12431243
}
12441244
},
@@ -2264,8 +2264,8 @@ var LibrarySDL = {
22642264
raw = callStbImage('stbi_load', [name]);
22652265
if (!raw) return 0;
22662266
#else
2267-
warnOnce('Cannot find preloaded image ' + filename);
2268-
warnOnce('Cannot find preloaded image ' + filename + '. Consider using STB_IMAGE=1 if you want synchronous image decoding (see settings.js), or package files with --use-preload-plugins');
2267+
warnOnce(`Cannot find preloaded image ${filename}`);
2268+
warnOnce(`Cannot find preloaded image ${filename}. Consider using STB_IMAGE=1 if you want synchronous image decoding (see settings.js), or package files with --use-preload-plugins`);
22692269
return 0;
22702270
#endif
22712271
} else if (Module['freePreloadedMediaOnUse']) {
@@ -2275,7 +2275,7 @@ var LibrarySDL = {
22752275

22762276
var surf = SDL.makeSurface(raw.width, raw.height, 0, false, 'load:' + filename);
22772277
var surfData = SDL.surfaces[surf];
2278-
surfData.ctx.globalCompositeOperation = "copy";
2278+
surfData.ctx.globalCompositeOperation = 'copy';
22792279
if (!raw.rawData) {
22802280
surfData.ctx.drawImage(raw, 0, 0, raw.width, raw.height, 0, 0, raw.width, raw.height);
22812281
} else {
@@ -2385,12 +2385,12 @@ var LibrarySDL = {
23852385
} else if (SDL.audio.format == {{{ cDefs.AUDIO_F32 }}}) {
23862386
SDL.audio.silence = 0.0; // Float data in range [-1.0, 1.0], silence is 0.0
23872387
} else {
2388-
abort('Invalid SDL audio format ' + SDL.audio.format + '!');
2388+
abort(`Invalid SDL audio format ${SDL.audio.format}!`);
23892389
}
23902390
// Round the desired audio frequency up to the next 'common' frequency value.
23912391
// Web Audio API spec states 'An implementation must support sample-rates in at least the range 22050 to 96000.'
23922392
if (SDL.audio.freq <= 0) {
2393-
abort('Unsupported sound frequency ' + SDL.audio.freq + '!');
2393+
abort(`Unsupported sound frequency ${SDL.audio.freq}!`);
23942394
} else if (SDL.audio.freq <= 22050) {
23952395
SDL.audio.freq = 22050; // Take it safe and clamp everything lower than 22kHz to that.
23962396
} else if (SDL.audio.freq <= 32000) {
@@ -3137,8 +3137,7 @@ var LibrarySDL = {
31373137
#if ASSERTIONS
31383138
// Check the final context looks valid. See
31393139
// https://github.com/emscripten-core/emscripten/issues/16242
3140-
assert(typeof SDL.ttfContext.measureText == 'function',
3141-
'context ' + SDL.ttfContext + 'must provide valid methods');
3140+
assert(typeof SDL.ttfContext.measureText == 'function', `context ${SDL.ttfContext} must provide valid methods`);
31423141
#endif
31433142
return 0;
31443143
},
@@ -3357,7 +3356,7 @@ var LibrarySDL = {
33573356
SDL_GL_SetAttribute__proxy: 'sync',
33583357
SDL_GL_SetAttribute: (attr, value) => {
33593358
if (!(attr in SDL.glAttributes)) {
3360-
abort('Unknown SDL GL attribute (' + attr + '). Please check if your SDL version is supported.');
3359+
abort(`Unknown SDL GL attribute (${attr}). Please check if your SDL version is supported.`);
33613360
}
33623361

33633362
SDL.glAttributes[attr] = value;
@@ -3366,7 +3365,7 @@ var LibrarySDL = {
33663365
SDL_GL_GetAttribute__proxy: 'sync',
33673366
SDL_GL_GetAttribute: (attr, value) => {
33683367
if (!(attr in SDL.glAttributes)) {
3369-
abort('Unknown SDL GL attribute (' + attr + '). Please check if your SDL version is supported.');
3368+
abort(`Unknown SDL GL attribute (${attr}). Please check if your SDL version is supported.`);
33703369
}
33713370

33723371
if (value) {{{ makeSetValue('value', 0, 'SDL.glAttributes[attr]', 'i32') }}};

src/lib/libstrings.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ addToLibrary({
7676
u0 = ((u0 & 15) << 12) | (u1 << 6) | u2;
7777
} else {
7878
#if ASSERTIONS
79-
if ((u0 & 0xF8) != 0xF0) warnOnce('Invalid UTF-8 leading byte ' + ptrToString(u0) + ' encountered when deserializing a UTF-8 string in wasm memory to a JS string!');
79+
if ((u0 & 0xF8) != 0xF0) warnOnce(`Invalid UTF-8 leading byte ${ptrToString(u0)} encountered when deserializing a UTF-8 string in wasm memory to a JS string!`);
8080
#endif
8181
u0 = ((u0 & 7) << 18) | (u1 << 12) | (u2 << 6) | (heapOrArray[idx++] & 63);
8282
}
@@ -186,7 +186,7 @@ addToLibrary({
186186
} else {
187187
if (outIdx + 3 >= endIdx) break;
188188
#if ASSERTIONS
189-
if (u > 0x10FFFF) warnOnce('Invalid Unicode code point ' + ptrToString(u) + ' encountered when serializing a JS string to a UTF-8 string in wasm memory! (Valid unicode code points should be in range 0-0x10FFFF).');
189+
if (u > 0x10FFFF) warnOnce(`Invalid Unicode code point ${ptrToString(u)} encountered when serializing a JS string to a UTF-8 string in wasm memory! (Valid unicode code points should be in range 0-0x10FFFF).`);
190190
#endif
191191
heap[outIdx++] = 0xF0 | (u >> 18);
192192
heap[outIdx++] = 0x80 | ((u >> 12) & 63);

src/lib/libsyscall.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ var SyscallsLibrary = {
339339
if (info.errno) throw new FS.ErrnoError(info.errno);
340340
info.addr = DNS.lookup_addr(info.addr) || info.addr;
341341
#if SYSCALL_DEBUG
342-
dbg(' (socketaddress: "' + [info.addr, info.port] + '")');
342+
dbg(` (socketaddress: "${[info.addr, info.port]}")`);
343343
#endif
344344
return info;
345345
},

src/lib/libwasmfs_node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ addToLibrary({
1111
$wasmfsNodeConvertNodeCode: (e) => {
1212
var code = e.code;
1313
#if ASSERTIONS
14-
assert(code in ERRNO_CODES, 'unexpected node error code: ' + code + ' (' + e + ')');
14+
assert(code in ERRNO_CODES, `unexpected node error code: ${code} (${e})`);
1515
#endif
1616
return ERRNO_CODES[code];
1717
},

src/lib/libwebaudio.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ var LibraryWebAudio = {
185185
assert(stackLowestAddress % 16 == 0, `AudioWorklet stack should be aligned to 16 bytes! (was ${stackLowestAddress} == ${stackLowestAddress%16} mod 16) Use e.g. memalign(16, stackSize) to align the stack!`);
186186
assert(stackSize != 0, 'AudioWorklets require a dedicated stack space for audio data marshalling between Wasm and JS!');
187187
assert(stackSize % 16 == 0, `AudioWorklet stack size should be a multiple of 16 bytes! (was ${stackSize} == ${stackSize%16} mod 16)`);
188-
assert(!audioContext.audioWorkletInitialized, 'emscripten_create_wasm_audio_worklet() was already called for AudioContext ' + contextHandle + '! Only call this function once per AudioContext!');
188+
assert(!audioContext.audioWorkletInitialized, `emscripten_create_wasm_audio_worklet() was already called for AudioContext ${contextHandle}! Only call this function once per AudioContext!`);
189189
audioContext.audioWorkletInitialized = 1;
190190
#endif
191191

0 commit comments

Comments
 (0)