diff --git a/ChangeLog.md b/ChangeLog.md index 5728cfd5b67db..d110abab8dc6f 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -35,6 +35,10 @@ See docs/process.md for more on how version tagging works. - SDL2 port updated to include stub functions for `SDL_hid_init()` and related functions. (#26297) - libpng port updated from 1.6.39 to 1.6.55. (#26388) +- 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 maybe 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/lib/libglemu.js b/src/lib/libglemu.js index e5fcf78994d87..a76ce93f2b5c4 100644 --- a/src/lib/libglemu.js +++ b/src/lib/libglemu.js @@ -34,43 +34,41 @@ var LibraryGLEmulation = { 'glVertexAttribPointer', 'glActiveTexture', '$stringToNewUTF8', '$ptrToString', '$getEmscriptenSupportedExtensions', ], - $GLEmulation__postset: -#if MAYBE_CLOSURE_COMPILER - // Forward declare GL functions that are overridden by GLEmulation here to appease Closure compiler. - '/**@suppress {duplicate, undefinedVars}*/var _emscripten_glDrawArrays;' + - '/**@suppress {duplicate, undefinedVars}*/var _emscripten_glDrawElements;' + - '/**@suppress {duplicate, undefinedVars}*/var _emscripten_glActiveTexture;' + - '/**@suppress {duplicate, undefinedVars}*/var _emscripten_glEnable;' + - '/**@suppress {duplicate, undefinedVars}*/var _emscripten_glDisable;' + - '/**@suppress {duplicate, undefinedVars}*/var _emscripten_glTexEnvf;' + - '/**@suppress {duplicate, undefinedVars}*/var _emscripten_glTexEnvi;' + - '/**@suppress {duplicate, undefinedVars}*/var _emscripten_glTexEnvfv;' + - '/**@suppress {duplicate, undefinedVars}*/var _emscripten_glGetIntegerv;' + - '/**@suppress {duplicate, undefinedVars}*/var _emscripten_glIsEnabled;' + - '/**@suppress {duplicate, undefinedVars}*/var _emscripten_glGetBooleanv;' + - '/**@suppress {duplicate, undefinedVars}*/var _emscripten_glGetString;' + - '/**@suppress {duplicate, undefinedVars}*/var _emscripten_glCreateShader;' + - '/**@suppress {duplicate, undefinedVars}*/var _emscripten_glShaderSource;' + - '/**@suppress {duplicate, undefinedVars}*/var _emscripten_glCompileShader;' + - '/**@suppress {duplicate, undefinedVars}*/var _emscripten_glAttachShader;' + - '/**@suppress {duplicate, undefinedVars}*/var _emscripten_glDetachShader;' + - '/**@suppress {duplicate, undefinedVars}*/var _emscripten_glUseProgram;' + - '/**@suppress {duplicate, undefinedVars}*/var _emscripten_glDeleteProgram;' + - '/**@suppress {duplicate, undefinedVars}*/var _emscripten_glBindAttribLocation;' + - '/**@suppress {duplicate, undefinedVars}*/var _emscripten_glLinkProgram;' + - '/**@suppress {duplicate, undefinedVars}*/var _emscripten_glBindBuffer;' + - '/**@suppress {duplicate, undefinedVars}*/var _emscripten_glGetFloatv;' + - '/**@suppress {duplicate, undefinedVars}*/var _emscripten_glHint;' + - '/**@suppress {duplicate, undefinedVars}*/var _emscripten_glEnableVertexAttribArray;' + - '/**@suppress {duplicate, undefinedVars}*/var _emscripten_glDisableVertexAttribArray;' + - '/**@suppress {duplicate, undefinedVars}*/var _emscripten_glVertexAttribPointer;' + - '/**@suppress {duplicate, undefinedVars}*/var _glTexEnvf;' + - '/**@suppress {duplicate, undefinedVars}*/var _glTexEnvi;' + - '/**@suppress {duplicate, undefinedVars}*/var _glTexEnvfv;' + - '/**@suppress {duplicate, undefinedVars}*/var _glGetTexEnviv;' + - '/**@suppress {duplicate, undefinedVars}*/var _glGetTexEnvfv;' + -#endif - 'GLEmulation.init();', + $GLEmulation__postset: ` + // Forward declare GL functions that are overridden by GLEmulation. + /**@suppress {duplicate, undefinedVars}*/var _emscripten_glDrawArrays; + /**@suppress {duplicate, undefinedVars}*/var _emscripten_glDrawElements; + /**@suppress {duplicate, undefinedVars}*/var _emscripten_glActiveTexture; + /**@suppress {duplicate, undefinedVars}*/var _emscripten_glEnable; + /**@suppress {duplicate, undefinedVars}*/var _emscripten_glDisable; + /**@suppress {duplicate, undefinedVars}*/var _emscripten_glTexEnvf; + /**@suppress {duplicate, undefinedVars}*/var _emscripten_glTexEnvi; + /**@suppress {duplicate, undefinedVars}*/var _emscripten_glTexEnvfv; + /**@suppress {duplicate, undefinedVars}*/var _emscripten_glGetIntegerv; + /**@suppress {duplicate, undefinedVars}*/var _emscripten_glIsEnabled; + /**@suppress {duplicate, undefinedVars}*/var _emscripten_glGetBooleanv; + /**@suppress {duplicate, undefinedVars}*/var _emscripten_glGetString; + /**@suppress {duplicate, undefinedVars}*/var _emscripten_glCreateShader; + /**@suppress {duplicate, undefinedVars}*/var _emscripten_glShaderSource; + /**@suppress {duplicate, undefinedVars}*/var _emscripten_glCompileShader; + /**@suppress {duplicate, undefinedVars}*/var _emscripten_glAttachShader; + /**@suppress {duplicate, undefinedVars}*/var _emscripten_glDetachShader; + /**@suppress {duplicate, undefinedVars}*/var _emscripten_glUseProgram; + /**@suppress {duplicate, undefinedVars}*/var _emscripten_glDeleteProgram; + /**@suppress {duplicate, undefinedVars}*/var _emscripten_glBindAttribLocation; + /**@suppress {duplicate, undefinedVars}*/var _emscripten_glLinkProgram; + /**@suppress {duplicate, undefinedVars}*/var _emscripten_glBindBuffer; + /**@suppress {duplicate, undefinedVars}*/var _emscripten_glGetFloatv; + /**@suppress {duplicate, undefinedVars}*/var _emscripten_glHint; + /**@suppress {duplicate, undefinedVars}*/var _emscripten_glEnableVertexAttribArray; + /**@suppress {duplicate, undefinedVars}*/var _emscripten_glDisableVertexAttribArray; + /**@suppress {duplicate, undefinedVars}*/var _emscripten_glVertexAttribPointer; + /**@suppress {duplicate, undefinedVars}*/var _glTexEnvf; + /**@suppress {duplicate, undefinedVars}*/var _glTexEnvi; + /**@suppress {duplicate, undefinedVars}*/var _glTexEnvfv; + /**@suppress {duplicate, undefinedVars}*/var _glGetTexEnviv; + /**@suppress {duplicate, undefinedVars}*/var _glGetTexEnvfv; + GLEmulation.init();`, $GLEmulation: { // Fog support. Partial, we assume shaders are used that implement fog. We just pass them uniforms fogStart: 0, 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/browser/glut_touchevents.c b/test/browser/glut_touchevents.c index ddd6ad6b584c1..7214c2f4b2af7 100644 --- a/test/browser/glut_touchevents.c +++ b/test/browser/glut_touchevents.c @@ -68,7 +68,6 @@ int main(int argc, char *argv[]) touches.item = function(i) { return this[i]; }; var event = document.createEvent('UIEvent'); - event.target = Module['canvas']; event.button = 0; event.changedTouches = touches; event.initUIEvent(eventType, true, true, window, 1); 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/embind/test_pthreads.cpp b/test/embind/test_pthreads.cpp index 3a3939d2fb2ad..caa1f23feb794 100644 --- a/test/embind/test_pthreads.cpp +++ b/test/embind/test_pthreads.cpp @@ -8,7 +8,7 @@ using namespace emscripten; void thread(void) { EM_ASM({ - globalProperty = { + globalThis.globalProperty = { foo: function(value) { return value; } diff --git a/test/other/test_runtime_keepalive.cpp b/test/other/test_runtime_keepalive.cpp index 3bccbe9743484..9f1cf5fc450f3 100644 --- a/test/other/test_runtime_keepalive.cpp +++ b/test/other/test_runtime_keepalive.cpp @@ -8,7 +8,7 @@ int main() { Module["onExit"] = () => { out("onExit"); }; runtimeKeepalivePush(); out("runtimeKeepalivePush done"); - counter = 0; + var counter = 0; function timerCallback() { if (counter < 5) { runtimeKeepalivePush(); diff --git a/test/test_browser.py b/test/test_browser.py index 59a979bddcfff..92e54e944cd63 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -944,7 +944,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=['-sLEGACY_GL_EMULATION', '-lSDL', '-lGL'] + args) + self.btest_exit('test_sdl_canvas.c', cflags=['-sSTRICT_JS', '-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. @@ -1058,7 +1058,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']) + self.btest_exit('glut_touchevents.c', cflags=['-lglut', '-sSTRICT_JS']) def test_glut_wheelevents(self): self.btest_exit('glut_wheelevents.c', cflags=['-lglut']) diff --git a/test/test_core.py b/test/test_core.py index a55bf02c9b970..7708f24a8ebab 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -411,7 +411,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') @@ -6306,7 +6305,6 @@ def test_jslib(self): @with_env_modify({'LC_ALL': 'latin-1', 'PYTHONUTF8': '0', 'PYTHONCOERCECLOCALE': '0'}) @crossplatform @no_modularize_instance('uses MODULARIZE') - @no_strict_js('MODULARIZE is not compatible with STRICT_JS') @no_omit_asm_module_exports('MODULARIZE is not compatible with DECLARE_ASM_MODULE_EXPORTS=0') def test_unicode_js_library(self): # First verify that we have correct overridden the default python file encoding. @@ -8038,7 +8036,6 @@ def get_wat_addr(call_index): @no_omit_asm_module_exports('MODULARIZE is not compatible with DECLARE_ASM_MODULE_EXPORTS=0') @no_modularize_instance('uses -sMODULARIZE') - @no_strict_js('MODULARIZE is not compatible with STRICT_JS') def test_modularize_closure_pre(self): # test that the combination of modularize + closure + pre-js works. in that mode, # 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): self.do_core_test('test_asan_api.c', cflags=['-fsanitize=address']) @asan - @no_strict_js('MODULARIZE is not compatible with STRICT_JS') @no_omit_asm_module_exports('MODULARIZE is not compatible with DECLARE_ASM_MODULE_EXPORTS=0') @no_modularize_instance('uses MODULARIZE') def test_asan_modularized_with_closure(self): @@ -9680,7 +9676,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('MODULARIZE 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']) @@ -9689,7 +9684,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('MODULARIZE is not compatible with STRICT_JS') def test_modularize_instance(self, args): if args: self.require_pthreads() @@ -9725,7 +9719,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('MODULARIZE is not compatible with STRICT_JS') def test_modularize_instance_embind(self): self.run_process([EMXX, test_file('modularize_instance_embind.cpp'), '-sMODULARIZE=instance', @@ -9905,7 +9898,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/tools/link.py b/tools/link.py index 451a6541a1de0..3a97cfcb4d4b3 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 or settings.MODULARIZE: + default_setting('STRICT_JS', 0) + if settings.STRICT: - if not settings.MODULARIZE: - default_setting('STRICT_JS', 1) default_setting('DEFAULT_TO_CXX', 0) default_setting('IGNORE_MISSING_MAIN', 0) default_setting('AUTO_NATIVE_LIBRARIES', 0)