From 5ff0a480cc5c221beb7477b2bdf22a75c4adcd40 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Wed, 22 Feb 2023 08:12:51 -0800 Subject: [PATCH] Mirror entire environment under node One can still use `-sDETERMINISITIC` to avoid this behaviour. Fixes: #18816 --- ChangeLog.md | 4 ++++ src/library_wasi.js | 14 ++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index d2d75e77e50e1..89a69705af6c9 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -21,6 +21,10 @@ See docs/process.md for more on how version tagging works. 3.1.33 (in development) ----------------------- - Update SDL2_ttf port to 2.20.2 (#18804) +- When running under node the full set of environment variables (i.e. + process.env) are now reflected to running emscripten process (via e.g. + getenv). If you don't want this behaviour `-sDETERMINISTIC` can be used + to disable this can give fake envinonment instead. 3.1.32 - 02/17/23 ----------------- diff --git a/src/library_wasi.js b/src/library_wasi.js index 97e3cbc59f046..6d4387d703b08 100644 --- a/src/library_wasi.js +++ b/src/library_wasi.js @@ -42,12 +42,12 @@ var WasiLibrary = { $getEnvStrings: function() { if (!getEnvStrings.strings) { // Default values. -#if !DETERMINISTIC - // Browser language detection #8751 - var lang = ((typeof navigator == 'object' && navigator.languages && navigator.languages[0]) || 'C').replace('-', '_') + '.UTF-8'; -#else +#if DETERMINISTIC // Deterministic language detection, ignore the browser's language. var lang = 'C.UTF-8'; +#else + // Browser language detection #8751 + var lang = ((typeof navigator == 'object' && navigator.languages && navigator.languages[0]) || 'C').replace('-', '_') + '.UTF-8'; #endif var env = { 'USER': 'web_user', @@ -58,6 +58,12 @@ var WasiLibrary = { 'LANG': lang, '_': getExecutableName() }; +#if ENVIRONMENT_MAY_BE_NODE && !DETERMINISTIC + if (ENVIRONMENT_IS_NODE) { + // Under node we mirror then entire outer environment + env = process.env; + } +#endif // Apply the user-provided values, if any. for (var x in ENV) { // x is a key in ENV; if ENV[x] is undefined, that means it was