Skip to content

Commit 8cc1bb1

Browse files
committed
Add a settings to disable all polyfills
See #15938
1 parent 583000b commit 8cc1bb1

File tree

5 files changed

+25
-2
lines changed

5 files changed

+25
-2
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ See docs/process.md for more on how version tagging works.
2020

2121
3.1.2
2222
-----
23+
- A new setting, `POLYFILL`, was added which is on by default but can be disabled
24+
(via `-sNO_POLYFILL`) to prevent emscripten from outputing needed polyfills.
25+
For default browser targets, no polyfills are needed so this option only has
26+
meaning when targeting older browsers.
2327
- `EVAL_CTORS` has been rewritten and improved. The main differences from before
2428
are that it is much more capable (it can now eval parts of functions and not
2529
just all or nothing, and it can eval more wasm constructs like globals). It is

src/polyfill/promise.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
// THE SOFTWARE.
2424
//==============================================================================
2525

26+
#if !POLYFILL
27+
assert(false, "this file should never be included unless POLYFILL is set");
28+
#endif
29+
2630
/** @suppress{duplicate} This is already defined in from Closure's built-in
2731
externs.zip//es6.js, Closure should not yell when seeing this again. */
2832
var Promise = (function() {

src/settings.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1971,6 +1971,14 @@ var ALLOW_UNIMPLEMENTED_SYSCALLS = 1;
19711971
// [link]
19721972
var TRUSTED_TYPES = 0;
19731973

1974+
// When targeting older browsers emscripten will sometimes require that
1975+
// polyfills be included in the output. If you would prefer to take care of
1976+
// polyfilling yourself via some other mechanism you can prevent emscripten
1977+
// from generating these by passing `-sNO_POLYFILL` or `-sPOLYFILL=0`
1978+
// With default browser targets emscripten does not need any polyfills so this
1979+
// settings is *only* needed when also explicitly targeting older browsers.
1980+
var POLYFILL = 1;
1981+
19741982
//===========================================
19751983
// Internal, used for testing only, from here
19761984
//===========================================

src/shell.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ if (!Module) /** @suppress{checkTypes}*/Module = {"__EMSCRIPTEN_PRIVATE_MODULE_E
3636
var Module = typeof {{{ EXPORT_NAME }}} !== 'undefined' ? {{{ EXPORT_NAME }}} : {};
3737
#endif // USE_CLOSURE_COMPILER
3838

39+
#if POLYFILL
3940
#if ((MAYBE_WASM2JS && WASM != 2) || MODULARIZE) && (MIN_CHROME_VERSION < 33 || MIN_EDGE_VERSION < 12 || MIN_FIREFOX_VERSION < 29 || MIN_IE_VERSION != TARGET_NOT_SUPPORTED || MIN_SAFARI_VERSION < 80000) // https://caniuse.com/#feat=promises
4041
// Include a Promise polyfill for legacy browsers. This is needed either for
4142
// wasm2js, where we polyfill the wasm API which needs Promises, or when using
4243
// modularize which creates a Promise for when the module is ready.
4344
#include "polyfill/promise.js"
4445
#endif
46+
#endif
4547

4648
// See https://caniuse.com/mdn-javascript_builtins_object_assign
4749
#if MIN_CHROME_VERSION < 45 || MIN_EDGE_VERSION < 12 || MIN_FIREFOX_VERSION < 34 || MIN_IE_VERSION != TARGET_NOT_SUPPORTED || MIN_SAFARI_VERSION < 90000

tests/test_other.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10022,9 +10022,14 @@ def test(args, expect_fail):
1002210022
return self.run_js('a.out.js', assert_returncode=NON_ZERO if expect_fail else 0)
1002310023

1002410024
# we fail without legacy support
10025-
self.assertNotContained('hello, world!', test([], expect_fail=True))
10025+
test([], expect_fail=True)
10026+
1002610027
# but work with it
10027-
self.assertContained('hello, world!', test(['-sLEGACY_VM_SUPPORT'], expect_fail=False))
10028+
output = test(['-sLEGACY_VM_SUPPORT'], expect_fail=False)
10029+
self.assertContained('hello, world!', output)
10030+
10031+
# unless we explictly disable polyfills
10032+
test(['-sLEGACY_VM_SUPPORT', '-sNO_POLYFILL'], expect_fail=True)
1002810033

1002910034
def test_webgpu_compiletest(self):
1003010035
for args in [[], ['-sASSERTIONS'], ['-sASSERTIONS', '--closure=1'], ['-sMAIN_MODULE=1']]:

0 commit comments

Comments
 (0)