Skip to content

Commit b972b77

Browse files
authored
Treat ENVIRONMENT setting as a list. NFC (#24545)
This should not be a user-visible change I hope since the existing bespoke format of comma-separated-list will parse just fine as a real list too.
1 parent ffcd91b commit b972b77

File tree

6 files changed

+23
-24
lines changed

6 files changed

+23
-24
lines changed

site/source/docs/tools_reference/settings_reference.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,9 +1011,9 @@ ones we identify at runtime using ``ENVIRONMENT_IS_*``. Specifically:
10111011
at compile time, there is no runtime behavior change.
10121012

10131013
Note that by default we do not include the 'shell' environment since direct
1014-
usage of d8, js, jsc is extremely rare.
1014+
usage of d8, spidermonkey and jsc is extremely rare.
10151015

1016-
Default value: 'web,webview,worker,node'
1016+
Default value: ['web', 'webview', 'worker', 'node']
10171017

10181018
.. _lz4:
10191019

src/settings.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,9 +662,9 @@ var LEGACY_VM_SUPPORT = false;
662662
// at compile time, there is no runtime behavior change.
663663
//
664664
// Note that by default we do not include the 'shell' environment since direct
665-
// usage of d8, js, jsc is extremely rare.
665+
// usage of d8, spidermonkey and jsc is extremely rare.
666666
// [link]
667-
var ENVIRONMENT = 'web,webview,worker,node';
667+
var ENVIRONMENT = ['web', 'webview', 'worker', 'node'];
668668

669669
// Enable this to support lz4-compressed file packages. They are stored compressed in memory, and
670670
// decompressed on the fly, avoiding storing the entire decompressed data in memory at once.

src/shell.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,16 @@ if (ENVIRONMENT_IS_AUDIO_WORKLET) ENVIRONMENT_IS_WASM_WORKER = true;
5959
// Determine the runtime environment we are in. You can customize this by
6060
// setting the ENVIRONMENT setting at compile time (see settings.js).
6161

62-
#if ENVIRONMENT && !ENVIRONMENT.includes(',')
63-
var ENVIRONMENT_IS_WEB = {{{ ENVIRONMENT === 'web' }}};
62+
#if ENVIRONMENT.length == 1
63+
var ENVIRONMENT_IS_WEB = {{{ ENVIRONMENT[0] === 'web' }}};
6464
#if PTHREADS && ENVIRONMENT_MAY_BE_NODE
6565
// node+pthreads always supports workers; detect which we are at runtime
6666
var ENVIRONMENT_IS_WORKER = typeof WorkerGlobalScope != 'undefined';
6767
#else
68-
var ENVIRONMENT_IS_WORKER = {{{ ENVIRONMENT === 'worker' }}};
68+
var ENVIRONMENT_IS_WORKER = {{{ ENVIRONMENT[0] === 'worker' }}};
6969
#endif
70-
var ENVIRONMENT_IS_NODE = {{{ ENVIRONMENT === 'node' }}};
71-
var ENVIRONMENT_IS_SHELL = {{{ ENVIRONMENT === 'shell' }}};
70+
var ENVIRONMENT_IS_NODE = {{{ ENVIRONMENT[0] === 'node' }}};
71+
var ENVIRONMENT_IS_SHELL = {{{ ENVIRONMENT[0] === 'shell' }}};
7272
#else // ENVIRONMENT
7373
// Attempt to auto-detect the environment
7474
var ENVIRONMENT_IS_WEB = typeof window == 'object';
@@ -183,7 +183,7 @@ var readAsync, readBinary;
183183

184184
#if ENVIRONMENT_MAY_BE_NODE
185185
if (ENVIRONMENT_IS_NODE) {
186-
#if ENVIRONMENT && ASSERTIONS
186+
#if ENVIRONMENT.length && ASSERTIONS
187187
const isNode = {{{ nodeDetectionCode() }}};
188188
if (!isNode) throw new Error('not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)');
189189
#endif
@@ -265,7 +265,7 @@ if (ENVIRONMENT_IS_NODE) {
265265
#if ENVIRONMENT_MAY_BE_SHELL || ASSERTIONS
266266
if (ENVIRONMENT_IS_SHELL) {
267267

268-
#if ENVIRONMENT && ASSERTIONS
268+
#if ENVIRONMENT.length && ASSERTIONS
269269
const isNode = {{{ nodeDetectionCode() }}};
270270
if (isNode || typeof window == 'object' || typeof WorkerGlobalScope != 'undefined') throw new Error('not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)');
271271
#endif
@@ -345,7 +345,7 @@ if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
345345
// infer anything from them.
346346
}
347347

348-
#if ENVIRONMENT && ASSERTIONS
348+
#if ENVIRONMENT.length && ASSERTIONS
349349
if (!(typeof window == 'object' || typeof WorkerGlobalScope != 'undefined')) throw new Error('not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)');
350350
#endif
351351

src/shell_minimal.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ var ENVIRONMENT_IS_SHELL = typeof read == 'function';
4545
#if ASSERTIONS || PTHREADS
4646
#if !ENVIRONMENT_MAY_BE_NODE && !ENVIRONMENT_MAY_BE_SHELL
4747
var ENVIRONMENT_IS_WEB = true
48-
#elif ENVIRONMENT && !ENVIRONMENT.includes(',')
49-
var ENVIRONMENT_IS_WEB = {{{ ENVIRONMENT === 'web' }}};
48+
#elif ENVIRONMENT.length == 1
49+
var ENVIRONMENT_IS_WEB = {{{ ENVIRONMENT[0] === 'web' }}};
5050
#elif ENVIRONMENT_MAY_BE_SHELL && ENVIRONMENT_MAY_BE_NODE
5151
var ENVIRONMENT_IS_WEB = !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_SHELL;
5252
#elif ENVIRONMENT_MAY_BE_SHELL

tools/link.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,18 +166,17 @@ def setup_environment_settings():
166166
# Note: we need to actually modify ENVIRONMENTS variable here before the parsing,
167167
# because some JS code reads it back so modifying parsed info alone is not sufficient.
168168
if settings.SHARED_MEMORY and settings.ENVIRONMENT:
169-
settings.ENVIRONMENT += ',worker'
169+
settings.ENVIRONMENT.append('worker')
170170

171171
# Environment setting based on user input
172-
environments = settings.ENVIRONMENT.split(',')
173-
if any(x for x in environments if x not in VALID_ENVIRONMENTS):
172+
if any(x for x in settings.ENVIRONMENT if x not in VALID_ENVIRONMENTS):
174173
exit_with_error(f'Invalid environment specified in "ENVIRONMENT": {settings.ENVIRONMENT}. Should be one of: {",".join(VALID_ENVIRONMENTS)}')
175174

176-
settings.ENVIRONMENT_MAY_BE_WEB = not settings.ENVIRONMENT or 'web' in environments
177-
settings.ENVIRONMENT_MAY_BE_WEBVIEW = not settings.ENVIRONMENT or 'webview' in environments
178-
settings.ENVIRONMENT_MAY_BE_NODE = not settings.ENVIRONMENT or 'node' in environments
179-
settings.ENVIRONMENT_MAY_BE_SHELL = not settings.ENVIRONMENT or 'shell' in environments
180-
settings.ENVIRONMENT_MAY_BE_WORKER = not settings.ENVIRONMENT or 'worker' in environments
175+
settings.ENVIRONMENT_MAY_BE_WEB = not settings.ENVIRONMENT or 'web' in settings.ENVIRONMENT
176+
settings.ENVIRONMENT_MAY_BE_WEBVIEW = not settings.ENVIRONMENT or 'webview' in settings.ENVIRONMENT
177+
settings.ENVIRONMENT_MAY_BE_NODE = not settings.ENVIRONMENT or 'node' in settings.ENVIRONMENT
178+
settings.ENVIRONMENT_MAY_BE_SHELL = not settings.ENVIRONMENT or 'shell' in settings.ENVIRONMENT
179+
settings.ENVIRONMENT_MAY_BE_WORKER = not settings.ENVIRONMENT or 'worker' in settings.ENVIRONMENT
181180

182181
if not settings.ENVIRONMENT_MAY_BE_NODE:
183182
if 'MIN_NODE_VERSION' in user_settings:
@@ -2008,7 +2007,7 @@ def run_embind_gen(options, wasm_target, js_syms, extra_settings):
20082007
settings.PRE_JS_FILES = []
20092008
settings.POST_JS_FILES = []
20102009
# Force node since that is where the tool runs.
2011-
settings.ENVIRONMENT = 'node'
2010+
settings.ENVIRONMENT = ['node']
20122011
settings.MINIMAL_RUNTIME = 0
20132012
# Required function to trigger TS generation.
20142013
settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$callRuntimeCallbacks']

tools/maint/update_settings_docs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def write_file(f):
101101
# Format:
102102
# var NAME = DEFAULT;
103103
# Split it and strip the final ';'.
104-
_, setting_name, _, setting_default = line.strip(';').split()
104+
_, setting_name, _, setting_default = line.strip(';').split(None, 3)
105105
comment = '\n'.join(current_comment).strip()
106106
write_setting(f, setting_name, setting_default, comment, current_tags)
107107
current_comment = []

0 commit comments

Comments
 (0)