Skip to content

Commit 3431363

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 50f14d6 commit 3431363

File tree

11 files changed

+54
-62
lines changed

11 files changed

+54
-62
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 maybe 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/lib/libglemu.js

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -34,43 +34,41 @@ var LibraryGLEmulation = {
3434
'glVertexAttribPointer', 'glActiveTexture', '$stringToNewUTF8',
3535
'$ptrToString', '$getEmscriptenSupportedExtensions',
3636
],
37-
$GLEmulation__postset:
38-
#if MAYBE_CLOSURE_COMPILER
39-
// Forward declare GL functions that are overridden by GLEmulation here to appease Closure compiler.
40-
'/**@suppress {duplicate, undefinedVars}*/var _emscripten_glDrawArrays;' +
41-
'/**@suppress {duplicate, undefinedVars}*/var _emscripten_glDrawElements;' +
42-
'/**@suppress {duplicate, undefinedVars}*/var _emscripten_glActiveTexture;' +
43-
'/**@suppress {duplicate, undefinedVars}*/var _emscripten_glEnable;' +
44-
'/**@suppress {duplicate, undefinedVars}*/var _emscripten_glDisable;' +
45-
'/**@suppress {duplicate, undefinedVars}*/var _emscripten_glTexEnvf;' +
46-
'/**@suppress {duplicate, undefinedVars}*/var _emscripten_glTexEnvi;' +
47-
'/**@suppress {duplicate, undefinedVars}*/var _emscripten_glTexEnvfv;' +
48-
'/**@suppress {duplicate, undefinedVars}*/var _emscripten_glGetIntegerv;' +
49-
'/**@suppress {duplicate, undefinedVars}*/var _emscripten_glIsEnabled;' +
50-
'/**@suppress {duplicate, undefinedVars}*/var _emscripten_glGetBooleanv;' +
51-
'/**@suppress {duplicate, undefinedVars}*/var _emscripten_glGetString;' +
52-
'/**@suppress {duplicate, undefinedVars}*/var _emscripten_glCreateShader;' +
53-
'/**@suppress {duplicate, undefinedVars}*/var _emscripten_glShaderSource;' +
54-
'/**@suppress {duplicate, undefinedVars}*/var _emscripten_glCompileShader;' +
55-
'/**@suppress {duplicate, undefinedVars}*/var _emscripten_glAttachShader;' +
56-
'/**@suppress {duplicate, undefinedVars}*/var _emscripten_glDetachShader;' +
57-
'/**@suppress {duplicate, undefinedVars}*/var _emscripten_glUseProgram;' +
58-
'/**@suppress {duplicate, undefinedVars}*/var _emscripten_glDeleteProgram;' +
59-
'/**@suppress {duplicate, undefinedVars}*/var _emscripten_glBindAttribLocation;' +
60-
'/**@suppress {duplicate, undefinedVars}*/var _emscripten_glLinkProgram;' +
61-
'/**@suppress {duplicate, undefinedVars}*/var _emscripten_glBindBuffer;' +
62-
'/**@suppress {duplicate, undefinedVars}*/var _emscripten_glGetFloatv;' +
63-
'/**@suppress {duplicate, undefinedVars}*/var _emscripten_glHint;' +
64-
'/**@suppress {duplicate, undefinedVars}*/var _emscripten_glEnableVertexAttribArray;' +
65-
'/**@suppress {duplicate, undefinedVars}*/var _emscripten_glDisableVertexAttribArray;' +
66-
'/**@suppress {duplicate, undefinedVars}*/var _emscripten_glVertexAttribPointer;' +
67-
'/**@suppress {duplicate, undefinedVars}*/var _glTexEnvf;' +
68-
'/**@suppress {duplicate, undefinedVars}*/var _glTexEnvi;' +
69-
'/**@suppress {duplicate, undefinedVars}*/var _glTexEnvfv;' +
70-
'/**@suppress {duplicate, undefinedVars}*/var _glGetTexEnviv;' +
71-
'/**@suppress {duplicate, undefinedVars}*/var _glGetTexEnvfv;' +
72-
#endif
73-
'GLEmulation.init();',
37+
$GLEmulation__postset: `
38+
// Forward declare GL functions that are overridden by GLEmulation.
39+
/**@suppress {duplicate, undefinedVars}*/var _emscripten_glDrawArrays;
40+
/**@suppress {duplicate, undefinedVars}*/var _emscripten_glDrawElements;
41+
/**@suppress {duplicate, undefinedVars}*/var _emscripten_glActiveTexture;
42+
/**@suppress {duplicate, undefinedVars}*/var _emscripten_glEnable;
43+
/**@suppress {duplicate, undefinedVars}*/var _emscripten_glDisable;
44+
/**@suppress {duplicate, undefinedVars}*/var _emscripten_glTexEnvf;
45+
/**@suppress {duplicate, undefinedVars}*/var _emscripten_glTexEnvi;
46+
/**@suppress {duplicate, undefinedVars}*/var _emscripten_glTexEnvfv;
47+
/**@suppress {duplicate, undefinedVars}*/var _emscripten_glGetIntegerv;
48+
/**@suppress {duplicate, undefinedVars}*/var _emscripten_glIsEnabled;
49+
/**@suppress {duplicate, undefinedVars}*/var _emscripten_glGetBooleanv;
50+
/**@suppress {duplicate, undefinedVars}*/var _emscripten_glGetString;
51+
/**@suppress {duplicate, undefinedVars}*/var _emscripten_glCreateShader;
52+
/**@suppress {duplicate, undefinedVars}*/var _emscripten_glShaderSource;
53+
/**@suppress {duplicate, undefinedVars}*/var _emscripten_glCompileShader;
54+
/**@suppress {duplicate, undefinedVars}*/var _emscripten_glAttachShader;
55+
/**@suppress {duplicate, undefinedVars}*/var _emscripten_glDetachShader;
56+
/**@suppress {duplicate, undefinedVars}*/var _emscripten_glUseProgram;
57+
/**@suppress {duplicate, undefinedVars}*/var _emscripten_glDeleteProgram;
58+
/**@suppress {duplicate, undefinedVars}*/var _emscripten_glBindAttribLocation;
59+
/**@suppress {duplicate, undefinedVars}*/var _emscripten_glLinkProgram;
60+
/**@suppress {duplicate, undefinedVars}*/var _emscripten_glBindBuffer;
61+
/**@suppress {duplicate, undefinedVars}*/var _emscripten_glGetFloatv;
62+
/**@suppress {duplicate, undefinedVars}*/var _emscripten_glHint;
63+
/**@suppress {duplicate, undefinedVars}*/var _emscripten_glEnableVertexAttribArray;
64+
/**@suppress {duplicate, undefinedVars}*/var _emscripten_glDisableVertexAttribArray;
65+
/**@suppress {duplicate, undefinedVars}*/var _emscripten_glVertexAttribPointer;
66+
/**@suppress {duplicate, undefinedVars}*/var _glTexEnvf;
67+
/**@suppress {duplicate, undefinedVars}*/var _glTexEnvi;
68+
/**@suppress {duplicate, undefinedVars}*/var _glTexEnvfv;
69+
/**@suppress {duplicate, undefinedVars}*/var _glGetTexEnviv;
70+
/**@suppress {duplicate, undefinedVars}*/var _glGetTexEnvfv;
71+
GLEmulation.init();`,
7472
$GLEmulation: {
7573
// Fog support. Partial, we assume shaders are used that implement fog. We just pass them uniforms
7674
fogStart: 0,

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

test/browser/glut_touchevents.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ int main(int argc, char *argv[])
6868
touches.item = function(i) { return this[i]; };
6969

7070
var event = document.createEvent('UIEvent');
71-
event.target = Module['canvas'];
7271
event.button = 0;
7372
event.changedTouches = touches;
7473
event.initUIEvent(eventType, true, true, window, 1);
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/embind/test_pthreads.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ using namespace emscripten;
88

99
void thread(void) {
1010
EM_ASM({
11-
globalProperty = {
11+
globalThis.globalProperty = {
1212
foo: function(value) {
1313
return value;
1414
}

test/other/test_runtime_keepalive.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ int main() {
88
Module["onExit"] = () => { out("onExit"); };
99
runtimeKeepalivePush();
1010
out("runtimeKeepalivePush done");
11-
counter = 0;
11+
var counter = 0;
1212
function timerCallback() {
1313
if (counter < 5) {
1414
runtimeKeepalivePush();

test/test_browser.py

Lines changed: 2 additions & 2 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=['-sLEGACY_GL_EMULATION', '-lSDL', '-lGL'] + args)
947+
self.btest_exit('test_sdl_canvas.c', cflags=['-sSTRICT_JS', '-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'])
1061+
self.btest_exit('glut_touchevents.c', cflags=['-lglut', '-sSTRICT_JS'])
10621062

10631063
def test_glut_wheelevents(self):
10641064
self.btest_exit('glut_wheelevents.c', cflags=['-lglut'])

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})

0 commit comments

Comments
 (0)