From 0bf241c6d789ebff2a39112baf1d2c2453ac8ea7 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Wed, 30 Oct 2024 17:08:11 -0700 Subject: [PATCH] Use nullish assignment in file_packager.py. NFC (#22805) --- ChangeLog.md | 7 ++++++- tools/file_packager.py | 13 ++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 44cab44de8255..33db051320865 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -21,7 +21,7 @@ See docs/process.md for more on how version tagging works. 3.1.71 (in development) ----------------------- - LLVM's `-Wnontrivial-memaccess` warning has been updated to also warn about - passing non-trivially-copyable destrination parameter to `memcpy`, + passing non-trivially-copyable destination parameter to `memcpy`, `memset` and similar functions for which it is a documented undefined behavior (#22798). See https://github.com/llvm/llvm-project/pull/111434 - The automatic fallback to `$HOME/.emscripten_cache` when the emscripten @@ -29,6 +29,11 @@ See docs/process.md for more on how version tagging works. confusion. Anyone who really wants to use `$HOME/.emscripten_cache` can still do so either via an environment variable (`EMCC_CACHE`) or via a config file setting `CACHE`. +- The standalone `file_packager.py` tool now outputs modern JS (specifically it + includes nullish assignment). If you use this output directly and you want + to support older browsers you may need to transpile it. If you use + `file_packager` via emcc the output will be transpiled as part of the emcc + output. (#22805) 3.1.70 - 10/25/24 ----------------- diff --git a/tools/file_packager.py b/tools/file_packager.py index ed006c16f516e..5ac8fd163a6d4 100755 --- a/tools/file_packager.py +++ b/tools/file_packager.py @@ -607,10 +607,7 @@ def generate_js(data_target, data_files, metadata): var Module = typeof %(EXPORT_NAME)s != 'undefined' ? %(EXPORT_NAME)s : {};\n''' % {"EXPORT_NAME": options.export_name} ret += ''' - if (!Module['expectedDataFileDownloads']) { - Module['expectedDataFileDownloads'] = 0; - } - + Module['expectedDataFileDownloads'] ??= 0; Module['expectedDataFileDownloads']++; (() => { // 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): # we need to find the datafile in the same dir as the html file code += ''' - if (!Module['preloadResults']) Module['preloadResults'] = {};\n''' + Module['preloadResults'] ??= {};\n''' if options.use_preload_cache: code += ''' @@ -1099,8 +1096,7 @@ def generate_js(data_target, data_files, metadata): if (Module['calledRun']) { runWithFS(Module); } else { - if (!Module['preRun']) Module['preRun'] = []; - Module["preRun"].push(runWithFS); // FS is not initialized yet, wait for it + (Module['preRun'] ??= []).push(runWithFS); // FS is not initialized yet, wait for it }\n''' if options.separate_metadata: @@ -1139,8 +1135,7 @@ def generate_js(data_target, data_files, metadata): if (Module['calledRun']) { runMetaWithFS(); } else { - if (!Module['preRun']) Module['preRun'] = []; - Module["preRun"].push(runMetaWithFS); + (Module['preRun'] ??= []).push(runMetaWithFS); }\n''' % {'node_support_code': node_support_code, 'metadata_file': os.path.basename(options.jsoutput + '.metadata')} else: ret += '''