Skip to content

Commit 2f86cdf

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 a699999 commit 2f86cdf

File tree

8 files changed

+21
-31
lines changed

8 files changed

+21
-31
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ See docs/process.md for more on how version tagging works.
3535
- SDL2 port updated to include stub functions for `SDL_hid_init()` and related
3636
functions. (#26297)
3737
- libpng port updated from 1.6.39 to 1.6.55. (#26388)
38+
- The `STRICT_JS` setting is now on by default. Previously it was enabled by
39+
default in `STRICT` mode. If you have EM_ASM or EM_JS or `--pre-js` code
40+
that does not conform to JS strict mode then you may need to disable this
41+
with `-sSTRICT_JS=0`. (#26421)
3842

3943
5.0.2 - 02/25/26
4044
----------------

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
@@ -944,7 +944,7 @@ def test_sdl_stb_image_cleanup(self):
944944
'safe_heap_O2': (['-sSAFE_HEAP', '-O2'],),
945945
})
946946
def test_sdl_canvas(self, args):
947-
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)
948948

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

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

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

49394939
@parameterized({
49404940
'': ([],),
4941-
'strict_js': (['-sSTRICT_JS'],),
49424941
'minimal_runtime': (['-sMINIMAL_RUNTIME=1'],),
49434942
'minimal_runtime_2': (['-sMINIMAL_RUNTIME=2'],),
49444943
})
@@ -5401,8 +5400,8 @@ def test_pthread_unhandledrejection(self):
54015400
def test_pthread_key_recreation(self):
54025401
self.btest_exit('pthread/test_pthread_key_recreation.c', cflags=['-pthread', '-sPTHREAD_POOL_SIZE=1'])
54035402

5404-
def test_full_js_library_strict(self):
5405-
self.btest_exit('hello_world.c', cflags=['-sINCLUDE_FULL_LIBRARY', '-sSTRICT_JS'])
5403+
def test_full_js_library(self):
5404+
self.btest_exit('hello_world.c', cflags=['-sINCLUDE_FULL_LIBRARY'])
54065405

54075406
# Tests the AudioWorklet demo
54085407
@parameterized({

test/test_core.py

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

412412
no_safe_heap = make_no_decorator_for_setting('SAFE_HEAP')
413413
no_strict = make_no_decorator_for_setting('STRICT')
414-
no_strict_js = make_no_decorator_for_setting('STRICT_JS')
415414
no_big_endian = make_no_decorator_for_setting('SUPPORT_BIG_ENDIAN')
416415
no_omit_asm_module_exports = make_no_decorator_for_setting('DECLARE_ASM_MODULE_EXPORTS=0')
417416
no_js_math = make_no_decorator_for_setting('JS_MATH')
@@ -6306,7 +6305,6 @@ def test_jslib(self):
63066305
@with_env_modify({'LC_ALL': 'latin-1', 'PYTHONUTF8': '0', 'PYTHONCOERCECLOCALE': '0'})
63076306
@crossplatform
63086307
@no_modularize_instance('uses MODULARIZE')
6309-
@no_strict_js('MODULARIZE is not compatible with STRICT_JS')
63106308
@no_omit_asm_module_exports('MODULARIZE is not compatible with DECLARE_ASM_MODULE_EXPORTS=0')
63116309
def test_unicode_js_library(self):
63126310
# First verify that we have correct overridden the default python file encoding.
@@ -8038,7 +8036,6 @@ def get_wat_addr(call_index):
80388036

80398037
@no_omit_asm_module_exports('MODULARIZE is not compatible with DECLARE_ASM_MODULE_EXPORTS=0')
80408038
@no_modularize_instance('uses -sMODULARIZE')
8041-
@no_strict_js('MODULARIZE is not compatible with STRICT_JS')
80428039
def test_modularize_closure_pre(self):
80438040
# test that the combination of modularize + closure + pre-js works. in that mode,
80448041
# closure should not minify the Module object in a way that the pre-js cannot use it.
@@ -8985,7 +8982,6 @@ def test_asan_api(self):
89858982
self.do_core_test('test_asan_api.c', cflags=['-fsanitize=address'])
89868983

89878984
@asan
8988-
@no_strict_js('MODULARIZE is not compatible with STRICT_JS')
89898985
@no_omit_asm_module_exports('MODULARIZE is not compatible with DECLARE_ASM_MODULE_EXPORTS=0')
89908986
@no_modularize_instance('uses MODULARIZE')
89918987
def test_asan_modularized_with_closure(self):
@@ -9680,7 +9676,6 @@ def test_esm_integration(self):
96809676
self.assertFileContents(test_file('core/test_esm_integration.expected.mjs'), read_file('hello_world.mjs'))
96819677

96829678
@no_omit_asm_module_exports('MODULARIZE is not compatible with DECLARE_ASM_MODULE_EXPORTS=0')
9683-
@no_strict_js('MODULARIZE is not compatible with STRICT_JS')
96849679
def test_modularize_instance_hello(self):
96859680
self.do_core_test('test_hello_world.c', cflags=['-sMODULARIZE=instance', '-Wno-experimental'])
96869681

@@ -9689,7 +9684,6 @@ def test_modularize_instance_hello(self):
96899684
'pthreads': (['-pthread'],),
96909685
})
96919686
@no_omit_asm_module_exports('MODULARIZE is not compatible with DECLARE_ASM_MODULE_EXPORTS=0')
9692-
@no_strict_js('MODULARIZE is not compatible with STRICT_JS')
96939687
def test_modularize_instance(self, args):
96949688
if args:
96959689
self.require_pthreads()
@@ -9725,7 +9719,6 @@ def test_modularize_instance(self, args):
97259719

