From c1f5e24d76845383b17214c9e699d00e07db9a53 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Sun, 12 Dec 2021 17:01:56 -0800 Subject: [PATCH] Initial usage of ES6 in JS library code Now that ES6 features are permitted in emscripten JS library code (see #15763) we can take advantage of some of them to reduce size of our output JS. This is just an initial test of using ES6 features. See: #11984 --- ChangeLog.md | 2 +- emcc.py | 2 +- src/library.js | 16 ++++++-------- src/library_browser.js | 4 ++-- src/library_webgl.js | 2 +- src/preamble_minimal.js | 8 ++----- src/proxyClient.js | 4 ++-- src/runtime_strings.js | 2 +- src/shell.js | 22 +++++++++---------- src/shell_minimal.js | 2 +- tests/code_size/hello_webgl2_wasm.json | 8 +++---- tests/code_size/hello_webgl2_wasm2js.json | 8 +++---- tests/code_size/hello_webgl_wasm.json | 8 +++---- tests/code_size/hello_webgl_wasm2js.json | 8 +++---- tests/code_size/random_printf_wasm.json | 8 +++---- tests/code_size/random_printf_wasm2js.json | 8 +++---- tests/common.py | 2 -- tests/minimal_webgl/library_js.js | 2 +- tests/other/metadce/hello_libcxx_O2.jssize | 2 +- .../hello_libcxx_O2_fexceptions.jssize | 2 +- ...cxx_O2_fexceptions_DEMANGLE_SUPPORT.jssize | 2 +- tests/other/metadce/hello_world.jssize | 2 +- tests/other/metadce/hello_world_O1.jssize | 2 +- tests/other/metadce/hello_world_O2.jssize | 2 +- tests/other/metadce/hello_world_O3.jssize | 2 +- .../hello_world_O3_MAIN_MODULE_2.jssize | 2 +- tests/other/metadce/hello_world_Os.jssize | 2 +- ...lo_world_Os_EXPORTED_FUNCTIONS_NONE.jssize | 2 +- tests/other/metadce/hello_world_Oz.jssize | 2 +- .../other/metadce/libcxxabi_message_O3.jssize | 2 +- ...ibcxxabi_message_O3_STANDALONE_WASM.jssize | 2 +- tests/other/metadce/mem_O3.jssize | 2 +- .../metadce/mem_O3_ALLOW_MEMORY_GROWTH.jssize | 2 +- ...ALLOW_MEMORY_GROWTH_STANDALONE_WASM.jssize | 2 +- .../metadce/mem_O3_STANDALONE_WASM.jssize | 2 +- .../mem_no_argv_O3_STANDALONE_WASM.jssize | 2 +- ...mem_no_argv_O3_STANDALONE_WASM_flto.jssize | 2 +- ..._no_main_O3_STANDALONE_WASM_noentry.jssize | 2 +- tests/other/metadce/minimal.jssize | 2 +- tests/other/metadce/minimal_O1.jssize | 2 +- tests/other/metadce/minimal_O2.jssize | 2 +- tests/other/metadce/minimal_O3.jssize | 2 +- tests/other/metadce/minimal_Os.jssize | 2 +- tests/other/metadce/minimal_Oz.jssize | 2 +- ...in_Oz_USE_PTHREADS_PROXY_TO_PTHREAD.jssize | 2 +- tests/test_other.py | 1 + ..._postprocess_around_closure_limitations.py | 3 +++ 47 files changed, 85 insertions(+), 89 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index f6804726a9f9d..3e92acc03ef84 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -18,7 +18,7 @@ to browse the changes between the tags. See docs/process.md for more on how version tagging works. -3.0.2 +3.1.0 ----- - Emscripten in starting to use ES6 features in its core libraries (at last!). For most users targeting the default set of browsers this is a code size win. diff --git a/emcc.py b/emcc.py index d402507822f3a..a72f62f3ac028 100755 --- a/emcc.py +++ b/emcc.py @@ -3416,7 +3416,7 @@ def modularize(): if shared.target_environment_may_be('node'): script_url_node = "if (typeof __filename !== 'undefined') _scriptDir = _scriptDir || __filename;" src = ''' -var %(EXPORT_NAME)s = (function() { +var %(EXPORT_NAME)s = (() => { var _scriptDir = %(script_url)s; %(script_url_node)s return (%(src)s); diff --git a/src/library.js b/src/library.js index d0a19be918798..60411002ee05d 100644 --- a/src/library.js +++ b/src/library.js @@ -325,14 +325,12 @@ LibraryManager.library = { var cp = require('child_process'); var ret = cp.spawnSync(cmdstr, [], {shell:true, stdio:'inherit'}); - var _W_EXITCODE = function(ret, sig) { - return ((ret) << 8 | (sig)); - } + var _W_EXITCODE = (ret, sig) => ((ret) << 8 | (sig)); // this really only can happen if process is killed by signal if (ret.status === null) { // sadly node doesn't expose such function - var signalToNumber = function(sig) { + var signalToNumber = (sig) => { // implement only the most common ones, and fallback to SIGINT switch (sig) { case 'SIGHUP': return 1; @@ -1177,7 +1175,7 @@ LibraryManager.library = { var date = initDate(); var value; - var getMatch = function(symbol) { + var getMatch = (symbol) => { var pos = capture.indexOf(symbol); // check if symbol appears in regexp if (pos >= 0) { @@ -2530,7 +2528,7 @@ LibraryManager.library = { emscripten_get_now: ';' + #if ENVIRONMENT_MAY_BE_NODE "if (ENVIRONMENT_IS_NODE) {\n" + - " _emscripten_get_now = function() {\n" + + " _emscripten_get_now = () => {\n" + " var t = process['hrtime']();\n" + " return t[0] * 1e3 + t[1] / 1e6;\n" + " };\n" + @@ -2539,7 +2537,7 @@ LibraryManager.library = { #if USE_PTHREADS // Pthreads need their clocks synchronized to the execution of the main thread, so give them a special form of the function. "if (ENVIRONMENT_IS_PTHREAD) {\n" + - " _emscripten_get_now = function() { return performance.now() - Module['__performance_now_clock_drift']; };\n" + + " _emscripten_get_now = () => performance.now() - Module['__performance_now_clock_drift'];\n" + "} else " + #endif #if ENVIRONMENT_MAY_BE_SHELL @@ -2549,14 +2547,14 @@ LibraryManager.library = { #endif #if MIN_IE_VERSION <= 9 || MIN_FIREFOX_VERSION <= 14 || MIN_CHROME_VERSION <= 23 || MIN_SAFARI_VERSION <= 80400 // https://caniuse.com/#feat=high-resolution-time "if (typeof performance !== 'undefined' && performance.now) {\n" + - " _emscripten_get_now = function() { return performance.now(); }\n" + + " _emscripten_get_now = () => performance.now();\n" + "} else {\n" + " _emscripten_get_now = Date.now;\n" + "}", #else // Modern environment where performance.now() is supported: // N.B. a shorter form "_emscripten_get_now = return performance.now;" is unfortunately not allowed even in current browsers (e.g. FF Nightly 75). - "_emscripten_get_now = function() { return performance.now(); }\n", + "_emscripten_get_now = () => performance.now();\n", #endif emscripten_get_now_res: function() { // return resolution of get_now, in nanoseconds diff --git a/src/library_browser.js b/src/library_browser.js index 3c8b2a8a48781..3d9660ad3e3b1 100644 --- a/src/library_browser.js +++ b/src/library_browser.js @@ -150,7 +150,7 @@ var LibraryBrowser = { assert(typeof url == 'string', 'createObjectURL must return a url as a string'); #endif var img = new Image(); - img.onload = function img_onload() { + img.onload = () => { assert(img.complete, 'Image ' + name + ' could not be decoded'); var canvas = document.createElement('canvas'); canvas.width = img.width; @@ -161,7 +161,7 @@ var LibraryBrowser = { Browser.URLObject.revokeObjectURL(url); if (onload) onload(byteArray); }; - img.onerror = function img_onerror(event) { + img.onerror = (event) => { out('Image ' + url + ' could not be decoded'); if (onerror) onerror(); }; diff --git a/src/library_webgl.js b/src/library_webgl.js index 798efa7f35ed4..8d6e49035530c 100644 --- a/src/library_webgl.js +++ b/src/library_webgl.js @@ -675,7 +675,7 @@ var LibraryGL = { #endif #if GL_DISABLE_HALF_FLOAT_EXTENSION_IF_BROKEN - function disableHalfFloatExtensionIfBroken(ctx) { + const disableHalfFloatExtensionIfBroken = (ctx) => { var t = ctx.createTexture(); ctx.bindTexture(0xDE1/*GL_TEXTURE_2D*/, t); for (var i = 0; i < 8 && ctx.getError(); ++i) /*no-op*/; diff --git a/src/preamble_minimal.js b/src/preamble_minimal.js index fe195f377a5e8..e81c9aee3daec 100644 --- a/src/preamble_minimal.js +++ b/src/preamble_minimal.js @@ -29,12 +29,8 @@ var tempI64; #endif var tempRet0 = 0; -var setTempRet0 = function(value) { - tempRet0 = value; -} -var getTempRet0 = function() { - return tempRet0; -} +var setTempRet0 = (value) => { tempRet0 = value }; +var getTempRet0 = () => tempRet0; function alignUp(x, multiple) { if (x % multiple > 0) { diff --git a/src/proxyClient.js b/src/proxyClient.js index c41cbdc693a9a..2536f4c9663c3 100644 --- a/src/proxyClient.js +++ b/src/proxyClient.js @@ -205,7 +205,7 @@ worker.onmessage = function worker_onmessage(event) { case 'Image': { assert(data.method === 'src'); var img = new Image(); - img.onload = function() { + img.onload = () => { assert(img.complete); var canvas = document.createElement('canvas'); canvas.width = img.width; @@ -215,7 +215,7 @@ worker.onmessage = function worker_onmessage(event) { var imageData = ctx.getImageData(0, 0, img.width, img.height); worker.postMessage({ target: 'Image', method: 'onload', id: data.id, width: img.width, height: img.height, data: imageData.data, preMain: true }); }; - img.onerror = function() { + img.onerror = () => { worker.postMessage({ target: 'Image', method: 'onerror', id: data.id, preMain: true }); }; img.src = data.src; diff --git a/src/runtime_strings.js b/src/runtime_strings.js index 396d731413186..8b406338fe984 100644 --- a/src/runtime_strings.js +++ b/src/runtime_strings.js @@ -17,7 +17,7 @@ // character. function TextDecoderWrapper(encoding) { var textDecoder = new TextDecoder(encoding); - this.decode = function(data) { + this.decode = (data) => { #if ASSERTIONS assert(data instanceof Uint8Array); #endif diff --git a/src/shell.js b/src/shell.js index 9b0a7a4882af7..3590f866d68ac 100644 --- a/src/shell.js +++ b/src/shell.js @@ -82,7 +82,7 @@ var moduleOverrides = objAssign({}, Module); var arguments_ = []; var thisProgram = './this.program'; -var quit_ = function(status, toThrow) { +var quit_ = (status, toThrow) => { throw toThrow; }; @@ -171,7 +171,7 @@ var read_, // this may no longer be needed under node. function logExceptionOnExit(e) { if (e instanceof ExitStatus) return; - var toLog = e; + let toLog = e; #if ASSERTIONS if (e && typeof e === 'object' && e.stack) { toLog = [e, e.stack]; @@ -232,7 +232,7 @@ if (ENVIRONMENT_IS_NODE) { process['on']('unhandledRejection', function(reason) { throw reason; }); #endif - quit_ = function(status, toThrow) { + quit_ = (status, toThrow) => { if (keepRuntimeAlive()) { process['exitCode'] = status; throw toThrow; @@ -244,7 +244,7 @@ if (ENVIRONMENT_IS_NODE) { Module['inspect'] = function () { return '[Emscripten Module object]'; }; #if USE_PTHREADS - var nodeWorkerThreads; + let nodeWorkerThreads; try { nodeWorkerThreads = require('worker_threads'); } catch (e) { @@ -276,7 +276,7 @@ if (ENVIRONMENT_IS_SHELL) { if (typeof read != 'undefined') { read_ = function shell_read(f) { #if SUPPORT_BASE64_EMBEDDING - var data = tryParseAsDataURI(f); + const data = tryParseAsDataURI(f); if (data) { return intArrayToString(data); } @@ -286,7 +286,7 @@ if (ENVIRONMENT_IS_SHELL) { } readBinary = function readBinary(f) { - var data; + let data; #if SUPPORT_BASE64_EMBEDDING data = tryParseAsDataURI(f); if (data) { @@ -302,7 +302,7 @@ if (ENVIRONMENT_IS_SHELL) { }; readAsync = function readAsync(f, onload, onerror) { - setTimeout(function() { onload(readBinary(f)); }, 0); + setTimeout(() => onload(readBinary(f)), 0); }; if (typeof scriptArgs != 'undefined') { @@ -312,7 +312,7 @@ if (ENVIRONMENT_IS_SHELL) { } if (typeof quit === 'function') { - quit_ = function(status, toThrow) { + quit_ = (status, toThrow) => { logExceptionOnExit(toThrow); quit(status); }; @@ -385,7 +385,7 @@ if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) { } - setWindowTitle = function(title) { document.title = title }; + setWindowTitle = (title) => document.title = title; } else #endif // ENVIRONMENT_MAY_BE_WEB || ENVIRONMENT_MAY_BE_WORKER { @@ -413,8 +413,8 @@ var defaultPrint = console.log.bind(console); var defaultPrintErr = console.warn.bind(console); if (ENVIRONMENT_IS_NODE) { requireNodeFS(); - defaultPrint = function(str) { fs.writeSync(1, str + '\n'); }; - defaultPrintErr = function(str) { fs.writeSync(2, str + '\n'); }; + defaultPrint = (str) => fs.writeSync(1, str + '\n'); + defaultPrintErr = (str) => fs.writeSync(2, str + '\n'); } {{{ makeModuleReceiveWithVar('out', 'print', 'defaultPrint', true) }}} {{{ makeModuleReceiveWithVar('err', 'printErr', 'defaultPrintErr', true) }}} diff --git a/src/shell_minimal.js b/src/shell_minimal.js index fd95c9fbd0f21..f4e7f2a05dd2e 100644 --- a/src/shell_minimal.js +++ b/src/shell_minimal.js @@ -15,7 +15,7 @@ var Module = {{{ EXPORT_NAME }}}; #if MODULARIZE && EXPORT_READY_PROMISE // Set up the promise that indicates the Module is initialized var readyPromiseResolve, readyPromiseReject; -Module['ready'] = new Promise(function(resolve, reject) { +Module['ready'] = new Promise((resolve, reject) => { readyPromiseResolve = resolve; readyPromiseReject = reject; }); diff --git a/tests/code_size/hello_webgl2_wasm.json b/tests/code_size/hello_webgl2_wasm.json index 97f9fc0d88194..3d5d1058a68e2 100644 --- a/tests/code_size/hello_webgl2_wasm.json +++ b/tests/code_size/hello_webgl2_wasm.json @@ -1,10 +1,10 @@ { "a.html": 569, "a.html.gz": 379, - "a.js": 5000, - "a.js.gz": 2422, + "a.js": 4974, + "a.js.gz": 2418, "a.wasm": 10442, "a.wasm.gz": 6661, - "total": 16011, - "total_gz": 9462 + "total": 15985, + "total_gz": 9458 } diff --git a/tests/code_size/hello_webgl2_wasm2js.json b/tests/code_size/hello_webgl2_wasm2js.json index 6e4d4d12269f3..ea28f1dfcef3f 100644 --- a/tests/code_size/hello_webgl2_wasm2js.json +++ b/tests/code_size/hello_webgl2_wasm2js.json @@ -1,10 +1,10 @@ { "a.html": 594, "a.html.gz": 389, - "a.js": 20040, - "a.js.gz": 8198, + "a.js": 20034, + "a.js.gz": 8200, "a.mem": 3171, "a.mem.gz": 2714, - "total": 23805, - "total_gz": 11301 + "total": 23799, + "total_gz": 11303 } diff --git a/tests/code_size/hello_webgl_wasm.json b/tests/code_size/hello_webgl_wasm.json index 2e6fb45332a2c..f8f491721de8e 100644 --- a/tests/code_size/hello_webgl_wasm.json +++ b/tests/code_size/hello_webgl_wasm.json @@ -1,10 +1,10 @@ { "a.html": 569, "a.html.gz": 379, - "a.js": 4486, - "a.js.gz": 2249, + "a.js": 4480, + "a.js.gz": 2251, "a.wasm": 10442, "a.wasm.gz": 6661, - "total": 15497, - "total_gz": 9289 + "total": 15491, + "total_gz": 9291 } diff --git a/tests/code_size/hello_webgl_wasm2js.json b/tests/code_size/hello_webgl_wasm2js.json index 2f49057dde9b8..a8024cb946948 100644 --- a/tests/code_size/hello_webgl_wasm2js.json +++ b/tests/code_size/hello_webgl_wasm2js.json @@ -1,10 +1,10 @@ { "a.html": 594, "a.html.gz": 389, - "a.js": 19525, - "a.js.gz": 8035, + "a.js": 19519, + "a.js.gz": 8037, "a.mem": 3171, "a.mem.gz": 2714, - "total": 23290, - "total_gz": 11138 + "total": 23284, + "total_gz": 11140 } diff --git a/tests/code_size/random_printf_wasm.json b/tests/code_size/random_printf_wasm.json index aea2650805911..970a686e8492b 100644 --- a/tests/code_size/random_printf_wasm.json +++ b/tests/code_size/random_printf_wasm.json @@ -1,6 +1,6 @@ { - "a.html": 12988, - "a.html.gz": 6971, - "total": 12988, - "total_gz": 6971 + "a.html": 12973, + "a.html.gz": 6974, + "total": 12973, + "total_gz": 6974 } diff --git a/tests/code_size/random_printf_wasm2js.json b/tests/code_size/random_printf_wasm2js.json index 2765af12d0429..369cfc62d4d41 100644 --- a/tests/code_size/random_printf_wasm2js.json +++ b/tests/code_size/random_printf_wasm2js.json @@ -1,6 +1,6 @@ { - "a.html": 17816, - "a.html.gz": 7605, - "total": 17816, - "total_gz": 7605 + "a.html": 17801, + "a.html.gz": 7606, + "total": 17801, + "total_gz": 7606 } diff --git a/tests/common.py b/tests/common.py index 3bbc09d3852b4..2b4a97a66b119 100644 --- a/tests/common.py +++ b/tests/common.py @@ -587,8 +587,6 @@ def build(self, filename, libraries=[], includes=[], force_c=False, js_outfile=T self.run_process(cmd, stderr=self.stderr_redirect if not DEBUG else None) self.assertExists(output) - if js_outfile and not self.uses_es6: - self.verify_es5(output) if js_outfile and self.uses_memory_init_file(): src = read_file(output) diff --git a/tests/minimal_webgl/library_js.js b/tests/minimal_webgl/library_js.js index 50fa46bc2a4b9..688c47a3ffa7a 100644 --- a/tests/minimal_webgl/library_js.js +++ b/tests/minimal_webgl/library_js.js @@ -31,7 +31,7 @@ mergeInto(LibraryManager.library, { load_texture_from_url__deps: ['uploadFlipped'], load_texture_from_url: function(glTexture, url, outW, outH) { var img = new Image(); - img.onload = function() { + img.onload = () => { HEAPU32[outW>>2] = img.width; HEAPU32[outH>>2] = img.height; GLctx.bindTexture(0xDE1/*GLctx.TEXTURE_2D*/, GL.textures[glTexture]); diff --git a/tests/other/metadce/hello_libcxx_O2.jssize b/tests/other/metadce/hello_libcxx_O2.jssize index 508d01fdd19f2..0df5c1daef05d 100644 --- a/tests/other/metadce/hello_libcxx_O2.jssize +++ b/tests/other/metadce/hello_libcxx_O2.jssize @@ -1 +1 @@ -98376 +98355 diff --git a/tests/other/metadce/hello_libcxx_O2_fexceptions.jssize b/tests/other/metadce/hello_libcxx_O2_fexceptions.jssize index f17b326609dc2..032df3cc23772 100644 --- a/tests/other/metadce/hello_libcxx_O2_fexceptions.jssize +++ b/tests/other/metadce/hello_libcxx_O2_fexceptions.jssize @@ -1 +1 @@ -111848 +111827 diff --git a/tests/other/metadce/hello_libcxx_O2_fexceptions_DEMANGLE_SUPPORT.jssize b/tests/other/metadce/hello_libcxx_O2_fexceptions_DEMANGLE_SUPPORT.jssize index 56551e6b70996..8b18d51e5e3d3 100644 --- a/tests/other/metadce/hello_libcxx_O2_fexceptions_DEMANGLE_SUPPORT.jssize +++ b/tests/other/metadce/hello_libcxx_O2_fexceptions_DEMANGLE_SUPPORT.jssize @@ -1 +1 @@ -112835 +112814 diff --git a/tests/other/metadce/hello_world.jssize b/tests/other/metadce/hello_world.jssize index 512431cac4dc6..43009738e9fa5 100644 --- a/tests/other/metadce/hello_world.jssize +++ b/tests/other/metadce/hello_world.jssize @@ -1 +1 @@ -127954 +127918 diff --git a/tests/other/metadce/hello_world_O1.jssize b/tests/other/metadce/hello_world_O1.jssize index 6531f38742e25..7c9a8fedec47a 100644 --- a/tests/other/metadce/hello_world_O1.jssize +++ b/tests/other/metadce/hello_world_O1.jssize @@ -1 +1 @@ -58552 +58531 diff --git a/tests/other/metadce/hello_world_O2.jssize b/tests/other/metadce/hello_world_O2.jssize index 6d11a27347306..79a59b84055ac 100644 --- a/tests/other/metadce/hello_world_O2.jssize +++ b/tests/other/metadce/hello_world_O2.jssize @@ -1 +1 @@ -22140 +22119 diff --git a/tests/other/metadce/hello_world_O3.jssize b/tests/other/metadce/hello_world_O3.jssize index b26cdd9911258..d5ddf6631a881 100644 --- a/tests/other/metadce/hello_world_O3.jssize +++ b/tests/other/metadce/hello_world_O3.jssize @@ -1 +1 @@ -15478 +15457 diff --git a/tests/other/metadce/hello_world_O3_MAIN_MODULE_2.jssize b/tests/other/metadce/hello_world_O3_MAIN_MODULE_2.jssize index 49d14ce555858..fd8fab042b32a 100644 --- a/tests/other/metadce/hello_world_O3_MAIN_MODULE_2.jssize +++ b/tests/other/metadce/hello_world_O3_MAIN_MODULE_2.jssize @@ -1 +1 @@ -98468 +98447 diff --git a/tests/other/metadce/hello_world_Os.jssize b/tests/other/metadce/hello_world_Os.jssize index 8d273140bb622..0da23107b11f7 100644 --- a/tests/other/metadce/hello_world_Os.jssize +++ b/tests/other/metadce/hello_world_Os.jssize @@ -1 +1 @@ -15275 +15254 diff --git a/tests/other/metadce/hello_world_Os_EXPORTED_FUNCTIONS_NONE.jssize b/tests/other/metadce/hello_world_Os_EXPORTED_FUNCTIONS_NONE.jssize index 8568689ad4f0a..08ad7c5e3dc57 100644 --- a/tests/other/metadce/hello_world_Os_EXPORTED_FUNCTIONS_NONE.jssize +++ b/tests/other/metadce/hello_world_Os_EXPORTED_FUNCTIONS_NONE.jssize @@ -1 +1 @@ -12001 +11980 diff --git a/tests/other/metadce/hello_world_Oz.jssize b/tests/other/metadce/hello_world_Oz.jssize index d6a0cecf3fb00..a6a560b3cb802 100644 --- a/tests/other/metadce/hello_world_Oz.jssize +++ b/tests/other/metadce/hello_world_Oz.jssize @@ -1 +1 @@ -15150 +15129 diff --git a/tests/other/metadce/libcxxabi_message_O3.jssize b/tests/other/metadce/libcxxabi_message_O3.jssize index fd0e112864f3a..996f9c133bcbd 100644 --- a/tests/other/metadce/libcxxabi_message_O3.jssize +++ b/tests/other/metadce/libcxxabi_message_O3.jssize @@ -1 +1 @@ -13331 +13310 diff --git a/tests/other/metadce/libcxxabi_message_O3_STANDALONE_WASM.jssize b/tests/other/metadce/libcxxabi_message_O3_STANDALONE_WASM.jssize index 267d3112cec12..6ad35f4c704d5 100644 --- a/tests/other/metadce/libcxxabi_message_O3_STANDALONE_WASM.jssize +++ b/tests/other/metadce/libcxxabi_message_O3_STANDALONE_WASM.jssize @@ -1 +1 @@ -15018 +14997 diff --git a/tests/other/metadce/mem_O3.jssize b/tests/other/metadce/mem_O3.jssize index 51cd2147d6059..d704a6bf54711 100644 --- a/tests/other/metadce/mem_O3.jssize +++ b/tests/other/metadce/mem_O3.jssize @@ -1 +1 @@ -15456 +15435 diff --git a/tests/other/metadce/mem_O3_ALLOW_MEMORY_GROWTH.jssize b/tests/other/metadce/mem_O3_ALLOW_MEMORY_GROWTH.jssize index 80aaaf6a42870..e9f3adfa9ba52 100644 --- a/tests/other/metadce/mem_O3_ALLOW_MEMORY_GROWTH.jssize +++ b/tests/other/metadce/mem_O3_ALLOW_MEMORY_GROWTH.jssize @@ -1 +1 @@ -16130 +16109 diff --git a/tests/other/metadce/mem_O3_ALLOW_MEMORY_GROWTH_STANDALONE_WASM.jssize b/tests/other/metadce/mem_O3_ALLOW_MEMORY_GROWTH_STANDALONE_WASM.jssize index ce404cafc5de2..1a1ef86c9f668 100644 --- a/tests/other/metadce/mem_O3_ALLOW_MEMORY_GROWTH_STANDALONE_WASM.jssize +++ b/tests/other/metadce/mem_O3_ALLOW_MEMORY_GROWTH_STANDALONE_WASM.jssize @@ -1 +1 @@ -15913 +15892 diff --git a/tests/other/metadce/mem_O3_STANDALONE_WASM.jssize b/tests/other/metadce/mem_O3_STANDALONE_WASM.jssize index 57b0df1ecda5c..6822841a034cd 100644 --- a/tests/other/metadce/mem_O3_STANDALONE_WASM.jssize +++ b/tests/other/metadce/mem_O3_STANDALONE_WASM.jssize @@ -1 +1 @@ -15735 +15714 diff --git a/tests/other/metadce/mem_no_argv_O3_STANDALONE_WASM.jssize b/tests/other/metadce/mem_no_argv_O3_STANDALONE_WASM.jssize index 267d3112cec12..6ad35f4c704d5 100644 --- a/tests/other/metadce/mem_no_argv_O3_STANDALONE_WASM.jssize +++ b/tests/other/metadce/mem_no_argv_O3_STANDALONE_WASM.jssize @@ -1 +1 @@ -15018 +14997 diff --git a/tests/other/metadce/mem_no_argv_O3_STANDALONE_WASM_flto.jssize b/tests/other/metadce/mem_no_argv_O3_STANDALONE_WASM_flto.jssize index 267d3112cec12..6ad35f4c704d5 100644 --- a/tests/other/metadce/mem_no_argv_O3_STANDALONE_WASM_flto.jssize +++ b/tests/other/metadce/mem_no_argv_O3_STANDALONE_WASM_flto.jssize @@ -1 +1 @@ -15018 +14997 diff --git a/tests/other/metadce/mem_no_main_O3_STANDALONE_WASM_noentry.jssize b/tests/other/metadce/mem_no_main_O3_STANDALONE_WASM_noentry.jssize index 676922e559ad3..dce4347862f55 100644 --- a/tests/other/metadce/mem_no_main_O3_STANDALONE_WASM_noentry.jssize +++ b/tests/other/metadce/mem_no_main_O3_STANDALONE_WASM_noentry.jssize @@ -1 +1 @@ -13344 +13323 diff --git a/tests/other/metadce/minimal.jssize b/tests/other/metadce/minimal.jssize index f13bf0c5aac5b..3a28531185a94 100644 --- a/tests/other/metadce/minimal.jssize +++ b/tests/other/metadce/minimal.jssize @@ -1 +1 @@ -124443 +124407 diff --git a/tests/other/metadce/minimal_O1.jssize b/tests/other/metadce/minimal_O1.jssize index 4fa170fa00478..6c7d6a392ccbc 100644 --- a/tests/other/metadce/minimal_O1.jssize +++ b/tests/other/metadce/minimal_O1.jssize @@ -1 +1 @@ -55839 +55818 diff --git a/tests/other/metadce/minimal_O2.jssize b/tests/other/metadce/minimal_O2.jssize index 8aecdf888680f..0c689ce7d1fa5 100644 --- a/tests/other/metadce/minimal_O2.jssize +++ b/tests/other/metadce/minimal_O2.jssize @@ -1 +1 @@ -20107 +20086 diff --git a/tests/other/metadce/minimal_O3.jssize b/tests/other/metadce/minimal_O3.jssize index 5ed764ba37213..b6f0344c61ae9 100644 --- a/tests/other/metadce/minimal_O3.jssize +++ b/tests/other/metadce/minimal_O3.jssize @@ -1 +1 @@ -12375 +12354 diff --git a/tests/other/metadce/minimal_Os.jssize b/tests/other/metadce/minimal_Os.jssize index c2e219c613469..67420b23f156c 100644 --- a/tests/other/metadce/minimal_Os.jssize +++ b/tests/other/metadce/minimal_Os.jssize @@ -1 +1 @@ -12172 +12151 diff --git a/tests/other/metadce/minimal_Oz.jssize b/tests/other/metadce/minimal_Oz.jssize index c2e219c613469..67420b23f156c 100644 --- a/tests/other/metadce/minimal_Oz.jssize +++ b/tests/other/metadce/minimal_Oz.jssize @@ -1 +1 @@ -12172 +12151 diff --git a/tests/other/metadce/minimal_main_Oz_USE_PTHREADS_PROXY_TO_PTHREAD.jssize b/tests/other/metadce/minimal_main_Oz_USE_PTHREADS_PROXY_TO_PTHREAD.jssize index df1eaef8152a5..bb4152e8aef81 100644 --- a/tests/other/metadce/minimal_main_Oz_USE_PTHREADS_PROXY_TO_PTHREAD.jssize +++ b/tests/other/metadce/minimal_main_Oz_USE_PTHREADS_PROXY_TO_PTHREAD.jssize @@ -1 +1 @@ -48861 +48772 diff --git a/tests/test_other.py b/tests/test_other.py index 74fc767b217d4..b2f82cbd2d10c 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -11371,6 +11371,7 @@ def check_for_es6(filename, expect): self.assertContained('const ', js) self.assertContained('let ', js) else: + self.verify_es5(filename) self.assertNotContained('() => 2', js) self.assertNotContained('()=>2', js) self.assertNotContained('const ', js) diff --git a/tools/hacky_postprocess_around_closure_limitations.py b/tools/hacky_postprocess_around_closure_limitations.py index 9cee8eb666889..797c6b8a849fc 100644 --- a/tools/hacky_postprocess_around_closure_limitations.py +++ b/tools/hacky_postprocess_around_closure_limitations.py @@ -48,6 +48,9 @@ # var Module=function(a){ f = re.sub(r'\s*function\s*\(Module\)\s*{\s*Module\s*=\s*Module\s*\|\|\s*{\s*}\s*;\s*var\s+(\w+)\s*=\s*Module\s*;', r'function(\1){', f) +# Same as above but for arrow function +f = re.sub(r'\s*\(Module\)\s*=>\s*{\s*Module\s*=\s*Module\s*\|\|\s*{\s*}\s*;\s*var\s+(\w+)\s*=\s*Module\s*;', r'(\1)=>{', f) + f = re.sub(r'\s+', ' ', f) f = re.sub(r'[\n\s]+\n\s*', '\n', f) f = re.sub(r'([;{}=,\+\-\*/\(\)\[\]])[\n]', r'\1', f)