Skip to content

Commit

Permalink
Remove polyfills for Fetch and Object.assign (#23118)
Browse files Browse the repository at this point in the history
This change required the minimum supported browser versions to be bumped
just a little.
  • Loading branch information
sbc100 authored Dec 13, 2024
1 parent d04f14a commit 53c8132
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 220 deletions.
6 changes: 5 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ See docs/process.md for more on how version tagging works.
-----------------------
- The file system was updated to independently track atime, mtime and ctime
instead of using the same time for all three. (#22998)
- The minimum supported chrome version was bumped from 32 to 33. (#23077)
- Emscripten-generated code will now use async/await internally when loading
the Wasm module. This will be lowered away by babel when targeting older
browsers. (#23068)
- Due to the discontinued support for invalid specializations of
- `std::basic_string` (https://github.com/llvm/llvm-project/pull/72694), the
support for `std::basic_string<unsigned char>` was removed from embind.
(#23070)
- The minimum supported versions of browser engines that we support were updated
to versions that support Promise, Fetch and Object.asign APIs, allowing the
polyfills for these to be removed. Chrome 32 -> 45, Firefox 34 -> 40, Safari
9.0 -> 10.1. These browser engines version are all over 8 years old now.
(#23077, #23118)

3.1.73 - 11/28/24
-----------------
Expand Down
80 changes: 0 additions & 80 deletions src/polyfill/fetch.js

This file was deleted.

34 changes: 0 additions & 34 deletions src/polyfill/objassign.js

This file was deleted.

10 changes: 0 additions & 10 deletions src/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,10 @@ var Module = typeof {{{ EXPORT_NAME }}} != 'undefined' ? {{{ EXPORT_NAME }}} : {
#endif // USE_CLOSURE_COMPILER

#if POLYFILL
#if MIN_CHROME_VERSION < 45 || MIN_FIREFOX_VERSION < 34 || MIN_SAFARI_VERSION < 90000
// See https://caniuse.com/mdn-javascript_builtins_object_assign
#include "polyfill/objassign.js"
#endif

#if WASM_BIGINT && MIN_SAFARI_VERSION < 150000
// See https://caniuse.com/mdn-javascript_builtins_bigint64array
#include "polyfill/bigint64array.js"
#endif

#if MIN_CHROME_VERSION < 40 || MIN_FIREFOX_VERSION < 39 || MIN_SAFARI_VERSION < 103000
// See https://caniuse.com/fetch
#include "polyfill/fetch.js"
#endif
#endif // POLYFILL

#if MODULARIZE
Expand Down
7 changes: 0 additions & 7 deletions src/shell_minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,6 @@ function ready() {
#endif
}

#if POLYFILL
// See https://caniuse.com/mdn-javascript_builtins_object_assign
#if MIN_CHROME_VERSION < 45 || MIN_FIREFOX_VERSION < 34 || MIN_SAFARI_VERSION < 90000
#include "polyfill/objassign.js"
#endif
#endif

#if PTHREADS
// MINIMAL_RUNTIME does not support --proxy-to-worker option, so Worker and Pthread environments
// coincide.
Expand Down
3 changes: 1 addition & 2 deletions test/browser_reporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ function reportResultToServer(result) {
if ((typeof ENVIRONMENT_IS_NODE !== 'undefined' && ENVIRONMENT_IS_NODE) || (typeof ENVIRONMENT_IS_AUDIO_WORKLET !== 'undefined' && ENVIRONMENT_IS_AUDIO_WORKLET)) {
out(`RESULT: ${result}`);
} else {
let doFetch = typeof origFetch != 'undefined' ? origFetch : fetch;
doFetch(`${reportingURL}/report_result?${encodeURIComponent(result)}`).then(() => {
fetch(`${reportingURL}/report_result?${encodeURIComponent(result)}`).then(() => {
if (typeof window === 'object' && window && hasModule && !Module['pageThrewException']) {
/* for easy debugging, don't close window on failure */
window.close();
Expand Down
82 changes: 0 additions & 82 deletions test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5445,88 +5445,6 @@ def test_webpack(self, es6):
shutil.copy('webpack/src/hello.wasm', 'webpack/dist/')
self.run_browser('webpack/dist/index.html', '/report_result?exit:0')

def test_fetch_polyfill_preload(self):
create_file('hello.txt', 'hello, world!')
create_file('main.c', r'''
#include <stdio.h>
#include <string.h>
#include <emscripten.h>
int main() {
FILE *f = fopen("hello.txt", "r");
char buf[100];
fread(buf, 1, 20, f);
buf[20] = 0;
fclose(f);
printf("%s\n", buf);
return 0;
}''')

create_file('on_window_error_shell.html', r'''
<html>
<center><canvas id='canvas' width='256' height='256'></canvas></center>
<hr><div id='output'></div><hr>
<script type='text/javascript'>
window.addEventListener('error', event => {
const error = String(event.message);
window.disableErrorReporting = true;
window.onerror = null;
var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://localhost:8888/report_result?exception:' + error.substr(-23), true);
xhr.send();
setTimeout(function() { window.close() }, 1000);
});
</script>
{{{ SCRIPT }}}
</body>
</html>''')

def test(args, expect_fail):
self.compile_btest('main.c', ['-sEXIT_RUNTIME', '--preload-file', 'hello.txt', '--shell-file', 'on_window_error_shell.html', '-o', 'a.out.html'] + args)
if expect_fail:
js = read_file('a.out.js')
create_file('a.out.js', 'let origFetch = fetch; fetch = undefined;\n' + js)
return self.run_browser('a.out.html', '/report_result?exception:fetch is not a function')
else:
return self.run_browser('a.out.html', '/report_result?exit:0')

test([], expect_fail=False)
test([], expect_fail=True)
test(['-sLEGACY_VM_SUPPORT'], expect_fail=False)
test(['-sLEGACY_VM_SUPPORT', '-sNO_POLYFILL'], expect_fail=True)

@no_wasm64('https://github.com/llvm/llvm-project/issues/98778')
def test_fetch_polyfill_shared_lib(self):
create_file('library.c', r'''
int library_func() {
return 42;
}
''')
create_file('main.c', r'''
#include <dlfcn.h>
#include <stdio.h>
int main() {
void *lib_handle = dlopen("/library.so", RTLD_NOW);
typedef int (*voidfunc)();
voidfunc x = (voidfunc)dlsym(lib_handle, "library_func");
return x();
}
''')

self.emcc('library.c', ['-sSIDE_MODULE', '-O2', '-o', 'library.so'])

def test(args, expect_fail):
self.compile_btest('main.c', ['-fPIC', 'library.so', '-sMAIN_MODULE=2', '-sEXIT_RUNTIME', '-o', 'a.out.html'] + args)
if expect_fail:
js = read_file('a.out.js')
create_file('a.out.js', 'let origFetch = fetch; fetch = undefined;\n' + js)
return self.run_browser('a.out.html', '/report_result?abort:both async and sync fetching of the wasm failed')
else:
return self.run_browser('a.out.html', '/report_result?exit:42')

test([], expect_fail=True)
test(['-sLEGACY_VM_SUPPORT'], expect_fail=False)
test(['-sLEGACY_VM_SUPPORT', '-sNO_POLYFILL'], expect_fail=True)


class emrun(RunnerCore):
def test_emrun_info(self):
Expand Down
2 changes: 1 addition & 1 deletion test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -15260,7 +15260,7 @@ def test_no_extra_output(self):

def test_browser_too_old(self):
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sMIN_CHROME_VERSION=10'])
self.assertContained('emcc: error: MIN_CHROME_VERSION older than 33 is not supported', err)
self.assertContained('emcc: error: MIN_CHROME_VERSION older than 45 is not supported', err)

def test_js_only_settings(self):
err = self.run_process([EMCC, test_file('hello_world.c'), '-o', 'foo.wasm', '-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=emscripten_get_heap_max'], stderr=PIPE).stderr
Expand Down
6 changes: 3 additions & 3 deletions tools/feature_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
# Oldest support browser versions. These have been set somewhat
# arbitrarily for now.
# TODO(sbc): Design a of policy for managing these values.
OLDEST_SUPPORTED_CHROME = 33
OLDEST_SUPPORTED_FIREFOX = 34
OLDEST_SUPPORTED_SAFARI = 90000
OLDEST_SUPPORTED_CHROME = 45 # September 1, 2015
OLDEST_SUPPORTED_FIREFOX = 40 # August 11, 2015
OLDEST_SUPPORTED_SAFARI = 101000 # September 20, 2016
# 10.19.0 is the oldest version of node that we do any testing with.
# Keep this in sync with the test-node-compat in .circleci/config.yml.
OLDEST_SUPPORTED_NODE = 101900
Expand Down

0 comments on commit 53c8132

Please sign in to comment.