Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ See docs/process.md for more on how version tagging works.

7.0.2 (in development)
----------------------
- Integer values of `-jsDFOO=<value>` settings are now passed to JS library
code as numbers rather than as strings, like the values of `-s` settings.
In particular, `#if FOO` is now false when linking with `-jsDFOO=0`. Other
values are still passed as strings. (#28364)

7.0.1 - 11/21/26
----------------
Expand Down
33 changes: 33 additions & 0 deletions test/test_jslib.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,39 @@ def test_jslib_custom_settings(self):

self.assert_fail([EMCC, '-jsDWASM=1'], 'cannot change built-in settings values with a -jsD directive')

# Tests that integer values of -jsDfoo=val settings are passed to JS libraries
# as numbers, so that e.g. `#if FOO` is false with -jsDFOO=0.
@parameterized({
'': ('', 'enabled\nnumber: 1\n'),
'zero': ('=0', 'disabled\nnumber: 0\n'),
'one': ('=1', 'enabled\nnumber: 1\n'),
'negative': ('=-2', 'enabled\nnumber: -2\n'),
'hex': ('=0x10', 'enabled\nnumber: 16\n'),
'too_large': ('=9007199254740993', 'enabled\nstring: 9007199254740993\n'),
'empty': ('=', 'disabled\nstring: \n'),
'string': ('=abc', 'enabled\nstring: abc\n'),
})
def test_jslib_custom_settings_types(self, value, expected):
create_file('lib.js', r'''
addToLibrary({
js_function: () => {
#if CUSTOM_JS_OPTION
out('enabled');
#else
out('disabled');
#endif
out('{{{ typeof CUSTOM_JS_OPTION }}}: {{{ CUSTOM_JS_OPTION }}}');
},
});
''')
create_file('src.c', r'''
void js_function(void);
int main() {
js_function();
}
''')
self.do_runf('src.c', expected, cflags=['--js-library', 'lib.js', f'-jsDCUSTOM_JS_OPTION{value}'])

def test_jslib_native_deps(self):
# Verify that memset (which lives in compiled code), can be specified as a JS library
# dependency.
Expand Down
8 changes: 8 additions & 0 deletions tools/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,14 @@ def consume_arg_file():
value = '1'
if key in builtin_settings:
exit_with_error(f'{arg}: cannot change built-in settings values with a -jsD directive. Pass -s{key}={value} instead!')
# Pass integer values on as numbers rather than as strings, like with -s
# settings, so that e.g. `#if FOO` is false for `-jsDFOO=0`.
try:
number = int(value, 0)
if abs(number) <= 2**53 - 1:
value = number
except ValueError:
pass
# Allow overrides/duplicates for user-defined -jsD flags
settings[key] = value
newargs[i] = ''
Expand Down
Loading