Skip to content

Commit 487a0d4

Browse files
committed
Enable STRICT_JS by default
This has been enabled under `STRICT` mode since it was first added back in 2019 (#9265).
1 parent ebfb605 commit 487a0d4

File tree

7 files changed

+19
-29
lines changed

7 files changed

+19
-29
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ See docs/process.md for more on how version tagging works.
2323
- The deprecated `EMSCRIPTEN` macro is now defined in `emscripten.h` rather than
2424
on the command line (`__EMSCRIPTEN__`, which is built into LLVM, should be
2525
used instead). (#26417)
26+
- The `STRICT_JS` setting is now on by default. Previously it was enabled by
27+
default in `STRICT` mode. If you have EM_ASM or EM_JS or `--pre-js` code
28+
that does not conform to JS strict mode then you may need to disable this
29+
with `-sSTRICT_JS=0`. (#26421)
2630

2731
5.0.3 - 03/14/26
2832
----------------

site/source/docs/tools_reference/settings_reference.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,7 +1701,6 @@ Set the environment variable EMCC_STRICT=1 or pass -sSTRICT to test that a
17011701
codebase builds nicely in forward compatible manner.
17021702
Changes enabled by this:
17031703

1704-
- STRICT_JS is enabled.
17051704
- IGNORE_MISSING_MAIN is disabled.
17061705
- AUTO_JS_LIBRARIES is disabled.
17071706
- AUTO_NATIVE_LIBRARIES is disabled.
@@ -1732,7 +1731,7 @@ STRICT_JS
17321731

17331732
Add ``"use strict;"`` to generated JS
17341733

1735-
Default value: false
1734+
Default value: true
17361735

17371736
.. _warn_on_undefined_symbols:
17381737

src/settings.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,6 @@ var LINKABLE = false;
11601160
// codebase builds nicely in forward compatible manner.
11611161
// Changes enabled by this:
11621162
//
1163-
// - STRICT_JS is enabled.
11641163
// - IGNORE_MISSING_MAIN is disabled.
11651164
// - AUTO_JS_LIBRARIES is disabled.
11661165
// - AUTO_NATIVE_LIBRARIES is disabled.
@@ -1179,7 +1178,7 @@ var IGNORE_MISSING_MAIN = true;
11791178

11801179
// Add ``"use strict;"`` to generated JS
11811180
// [link]
1182-
var STRICT_JS = false;
1181+
var STRICT_JS = true;
11831182

11841183
// If set to 1, we will warn on any undefined symbols that are not resolved by
11851184
// the ``library_*.js`` files. Note that it is common in large projects to not

test/test_browser.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -606,13 +606,12 @@ def test_preload_caching(self, extra_size):
606606
addToLibrary({
607607
checkPreloadResults: function() {
608608
var cached = 0;
609-
var packages = Object.keys(Module['preloadResults']);
610-
packages.forEach(function(package) {
611-
var fromCache = Module['preloadResults'][package]['fromCache'];
609+
for (var result of Object.values(Module['preloadResults'])) {
610+
var fromCache = result['fromCache'];
612611
if (fromCache) {
613612
cached++;
614613
}
615-
});
614+
}
616615
return cached;
617616
}
618617
});
@@ -945,7 +944,7 @@ def test_sdl_stb_image_cleanup(self):
945944
'safe_heap_O2': (['-sSAFE_HEAP', '-O2'],),
946945
})
947946
def test_sdl_canvas(self, args):
948-
self.btest_exit('test_sdl_canvas.c', cflags=['-sSTRICT_JS', '-sLEGACY_GL_EMULATION', '-lSDL', '-lGL'] + args)
947+
self.btest_exit('test_sdl_canvas.c', cflags=['-sLEGACY_GL_EMULATION', '-lSDL', '-lGL'] + args)
949948

950949
def test_sdl_canvas_alpha(self):
951950
# N.B. On Linux with Intel integrated graphics cards, this test needs Firefox 49 or newer.
@@ -1059,7 +1058,7 @@ def test_sdl_mouse_offsets(self):
10591058
self.run_browser('page.html', '', '/report_result?exit:0')
10601059

10611060
def test_glut_touchevents(self):
1062-
self.btest_exit('glut_touchevents.c', cflags=['-lglut', '-sSTRICT_JS'])
1061+
self.btest_exit('glut_touchevents.c', cflags=['-lglut'])
10631062

10641063
def test_glut_wheelevents(self):
10651064
self.btest_exit('glut_wheelevents.c', cflags=['-lglut'])
@@ -4847,8 +4846,6 @@ def test_browser_run_from_different_directory_async(self):
48474846
# also also we eval the initial code, so currentScript is not present. That prevents us
48484847
# from finding the file in a subdir, but here we at least check we do not regress compared to the
48494848
# normal case of finding in the current dir.
4850-
# test both modularize (and creating an instance) and modularize-instance
4851-
# (which creates by itself)
48524849
@parameterized({
48534850
'': ([], ['-sMODULARIZE'], 'Module();'),
48544851
'subdir': (['subdir'], ['-sMODULARIZE'], 'Module();'),
@@ -4865,7 +4862,7 @@ def test_browser_modularize_no_current_script(self, path, args, creation):
48654862
setTimeout(async () => {
48664863
let response = await fetch('test.js');
48674864
let text = await response.text();
4868-
eval(text);
4865+
let Module = eval(text + '; Module');
48694866
%s
48704867
}, 1);
48714868
</script>
@@ -4953,7 +4950,6 @@ def test_no_declare_asm_module_exports_wasm2js(self, args):
49534950

49544951
@parameterized({
49554952
'': ([],),
4956-
'strict_js': (['-sSTRICT_JS'],),
49574953
'minimal_runtime': (['-sMINIMAL_RUNTIME=1'],),
49584954
'minimal_runtime_2': (['-sMINIMAL_RUNTIME=2'],),
49594955
})
@@ -5425,8 +5421,8 @@ def test_pthread_unhandledrejection(self):
54255421
def test_pthread_key_recreation(self):
54265422
self.btest_exit('pthread/test_pthread_key_recreation.c', cflags=['-pthread', '-sPTHREAD_POOL_SIZE=1'])
54275423

5428-
def test_full_js_library_strict(self):
5429-
self.btest_exit('hello_world.c', cflags=['-sINCLUDE_FULL_LIBRARY', '-sSTRICT_JS'])
5424+
def test_full_js_library(self):
5425+
self.btest_exit('hello_world.c', cflags=['-sINCLUDE_FULL_LIBRARY'])
54305426

54315427
# Tests the AudioWorklet demo
54325428
@parameterized({

test/test_core.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,6 @@ def decorated(self, textdecoder, *args, **kwargs):
429429

430430
no_safe_heap = make_no_decorator_for_setting('SAFE_HEAP')
431431
no_strict = make_no_decorator_for_setting('STRICT')
432-
no_strict_js = make_no_decorator_for_setting('STRICT_JS')
433432
no_big_endian = make_no_decorator_for_setting('SUPPORT_BIG_ENDIAN')
434433
no_omit_asm_module_exports = make_no_decorator_for_setting('DECLARE_ASM_MODULE_EXPORTS=0')
435434
no_js_math = make_no_decorator_for_setting('JS_MATH')
@@ -9729,7 +9728,6 @@ def test_esm_integration(self):
97299728
self.assertFileContents(test_file('core/test_esm_integration.expected.mjs'), read_file('hello_world.mjs'))
97309729

97319730
@no_omit_asm_module_exports('MODULARIZE is not compatible with DECLARE_ASM_MODULE_EXPORTS=0')
9732-
@no_strict_js('EXPORT_ES6 is not compatible with STRICT_JS')
97339731
def test_modularize_instance_hello(self):
97349732
self.do_core_test('test_hello_world.c', cflags=['-sMODULARIZE=instance', '-Wno-experimental'])
97359733

@@ -9738,7 +9736,6 @@ def test_modularize_instance_hello(self):
97389736
'pthreads': (['-pthread'],),
97399737
})
97409738
@no_omit_asm_module_exports('MODULARIZE is not compatible with DECLARE_ASM_MODULE_EXPORTS=0')
9741-
@no_strict_js('EXPORT_ES6 is not compatible with STRICT_JS')
97429739
def test_modularize_instance(self, args):
97439740
if args:
97449741
self.require_pthreads()
@@ -9774,7 +9771,6 @@ def test_modularize_instance(self, args):
97749771

97759772
@no_omit_asm_module_exports('MODULARIZE is not compatible with DECLARE_ASM_MODULE_EXPORTS=0')
97769773
@no_4gb('EMBIND_AOT can\'t lower 4gb')
9777-
@no_strict_js('EXPORT_ES6 is not compatible with STRICT_JS')
97789774
def test_modularize_instance_embind(self):
97799775
self.run_process([EMXX, test_file('modularize_instance_embind.cpp'),
97809776
'-sMODULARIZE=instance',
@@ -9955,7 +9951,6 @@ def setUp(self):
99559951

99569952
# Add DEFAULT_TO_CXX=0
99579953
strict = make_run('strict', cflags=[], settings={'STRICT': 1})
9958-
strict_js = make_run('strict_js', cflags=[], settings={'STRICT_JS': 1})
99599954

99609955
ubsan = make_run('ubsan', cflags=['-fsanitize=undefined', '--profiling'])
99619956
lsan = make_run('lsan', cflags=['-fsanitize=leak', '--profiling'], settings={'ALLOW_MEMORY_GROWTH': 1})

test/test_other.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3374,7 +3374,6 @@ def test_embind_subclass_pointer(self):
33743374
'o2': ['-O2'],
33753375
'o2_mem_growth': ['-O2', '-sALLOW_MEMORY_GROWTH', test_file('embind/isMemoryGrowthEnabled=true.cpp')],
33763376
'o2_closure': ['-O2', '--closure=1', '--closure-args', '--externs ' + shlex.quote(test_file('embind/underscore-externs.js')), '-sASSERTIONS=1'],
3377-
'strict_js': ['-sSTRICT_JS'],
33783377
# DYNCALLS tests the legacy native function API (ASYNCIFY implicitly enables DYNCALLS)
33793378
'dyncalls': ['-sDYNCALLS=1'],
33803379
})
@@ -9022,11 +9021,11 @@ def test(check, extra):
90229021
'embind': (['-lembind'],),
90239022
})
90249023
def test_full_js_library(self, args):
9025-
self.run_process([EMCC, test_file('hello_world.c'), '-sSTRICT_JS', '-sINCLUDE_FULL_LIBRARY'] + args)
9024+
self.run_process([EMCC, test_file('hello_world.c'), '-sINCLUDE_FULL_LIBRARY'] + args)
90269025

90279026
def test_full_js_library_undefined(self):
90289027
create_file('main.c', 'void foo(); int main() { foo(); return 0; }')
9029-
self.assert_fail([EMCC, 'main.c', '-sSTRICT_JS', '-sINCLUDE_FULL_LIBRARY'], 'undefined symbol: foo')
9028+
self.assert_fail([EMCC, 'main.c', '-sINCLUDE_FULL_LIBRARY'], 'undefined symbol: foo')
90309029

90319030
def test_full_js_library_except(self):
90329031
self.set_setting('INCLUDE_FULL_LIBRARY', 1)
@@ -13764,9 +13763,6 @@ def test_std_filesystem_tempdir(self):
1376413763
self.skipTest('https://github.com/emscripten-core/emscripten/issues/24830')
1376513764
self.do_other_test('test_std_filesystem_tempdir.cpp', cflags=['-g'])
1376613765

13767-
def test_strict_js_closure(self):
13768-
self.do_runf('hello_world.c', cflags=['-sSTRICT_JS', '-Werror=closure', '--closure=1', '-O3'])
13769-
1377013766
def test_em_js_deps(self):
1377113767
# Check that EM_JS_DEPS works. Specifically, multiple different instances in different
1377213768
# object files.

tools/link.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,9 +1147,10 @@ def limit_incoming_module_api():
11471147
elif options.shell_html:
11481148
diagnostics.warning('unused-command-line-argument', '--shell-file ignored when not generating html output')
11491149

1150+
if settings.EXPORT_ES6:
1151+
default_setting('STRICT_JS', 0)
1152+
11501153
if settings.STRICT:
1151-
if not settings.EXPORT_ES6:
1152-
default_setting('STRICT_JS', 1)
11531154
default_setting('DEFAULT_TO_CXX', 0)
11541155
default_setting('IGNORE_MISSING_MAIN', 0)
11551156
default_setting('AUTO_NATIVE_LIBRARIES', 0)

0 commit comments

Comments
 (0)