Skip to content

Commit 5ff0a48

Browse files
committed
Mirror entire environment under node
One can still use `-sDETERMINISITIC` to avoid this behaviour. Fixes: #18816
1 parent fbc5d5c commit 5ff0a48

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ See docs/process.md for more on how version tagging works.
2121
3.1.33 (in development)
2222
-----------------------
2323
- Update SDL2_ttf port to 2.20.2 (#18804)
24+
- When running under node the full set of environment variables (i.e.
25+
process.env) are now reflected to running emscripten process (via e.g.
26+
getenv). If you don't want this behaviour `-sDETERMINISTIC` can be used
27+
to disable this can give fake envinonment instead.
2428

2529
3.1.32 - 02/17/23
2630
-----------------

src/library_wasi.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ var WasiLibrary = {
4242
$getEnvStrings: function() {
4343
if (!getEnvStrings.strings) {
4444
// Default values.
45-
#if !DETERMINISTIC
46-
// Browser language detection #8751
47-
var lang = ((typeof navigator == 'object' && navigator.languages && navigator.languages[0]) || 'C').replace('-', '_') + '.UTF-8';
48-
#else
45+
#if DETERMINISTIC
4946
// Deterministic language detection, ignore the browser's language.
5047
var lang = 'C.UTF-8';
48+
#else
49+
// Browser language detection #8751
50+
var lang = ((typeof navigator == 'object' && navigator.languages && navigator.languages[0]) || 'C').replace('-', '_') + '.UTF-8';
5151
#endif
5252
var env = {
5353
'USER': 'web_user',
@@ -58,6 +58,12 @@ var WasiLibrary = {
5858
'LANG': lang,
5959
'_': getExecutableName()
6060
};
61+
#if ENVIRONMENT_MAY_BE_NODE && !DETERMINISTIC
62+
if (ENVIRONMENT_IS_NODE) {
63+
// Under node we mirror then entire outer environment
64+
env = process.env;
65+
}
66+
#endif
6167
// Apply the user-provided values, if any.
6268
for (var x in ENV) {
6369
// x is a key in ENV; if ENV[x] is undefined, that means it was

0 commit comments

Comments
 (0)