97269720
@no_omit_asm_module_exports('MODULARIZE is not compatible with DECLARE_ASM_MODULE_EXPORTS=0')
97279721
@no_4gb('EMBIND_AOT can\'t lower 4gb')
9728-
@no_strict_js('MODULARIZE is not compatible with STRICT_JS')
97299722
def test_modularize_instance_embind(self):
97309723
self.run_process([EMXX, test_file('modularize_instance_embind.cpp'),
97319724
'-sMODULARIZE=instance',
@@ -9905,7 +9898,6 @@ def setUp(self):
99059898

99069899
# Add DEFAULT_TO_CXX=0
99079900
strict = make_run('strict', cflags=[], settings={'STRICT': 1})
9908-
strict_js = make_run('strict_js', cflags=[], settings={'STRICT_JS': 1})
99099901

99109902
ubsan = make_run('ubsan', cflags=['-fsanitize=undefined', '--profiling'])
99119903
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
@@ -3451,7 +3451,6 @@ def test_embind_subclass_pointer(self):
34513451
'o2': ['-O2'],
34523452
'o2_mem_growth': ['-O2', '-sALLOW_MEMORY_GROWTH', test_file('embind/isMemoryGrowthEnabled=true.cpp')],
34533453
'o2_closure': ['-O2', '--closure=1', '--closure-args', '--externs ' + shlex.quote(test_file('embind/underscore-externs.js')), '-sASSERTIONS=1'],
3454-
'strict_js': ['-sSTRICT_JS'],
34553454
# DYNCALLS tests the legacy native function API (ASYNCIFY implicitly enables DYNCALLS)
34563455
'dyncalls': ['-sDYNCALLS=1'],
34573456
})
@@ -9083,11 +9082,11 @@ def test(check, extra):
90839082
'embind': (['-lembind'],),
90849083
})
90859084
def test_full_js_library(self, args):
9086-
self.run_process([EMCC, test_file('hello_world.c'), '-sSTRICT_JS', '-sINCLUDE_FULL_LIBRARY'] + args)
9085+
self.run_process([EMCC, test_file('hello_world.c'), '-sINCLUDE_FULL_LIBRARY'] + args)
90879086

90889087
def test_full_js_library_undefined(self):
90899088
create_file('main.c', 'void foo(); int main() { foo(); return 0; }')
9090-
self.assert_fail([EMCC, 'main.c', '-sSTRICT_JS', '-sINCLUDE_FULL_LIBRARY'], 'undefined symbol: foo')
9089+
self.assert_fail([EMCC, 'main.c', '-sINCLUDE_FULL_LIBRARY'], 'undefined symbol: foo')
90919090

90929091
def test_full_js_library_except(self):
90939092
self.set_setting('INCLUDE_FULL_LIBRARY', 1)
@@ -13830,9 +13829,6 @@ def test_std_filesystem_tempdir(self):
1383013829
self.skipTest('https://github.com/emscripten-core/emscripten/issues/24830')
1383113830
self.do_other_test('test_std_filesystem_tempdir.cpp', cflags=['-g'])
1383213831

13833-
def test_strict_js_closure(self):
13834-
self.do_runf('hello_world.c', cflags=['-sSTRICT_JS', '-Werror=closure', '--closure=1', '-O3'])
13835-
1383613832
def test_em_js_deps(self):
1383713833
# Check that EM_JS_DEPS works. Specifically, multiple different instances in different
1383813834
# 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 or settings.MODULARIZE:
1151+
default_setting('STRICT_JS', 0)
1152+
11501153
if settings.STRICT:
1151-
if not settings.MODULARIZE:
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)