Skip to content

Add a settings to disable all polyfills #16036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ See docs/process.md for more on how version tagging works.

3.1.2
-----
- A new setting, `POLYFILL`, was added which is on by default but can be disabled
(via `-sNO_POLYFILL`) to prevent emscripten from outputing needed polyfills.
For default browser targets, no polyfills are needed so this option only has
meaning when targeting older browsers.
- `EVAL_CTORS` has been rewritten and improved. The main differences from before
are that it is much more capable (it can now eval parts of functions and not
just all or nothing, and it can eval more wasm constructs like globals). It is
Expand Down
4 changes: 4 additions & 0 deletions src/polyfill/promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
// THE SOFTWARE.
//==============================================================================

#if !POLYFILL
assert(false, "this file should never be included unless POLYFILL is set");
#endif

/** @suppress{duplicate} This is already defined in from Closure's built-in
externs.zip//es6.js, Closure should not yell when seeing this again. */
var Promise = (function() {
Expand Down
8 changes: 8 additions & 0 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1971,6 +1971,14 @@ var ALLOW_UNIMPLEMENTED_SYSCALLS = 1;
// [link]
var TRUSTED_TYPES = 0;

// When targeting older browsers emscripten will sometimes require that
// polyfills be included in the output. If you would prefer to take care of
// polyfilling yourself via some other mechanism you can prevent emscripten
// from generating these by passing `-sNO_POLYFILL` or `-sPOLYFILL=0`
// With default browser targets emscripten does not need any polyfills so this
// settings is *only* needed when also explicitly targeting older browsers.
var POLYFILL = 1;

//===========================================
// Internal, used for testing only, from here
//===========================================
Expand Down
2 changes: 2 additions & 0 deletions src/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ if (!Module) /** @suppress{checkTypes}*/Module = {"__EMSCRIPTEN_PRIVATE_MODULE_E
var Module = typeof {{{ EXPORT_NAME }}} !== 'undefined' ? {{{ EXPORT_NAME }}} : {};
#endif // USE_CLOSURE_COMPILER

#if POLYFILL
#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
// Include a Promise polyfill for legacy browsers. This is needed either for
// wasm2js, where we polyfill the wasm API which needs Promises, or when using
// modularize which creates a Promise for when the module is ready.
#include "polyfill/promise.js"
#endif
#endif

// See https://caniuse.com/mdn-javascript_builtins_object_assign
#if MIN_CHROME_VERSION < 45 || MIN_EDGE_VERSION < 12 || MIN_FIREFOX_VERSION < 34 || MIN_IE_VERSION != TARGET_NOT_SUPPORTED || MIN_SAFARI_VERSION < 90000
Expand Down
9 changes: 7 additions & 2 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -10022,9 +10022,14 @@ def test(args, expect_fail):
return self.run_js('a.out.js', assert_returncode=NON_ZERO if expect_fail else 0)

# we fail without legacy support
self.assertNotContained('hello, world!', test([], expect_fail=True))
test([], expect_fail=True)

# but work with it
self.assertContained('hello, world!', test(['-sLEGACY_VM_SUPPORT'], expect_fail=False))
output = test(['-sLEGACY_VM_SUPPORT'], expect_fail=False)
self.assertContained('hello, world!', output)

# unless we explictly disable polyfills
test(['-sLEGACY_VM_SUPPORT', '-sNO_POLYFILL'], expect_fail=True)

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