Skip to content

Commit f996d5c

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 cb060ca commit f996d5c

File tree

8 files changed

+21
-28
lines changed

8 files changed

+21
-28
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ See docs/process.md for more on how version tagging works.
3939
functions. (#26297)
4040
- libpng port updated from 1.6.39 to 1.6.55. (#26388)
4141
- Added sdl3_ttf port. (#24601)
42+
- The `STRICT_JS` setting is now on by default. Previously it was enabled by
43+
default in `STRICT` mode. If you have EM_ASM or EM_JS or `--pre-js` code
44+
that does not conform to JS strict mode then you may need to disable this
45+
with `-sSTRICT_JS=0`. (#26421)
4246

4347
5.0.2 - 02/25/26
4448
----------------

site/source/docs/tools_reference/settings_reference.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,7 +1703,6 @@ Changes enabled by this:
17031703

17041704
- The C define EMSCRIPTEN is not defined (__EMSCRIPTEN__ always is, and
17051705
is the correct thing to use).
1706-
- STRICT_JS is enabled.
17071706
- IGNORE_MISSING_MAIN is disabled.
17081707
- AUTO_JS_LIBRARIES is disabled.
17091708
- AUTO_NATIVE_LIBRARIES is disabled.
@@ -1734,7 +1733,7 @@ STRICT_JS
17341733

17351734
Add ``"use strict;"`` to generated JS
17361735

1737-
Default value: false
1736+
Default value: true
17381737

17391738
.. _warn_on_undefined_symbols:
17401739

src/settings.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,6 @@ var LINKABLE = false;
11621162
//
11631163
// - The C define EMSCRIPTEN is not defined (__EMSCRIPTEN__ always is, and
11641164
// is the correct thing to use).
1165-
// - STRICT_JS is enabled.
11661165
// - IGNORE_MISSING_MAIN is disabled.
11671166
// - AUTO_JS_LIBRARIES is disabled.
11681167
// - AUTO_NATIVE_LIBRARIES is disabled.
@@ -1181,7 +1180,7 @@ var IGNORE_MISSING_MAIN = true;
11811180

11821181
// Add ``"use strict;"`` to generated JS
11831182
// [link]
1184-
var STRICT_JS = false;
1183+
var STRICT_JS = true;
11851184

11861185
// If set to 1, we will warn on any undefined symbols that are not resolved by
11871186
// the ``library_*.js`` files. Note that it is common in large projects to not
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
2-
"hello_world.js": 57007,
3-
"hello_world.js.gz": 17736,
2+
"hello_world.js": 57022,
3+
"hello_world.js.gz": 17744,
44
"hello_world.wasm": 15138,
55
"hello_world.wasm.gz": 7455,
6-
"no_asserts.js": 26576,
7-
"no_asserts.js.gz": 8881,
6+
"no_asserts.js": 26591,
7+
"no_asserts.js.gz": 8894,
88
"no_asserts.wasm": 12187,
99
"no_asserts.wasm.gz": 5984,
1010
"strict.js": 54825,
1111
"strict.js.gz": 17039,
1212
"strict.wasm": 15138,
1313
"strict.wasm.gz": 7450,
14-
"total": 180871,
15-
"total_gz": 64545
14+
"total": 180901,
15+
"total_gz": 64566
1616
}

test/test_browser.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ def test_sdl_stb_image_cleanup(self):
945945
'safe_heap_O2': (['-sSAFE_HEAP', '-O2'],),
946946
})
947947
def test_sdl_canvas(self, args):
948-
self.btest_exit('test_sdl_canvas.c', cflags=['-sSTRICT_JS', '-sLEGACY_GL_EMULATION', '-lSDL', '-lGL'] + args)
948+
self.btest_exit('test_sdl_canvas.c', cflags=['-sLEGACY_GL_EMULATION', '-lSDL', '-lGL'] + args)
949949

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

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

10641064
def test_glut_wheelevents(self):
10651065
self.btest_exit('glut_wheelevents.c', cflags=['-lglut'])
@@ -4953,7 +4953,6 @@ def test_no_declare_asm_module_exports_wasm2js(self, args):
49534953

49544954
@parameterized({
49554955
'': ([],),
4956-
'strict_js': (['-sSTRICT_JS'],),
49574956
'minimal_runtime': (['-sMINIMAL_RUNTIME=1'],),
49584957
'minimal_runtime_2': (['-sMINIMAL_RUNTIME=2'],),
49594958
})
@@ -5416,8 +5415,8 @@ def test_pthread_unhandledrejection(self):
54165415
def test_pthread_key_recreation(self):
54175416
self.btest_exit('pthread/test_pthread_key_recreation.c', cflags=['-pthread', '-sPTHREAD_POOL_SIZE=1'])
54185417

5419-
def test_full_js_library_strict(self):
5420-
self.btest_exit('hello_world.c', cflags=['-sINCLUDE_FULL_LIBRARY', '-sSTRICT_JS'])
5418+
def test_full_js_library(self):
5419+
self.btest_exit('hello_world.c', cflags=['-sINCLUDE_FULL_LIBRARY'])
54215420

54225421
# Tests the AudioWorklet demo
54235422
@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')
@@ -9714,7 +9713,6 @@ def test_esm_integration(self):
97149713
self.assertFileContents(test_file('core/test_esm_integration.expected.mjs'), read_file('hello_world.mjs'))
97159714

97169715
@no_omit_asm_module_exports('MODULARIZE is not compatible with DECLARE_ASM_MODULE_EXPORTS=0')
9717-
@no_strict_js('EXPORT_ES6 is not compatible with STRICT_JS')
97189716
def test_modularize_instance_hello(self):
97199717
self.do_core_test('test_hello_world.c', cflags=['-sMODULARIZE=instance', '-Wno-experimental'])
97209718

@@ -9723,7 +9721,6 @@ def test_modularize_instance_hello(self):
97239721
'pthreads': (['-pthread'],),
97249722
})
97259723
@no_omit_asm_module_exports('MODULARIZE is not compatible with DECLARE_ASM_MODULE_EXPORTS=0')
9726-
@no_strict_js('EXPORT_ES6 is not compatible with STRICT_JS')
97279724
def test_modularize_instance(self, args):
97289725
if args:
97299726
self.require_pthreads()
@@ -9759,7 +9756,6 @@ def test_modularize_instance(self, args):
97599756

