Skip to content

Commit 0bf241c

Browse files
authored
Use nullish assignment in file_packager.py. NFC (#22805)
1 parent 9ae9322 commit 0bf241c

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

ChangeLog.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,19 @@ See docs/process.md for more on how version tagging works.
2121
3.1.71 (in development)
2222
-----------------------
2323
- LLVM's `-Wnontrivial-memaccess` warning has been updated to also warn about
24-
passing non-trivially-copyable destrination parameter to `memcpy`,
24+
passing non-trivially-copyable destination parameter to `memcpy`,
2525
`memset` and similar functions for which it is a documented undefined
2626
behavior (#22798). See https://github.com/llvm/llvm-project/pull/111434
2727
- The automatic fallback to `$HOME/.emscripten_cache` when the emscripten
2828
directory is read-only was removed. This automatic behaviour could cause
2929
confusion. Anyone who really wants to use `$HOME/.emscripten_cache` can
3030
still do so either via an environment variable (`EMCC_CACHE`) or via a config
3131
file setting `CACHE`.
32+
- The standalone `file_packager.py` tool now outputs modern JS (specifically it
33+
includes nullish assignment). If you use this output directly and you want
34+
to support older browsers you may need to transpile it. If you use
35+
`file_packager` via emcc the output will be transpiled as part of the emcc
36+
output. (#22805)
3237

3338
3.1.70 - 10/25/24
3439
-----------------

tools/file_packager.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -607,10 +607,7 @@ def generate_js(data_target, data_files, metadata):
607607
var Module = typeof %(EXPORT_NAME)s != 'undefined' ? %(EXPORT_NAME)s : {};\n''' % {"EXPORT_NAME": options.export_name}
608608

609609
ret += '''
610-
if (!Module['expectedDataFileDownloads']) {
611-
Module['expectedDataFileDownloads'] = 0;
612-
}
613-
610+
Module['expectedDataFileDownloads'] ??= 0;
614611
Module['expectedDataFileDownloads']++;
615612
(() => {
616613
// Do not attempt to redownload the virtual filesystem data when in a pthread or a Wasm Worker context.
@@ -1033,7 +1030,7 @@ def generate_js(data_target, data_files, metadata):
10331030
# we need to find the datafile in the same dir as the html file
10341031

10351032
code += '''
1036-
if (!Module['preloadResults']) Module['preloadResults'] = {};\n'''
1033+
Module['preloadResults'] ??= {};\n'''
10371034

10381035
if options.use_preload_cache:
10391036
code += '''
@@ -1099,8 +1096,7 @@ def generate_js(data_target, data_files, metadata):
10991096
if (Module['calledRun']) {
11001097
runWithFS(Module);
11011098
} else {
1102-
if (!Module['preRun']) Module['preRun'] = [];
1103-
Module["preRun"].push(runWithFS); // FS is not initialized yet, wait for it
1099+
(Module['preRun'] ??= []).push(runWithFS); // FS is not initialized yet, wait for it
11041100
}\n'''
11051101

11061102
if options.separate_metadata:
@@ -1139,8 +1135,7 @@ def generate_js(data_target, data_files, metadata):
11391135
if (Module['calledRun']) {
11401136
runMetaWithFS();
11411137
} else {
1142-
if (!Module['preRun']) Module['preRun'] = [];
1143-
Module["preRun"].push(runMetaWithFS);
1138+
(Module['preRun'] ??= []).push(runMetaWithFS);
11441139
}\n''' % {'node_support_code': node_support_code, 'metadata_file': os.path.basename(options.jsoutput + '.metadata')}
11451140
else:
11461141
ret += '''

0 commit comments

Comments
 (0)