Skip to content

Commit 9565865

Browse files
authored
-sEXPORT_ES6 and multithreading too old browsers. (#25408)
~~Abort build if attempting to target -sEXPORT_ES6 and multithreading with too old target browser versions.~~ Add ES6 Module Workers as feature in the feature matrix.
1 parent b45fcac commit 9565865

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

src/lib/libpthread.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ const pthreadWorkerScript = TARGET_JS_NAME;
4242
// See https://github.com/emscripten-core/emscripten/issues/22394
4343
const pthreadWorkerOptions = `{
4444
#if EXPORT_ES6
45+
#if MIN_FIREFOX_VERSION < 114
46+
#error new Worker() supports ECMAScript module only starting from Firefox 114. Pass -sMIN_FIREFOX_VERSION=114 to target -sEXPORT_ES6 with -pthread. See https://caniuse.com/mdn-api_worker_worker_ecmascript_modules
47+
#endif
48+
#if MIN_CHROME_VERSION < 80
49+
#error new Worker() supports ECMAScript module only starting from Chrome 80. Pass -sMIN_CHROME_VERSION=80 to target -sEXPORT_ES6 with -pthread. See https://caniuse.com/mdn-api_worker_worker_ecmascript_modules
50+
#endif
51+
#if MIN_SAFARI_VERSION < 150000
52+
#error new Worker() supports ECMAScript module only starting from Safari 15. Pass -sMIN_SAFARI_VERSION=150000 to target -sEXPORT_ES6 with -pthread. See https://caniuse.com/mdn-api_worker_worker_ecmascript_modules
53+
#endif
4554
'type': 'module',
4655
#endif
4756
#if ENVIRONMENT_MAY_BE_NODE

src/lib/libwasm_worker.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@
4040
`;
4141
const wasmWorkerOptions = `{
4242
#if EXPORT_ES6
43+
#if MIN_FIREFOX_VERSION < 114
44+
#error new Worker() supports ECMAScript module only starting from Firefox 114. Pass -sMIN_FIREFOX_VERSION=114 to target -sEXPORT_ES6 with -sWASM_WORKERS. See https://caniuse.com/mdn-api_worker_worker_ecmascript_modules
45+
#endif
46+
#if MIN_CHROME_VERSION < 80
47+
#error new Worker() supports ECMAScript module only starting from Chrome 80. Pass -sMIN_CHROME_VERSION=80 to target -sEXPORT_ES6 with -sWASM_WORKERS. See https://caniuse.com/mdn-api_worker_worker_ecmascript_modules
48+
#endif
49+
#if MIN_SAFARI_VERSION < 150000
50+
#error new Worker() supports ECMAScript module only starting from Safari 15. Pass -sMIN_SAFARI_VERSION=150000 to target -sEXPORT_ES6 with -sWASM_WORKERS. See https://caniuse.com/mdn-api_worker_worker_ecmascript_modules
51+
#endif
4352
'type': 'module',
4453
#endif
4554
#if ENVIRONMENT_MAY_BE_NODE

tools/feature_matrix.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class Feature(IntEnum):
3838
THREADS = auto()
3939
PROMISE_ANY = auto()
4040
MEMORY64 = auto()
41+
WORKER_ES6_MODULES = auto()
4142

4243

4344
disable_override_features = set()
@@ -86,6 +87,14 @@ class Feature(IntEnum):
8687
'safari': UNSUPPORTED,
8788
'node': 230000,
8889
},
90+
# https://caniuse.com/mdn-api_worker_worker_ecmascript_modules: The ability to
91+
# call new Worker(url, { type: 'module' });
92+
Feature.WORKER_ES6_MODULES: {
93+
'chrome': 80,
94+
'firefox': 114,
95+
'safari': 150000,
96+
'node': 0, # This is a browser only feature, no requirements on Node.js
97+
},
8998
}
9099

91100
# Static assertion to check that we actually need each of the above feature flags
@@ -173,3 +182,7 @@ def apply_min_browser_versions():
173182
enable_feature(Feature.BULK_MEMORY, 'shared-mem')
174183
if settings.MEMORY64 == 1:
175184
enable_feature(Feature.MEMORY64, 'MEMORY64')
185+
if settings.EXPORT_ES6 and settings.PTHREADS:
186+
enable_feature(Feature.WORKER_ES6_MODULES, 'EXPORT_ES6 with -pthread')
187+
if settings.EXPORT_ES6 and settings.WASM_WORKERS:
188+
enable_feature(Feature.WORKER_ES6_MODULES, 'EXPORT_ES6 with -sWASM_WORKERS')

0 commit comments

Comments
 (0)