Skip to content

Commit 0d7ae4e

Browse files
committed
Use nullish assignment in file_packager.py
1 parent 48d9bc0 commit 0d7ae4e

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 browser 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.
@@ -1027,7 +1024,7 @@ def generate_js(data_target, data_files, metadata):
10271024
# we need to find the datafile in the same dir as the html file
10281025

10291026
code += '''
1030-
if (!Module['preloadResults']) Module['preloadResults'] = {};\n'''
1027+
Module['preloadResults'] ??= {};\n'''
10311028

10321029
if options.use_preload_cache:
10331030
code += '''
@@ -1093,8 +1090,7 @@ def generate_js(data_target, data_files, metadata):
10931090
if (Module['calledRun']) {
10941091
runWithFS(Module);
10951092
} else {
1096-
if (!Module['preRun']) Module['preRun'] = [];
1097-
Module["preRun"].push(runWithFS); // FS is not initialized yet, wait for it
1093+
(Module['preRun'] ??= []).push(runWithFS); // FS is not initialized yet, wait for it
10981094
}\n'''
10991095

11001096
if options.separate_metadata:
@@ -1118,8 +1114,7 @@ def generate_js(data_target, data_files, metadata):
11181114
if (Module['calledRun']) {
11191115
runMetaWithFS();
11201116
} else {
1121-
if (!Module['preRun']) Module['preRun'] = [];
1122-
Module["preRun"].push(runMetaWithFS);
1117+
(Module['preRun'] ??= []).push(runMetaWithFS);
11231118
}\n''' % {'metadata_file': os.path.basename(options.jsoutput + '.metadata')}
11241119
else:
11251120
_metadata_template = '''

0 commit comments

Comments
 (0)