97609757
@no_omit_asm_module_exports('MODULARIZE is not compatible with DECLARE_ASM_MODULE_EXPORTS=0')
97619758
@no_4gb('EMBIND_AOT can\'t lower 4gb')
9762-
@no_strict_js('EXPORT_ES6 is not compatible with STRICT_JS')
97639759
def test_modularize_instance_embind(self):
97649760
self.run_process([EMXX, test_file('modularize_instance_embind.cpp'),
97659761
'-sMODULARIZE=instance',
@@ -9940,7 +9936,6 @@ def setUp(self):
99409936

99419937
# Add DEFAULT_TO_CXX=0
99429938
strict = make_run('strict', cflags=[], settings={'STRICT': 1})
9943-
strict_js = make_run('strict_js', cflags=[], settings={'STRICT_JS': 1})
99449939

99459940
ubsan = make_run('ubsan', cflags=['-fsanitize=undefined', '--profiling'])
99469941
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
})
@@ -9005,11 +9004,11 @@ def test(check, extra):
90059004
'embind': (['-lembind'],),
90069005
})
90079006
def test_full_js_library(self, args):
9008-
self.run_process([EMCC, test_file('hello_world.c'), '-sSTRICT_JS', '-sINCLUDE_FULL_LIBRARY'] + args)
9007+
self.run_process([EMCC, test_file('hello_world.c'), '-sINCLUDE_FULL_LIBRARY'] + args)
90099008

90109009
def test_full_js_library_undefined(self):
90119010
create_file('main.c', 'void foo(); int main() { foo(); return 0; }')
9012-
self.assert_fail([EMCC, 'main.c', '-sSTRICT_JS', '-sINCLUDE_FULL_LIBRARY'], 'undefined symbol: foo')
9011+
self.assert_fail([EMCC, 'main.c', '-sINCLUDE_FULL_LIBRARY'], 'undefined symbol: foo')
90139012

90149013
def test_full_js_library_except(self):
90159014
self.set_setting('INCLUDE_FULL_LIBRARY', 1)
@@ -13753,9 +13752,6 @@ def test_std_filesystem_tempdir(self):
1375313752
self.skipTest('https://github.com/emscripten-core/emscripten/issues/24830')
1375413753
self.do_other_test('test_std_filesystem_tempdir.cpp', cflags=['-g'])
1375513754

13756-
def test_strict_js_closure(self):
13757-
self.do_runf('hello_world.c', cflags=['-sSTRICT_JS', '-Werror=closure', '--closure=1', '-O3'])
13758-
1375913755
def test_em_js_deps(self):
1376013756
# Check that EM_JS_DEPS works. Specifically, multiple different instances in different
1376113757
# 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)