diff --git a/ChangeLog.md b/ChangeLog.md index 817629e1f8f9e..884dacf21ab05 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -39,6 +39,10 @@ See docs/process.md for more on how version tagging works. functions. (#26297) - libpng port updated from 1.6.39 to 1.6.55. (#26388) - Added sdl3_ttf port. (#24601) +- The `STRICT_JS` setting is now on by default. Previously it was enabled by + default in `STRICT` mode. If you have EM_ASM or EM_JS or `--pre-js` code + that does not conform to JS strict mode then you may need to disable this + with `-sSTRICT_JS=0`. (#26421) 5.0.2 - 02/25/26 ---------------- diff --git a/site/source/docs/tools_reference/settings_reference.rst b/site/source/docs/tools_reference/settings_reference.rst index 89f79600b845c..26648970ac345 100644 --- a/site/source/docs/tools_reference/settings_reference.rst +++ b/site/source/docs/tools_reference/settings_reference.rst @@ -1703,7 +1703,6 @@ Changes enabled by this: - The C define EMSCRIPTEN is not defined (__EMSCRIPTEN__ always is, and is the correct thing to use). - - STRICT_JS is enabled. - IGNORE_MISSING_MAIN is disabled. - AUTO_JS_LIBRARIES is disabled. - AUTO_NATIVE_LIBRARIES is disabled. @@ -1734,7 +1733,7 @@ STRICT_JS Add ``"use strict;"`` to generated JS -Default value: false +Default value: true .. _warn_on_undefined_symbols: diff --git a/src/settings.js b/src/settings.js index e7148433a5f94..57466bbd4f34e 100644 --- a/src/settings.js +++ b/src/settings.js @@ -1162,7 +1162,6 @@ var LINKABLE = false; // // - The C define EMSCRIPTEN is not defined (__EMSCRIPTEN__ always is, and // is the correct thing to use). -// - STRICT_JS is enabled. // - IGNORE_MISSING_MAIN is disabled. // - AUTO_JS_LIBRARIES is disabled. // - AUTO_NATIVE_LIBRARIES is disabled. @@ -1181,7 +1180,7 @@ var IGNORE_MISSING_MAIN = true; // Add ``"use strict;"`` to generated JS // [link] -var STRICT_JS = false; +var STRICT_JS = true; // If set to 1, we will warn on any undefined symbols that are not resolved by // the ``library_*.js`` files. Note that it is common in large projects to not diff --git a/test/codesize/test_unoptimized_code_size.json b/test/codesize/test_unoptimized_code_size.json index 635a347810bec..e03c36608f744 100644 --- a/test/codesize/test_unoptimized_code_size.json +++ b/test/codesize/test_unoptimized_code_size.json @@ -1,16 +1,16 @@ { - "hello_world.js": 57007, - "hello_world.js.gz": 17736, + "hello_world.js": 57022, + "hello_world.js.gz": 17744, "hello_world.wasm": 15138, "hello_world.wasm.gz": 7455, - "no_asserts.js": 26576, - "no_asserts.js.gz": 8881, + "no_asserts.js": 26591, + "no_asserts.js.gz": 8894, "no_asserts.wasm": 12187, "no_asserts.wasm.gz": 5984, "strict.js": 54825, "strict.js.gz": 17039, "strict.wasm": 15138, "strict.wasm.gz": 7450, - "total": 180871, - "total_gz": 64545 + "total": 180901, + "total_gz": 64566 } diff --git a/test/test_browser.py b/test/test_browser.py index 234d24b305287..d0f63f7e803d0 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -945,7 +945,7 @@ def test_sdl_stb_image_cleanup(self): 'safe_heap_O2': (['-sSAFE_HEAP', '-O2'],), }) def test_sdl_canvas(self, args): - self.btest_exit('test_sdl_canvas.c', cflags=['-sSTRICT_JS', '-sLEGACY_GL_EMULATION', '-lSDL', '-lGL'] + args) + self.btest_exit('test_sdl_canvas.c', cflags=['-sLEGACY_GL_EMULATION', '-lSDL', '-lGL'] + args) def test_sdl_canvas_alpha(self): # 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): self.run_browser('page.html', '', '/report_result?exit:0') def test_glut_touchevents(self): - self.btest_exit('glut_touchevents.c', cflags=['-lglut', '-sSTRICT_JS']) + self.btest_exit('glut_touchevents.c', cflags=['-lglut']) def test_glut_wheelevents(self): self.btest_exit('glut_wheelevents.c', cflags=['-lglut']) @@ -4953,7 +4953,6 @@ def test_no_declare_asm_module_exports_wasm2js(self, args): @parameterized({ '': ([],), - 'strict_js': (['-sSTRICT_JS'],), 'minimal_runtime': (['-sMINIMAL_RUNTIME=1'],), 'minimal_runtime_2': (['-sMINIMAL_RUNTIME=2'],), }) @@ -5416,8 +5415,8 @@ def test_pthread_unhandledrejection(self): def test_pthread_key_recreation(self): self.btest_exit('pthread/test_pthread_key_recreation.c', cflags=['-pthread', '-sPTHREAD_POOL_SIZE=1']) - def test_full_js_library_strict(self): - self.btest_exit('hello_world.c', cflags=['-sINCLUDE_FULL_LIBRARY', '-sSTRICT_JS']) + def test_full_js_library(self): + self.btest_exit('hello_world.c', cflags=['-sINCLUDE_FULL_LIBRARY']) # Tests the AudioWorklet demo @parameterized({ diff --git a/test/test_core.py b/test/test_core.py index c517d88fb4552..2b9d7593e1e44 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -429,7 +429,6 @@ def decorated(self, textdecoder, *args, **kwargs): no_safe_heap = make_no_decorator_for_setting('SAFE_HEAP') no_strict = make_no_decorator_for_setting('STRICT') -no_strict_js = make_no_decorator_for_setting('STRICT_JS') no_big_endian = make_no_decorator_for_setting('SUPPORT_BIG_ENDIAN') no_omit_asm_module_exports = make_no_decorator_for_setting('DECLARE_ASM_MODULE_EXPORTS=0') no_js_math = make_no_decorator_for_setting('JS_MATH') @@ -9714,7 +9713,6 @@ def test_esm_integration(self): self.assertFileContents(test_file('core/test_esm_integration.expected.mjs'), read_file('hello_world.mjs')) @no_omit_asm_module_exports('MODULARIZE is not compatible with DECLARE_ASM_MODULE_EXPORTS=0') - @no_strict_js('EXPORT_ES6 is not compatible with STRICT_JS') def test_modularize_instance_hello(self): self.do_core_test('test_hello_world.c', cflags=['-sMODULARIZE=instance', '-Wno-experimental']) @@ -9723,7 +9721,6 @@ def test_modularize_instance_hello(self): 'pthreads': (['-pthread'],), }) @no_omit_asm_module_exports('MODULARIZE is not compatible with DECLARE_ASM_MODULE_EXPORTS=0') - @no_strict_js('EXPORT_ES6 is not compatible with STRICT_JS') def test_modularize_instance(self, args): if args: self.require_pthreads() @@ -9759,7 +9756,6 @@ def test_modularize_instance(self, args): @no_omit_asm_module_exports('MODULARIZE is not compatible with DECLARE_ASM_MODULE_EXPORTS=0') @no_4gb('EMBIND_AOT can\'t lower 4gb') - @no_strict_js('EXPORT_ES6 is not compatible with STRICT_JS') def test_modularize_instance_embind(self): self.run_process([EMXX, test_file('modularize_instance_embind.cpp'), '-sMODULARIZE=instance', @@ -9940,7 +9936,6 @@ def setUp(self): # Add DEFAULT_TO_CXX=0 strict = make_run('strict', cflags=[], settings={'STRICT': 1}) -strict_js = make_run('strict_js', cflags=[], settings={'STRICT_JS': 1}) ubsan = make_run('ubsan', cflags=['-fsanitize=undefined', '--profiling']) lsan = make_run('lsan', cflags=['-fsanitize=leak', '--profiling'], settings={'ALLOW_MEMORY_GROWTH': 1}) diff --git a/test/test_other.py b/test/test_other.py index 971eea354e4bd..3fa31ceb5d9f1 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -3374,7 +3374,6 @@ def test_embind_subclass_pointer(self): 'o2': ['-O2'], 'o2_mem_growth': ['-O2', '-sALLOW_MEMORY_GROWTH', test_file('embind/isMemoryGrowthEnabled=true.cpp')], 'o2_closure': ['-O2', '--closure=1', '--closure-args', '--externs ' + shlex.quote(test_file('embind/underscore-externs.js')), '-sASSERTIONS=1'], - 'strict_js': ['-sSTRICT_JS'], # DYNCALLS tests the legacy native function API (ASYNCIFY implicitly enables DYNCALLS) 'dyncalls': ['-sDYNCALLS=1'], }) @@ -9005,11 +9004,11 @@ def test(check, extra): 'embind': (['-lembind'],), }) def test_full_js_library(self, args): - self.run_process([EMCC, test_file('hello_world.c'), '-sSTRICT_JS', '-sINCLUDE_FULL_LIBRARY'] + args) + self.run_process([EMCC, test_file('hello_world.c'), '-sINCLUDE_FULL_LIBRARY'] + args) def test_full_js_library_undefined(self): create_file('main.c', 'void foo(); int main() { foo(); return 0; }') - self.assert_fail([EMCC, 'main.c', '-sSTRICT_JS', '-sINCLUDE_FULL_LIBRARY'], 'undefined symbol: foo') + self.assert_fail([EMCC, 'main.c', '-sINCLUDE_FULL_LIBRARY'], 'undefined symbol: foo') def test_full_js_library_except(self): self.set_setting('INCLUDE_FULL_LIBRARY', 1) @@ -13753,9 +13752,6 @@ def test_std_filesystem_tempdir(self): self.skipTest('https://github.com/emscripten-core/emscripten/issues/24830') self.do_other_test('test_std_filesystem_tempdir.cpp', cflags=['-g']) - def test_strict_js_closure(self): - self.do_runf('hello_world.c', cflags=['-sSTRICT_JS', '-Werror=closure', '--closure=1', '-O3']) - def test_em_js_deps(self): # Check that EM_JS_DEPS works. Specifically, multiple different instances in different # object files. diff --git a/tools/link.py b/tools/link.py index bf8557e3ea27b..376cc8c0c4bf2 100644 --- a/tools/link.py +++ b/tools/link.py @@ -1147,9 +1147,10 @@ def limit_incoming_module_api(): elif options.shell_html: diagnostics.warning('unused-command-line-argument', '--shell-file ignored when not generating html output') + if settings.EXPORT_ES6: + default_setting('STRICT_JS', 0) + if settings.STRICT: - if not settings.EXPORT_ES6: - default_setting('STRICT_JS', 1) default_setting('DEFAULT_TO_CXX', 0) default_setting('IGNORE_MISSING_MAIN', 0) default_setting('AUTO_NATIVE_LIBRARIES', 0)