diff --git a/src/lib/libpthread.js b/src/lib/libpthread.js index 44d75892c6e13..6b07f590eefda 100644 --- a/src/lib/libpthread.js +++ b/src/lib/libpthread.js @@ -42,6 +42,15 @@ const pthreadWorkerScript = TARGET_JS_NAME; // See https://github.com/emscripten-core/emscripten/issues/22394 const pthreadWorkerOptions = `{ #if EXPORT_ES6 +#if MIN_FIREFOX_VERSION < 114 +#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 +#endif +#if MIN_CHROME_VERSION < 80 +#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 +#endif +#if MIN_SAFARI_VERSION < 150000 +#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 +#endif 'type': 'module', #endif #if ENVIRONMENT_MAY_BE_NODE diff --git a/src/lib/libwasm_worker.js b/src/lib/libwasm_worker.js index 3e9016b554aea..7a3e0dfeeb66c 100644 --- a/src/lib/libwasm_worker.js +++ b/src/lib/libwasm_worker.js @@ -40,6 +40,15 @@ `; const wasmWorkerOptions = `{ #if EXPORT_ES6 +#if MIN_FIREFOX_VERSION < 114 +#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 +#endif +#if MIN_CHROME_VERSION < 80 +#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 +#endif +#if MIN_SAFARI_VERSION < 150000 +#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 +#endif 'type': 'module', #endif #if ENVIRONMENT_MAY_BE_NODE diff --git a/tools/feature_matrix.py b/tools/feature_matrix.py index 74116760420ce..405529e1fcda4 100644 --- a/tools/feature_matrix.py +++ b/tools/feature_matrix.py @@ -38,6 +38,7 @@ class Feature(IntEnum): THREADS = auto() PROMISE_ANY = auto() MEMORY64 = auto() + WORKER_ES6_MODULES = auto() disable_override_features = set() @@ -86,6 +87,14 @@ class Feature(IntEnum): 'safari': UNSUPPORTED, 'node': 230000, }, + # https://caniuse.com/mdn-api_worker_worker_ecmascript_modules: The ability to + # call new Worker(url, { type: 'module' }); + Feature.WORKER_ES6_MODULES: { + 'chrome': 80, + 'firefox': 114, + 'safari': 150000, + 'node': 0, # This is a browser only feature, no requirements on Node.js + }, } # Static assertion to check that we actually need each of the above feature flags @@ -173,3 +182,7 @@ def apply_min_browser_versions(): enable_feature(Feature.BULK_MEMORY, 'shared-mem') if settings.MEMORY64 == 1: enable_feature(Feature.MEMORY64, 'MEMORY64') + if settings.EXPORT_ES6 and settings.PTHREADS: + enable_feature(Feature.WORKER_ES6_MODULES, 'EXPORT_ES6 with -pthread') + if settings.EXPORT_ES6 and settings.WASM_WORKERS: + enable_feature(Feature.WORKER_ES6_MODULES, 'EXPORT_ES6 with -sWASM_WORKERS')