Skip to content

Commit f148f2b

Browse files
authored
Revert "Refactor modularization code to avoid nested functions. NFC (#20962)" (#20965)
This reverts commit 8027de3. I didn't wait long enough to confirm the browser tests all passed. My bad.
1 parent 8027de3 commit f148f2b

File tree

5 files changed

+44
-31
lines changed

5 files changed

+44
-31
lines changed

test/code_size/hello_webgl2_wasm.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 569,
33
"a.html.gz": 379,
4-
"a.js": 4691,
4+
"a.js": 4697,
55
"a.js.gz": 2419,
66
"a.wasm": 10482,
77
"a.wasm.gz": 6728,
8-
"total": 15742,
8+
"total": 15748,
99
"total_gz": 9526
1010
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 567,
33
"a.html.gz": 379,
4-
"a.js": 18016,
5-
"a.js.gz": 8139,
4+
"a.js": 18022,
5+
"a.js.gz": 8135,
66
"a.mem": 3123,
77
"a.mem.gz": 2693,
8-
"total": 21706,
9-
"total_gz": 11211
8+
"total": 21712,
9+
"total_gz": 11207
1010
}

test/code_size/hello_webgl_wasm.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 569,
33
"a.html.gz": 379,
4-
"a.js": 4177,
4+
"a.js": 4183,
55
"a.js.gz": 2241,
66
"a.wasm": 10482,
77
"a.wasm.gz": 6728,
8-
"total": 15228,
8+
"total": 15234,
99
"total_gz": 9348
1010
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 567,
33
"a.html.gz": 379,
4-
"a.js": 17493,
5-
"a.js.gz": 7960,
4+
"a.js": 17499,
5+
"a.js.gz": 7958,
66
"a.mem": 3123,
77
"a.mem.gz": 2693,
8-
"total": 21183,
9-
"total_gz": 11032
8+
"total": 21189,
9+
"total_gz": 11030
1010
}

tools/link.py

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2325,15 +2325,23 @@ def modularize():
23252325
if async_emit != '' and settings.EXPORT_NAME == 'config':
23262326
diagnostics.warning('emcc', 'EXPORT_NAME should not be named "config" when targeting Safari')
23272327

2328+
src = '''
2329+
%(maybe_async)sfunction(moduleArg = {}) {
2330+
2331+
%(src)s
2332+
2333+
return %(return_value)s
2334+
}
2335+
''' % {
2336+
'maybe_async': async_emit,
2337+
'src': src,
2338+
'return_value': return_value,
2339+
}
2340+
23282341
if settings.MINIMAL_RUNTIME and not settings.PTHREADS:
23292342
# Single threaded MINIMAL_RUNTIME programs do not need access to
23302343
# document.currentScript, so a simple export declaration is enough.
2331-
src = f'''\
2332-
var {settings.EXPORT_NAME} = {async_emit}(moduleArg = {{}}) => {{
2333-
{src}
2334-
return {return_value};
2335-
}};
2336-
'''
2344+
src = '/** @nocollapse */ var %s = %s' % (settings.EXPORT_NAME, src)
23372345
else:
23382346
script_url_node = ''
23392347
# When MODULARIZE this JS may be executed later,
@@ -2347,14 +2355,19 @@ def modularize():
23472355
script_url = "typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined"
23482356
if shared.target_environment_may_be('node'):
23492357
script_url_node = "if (typeof __filename !== 'undefined') _scriptDir ||= __filename;"
2350-
src = f'''{node_es6_imports()}
2351-
var {settings.EXPORT_NAME} = {async_emit}(moduleArg = {{}}) => {{
2352-
var _scriptDir = {script_url};
2353-
{script_url_node}
2354-
{src}
2355-
return {return_value};
2356-
}};
2357-
'''
2358+
src = '''%(node_imports)s
2359+
var %(EXPORT_NAME)s = (() => {
2360+
var _scriptDir = %(script_url)s;
2361+
%(script_url_node)s
2362+
return (%(src)s);
2363+
})();
2364+
''' % {
2365+
'node_imports': node_es6_imports(),
2366+
'EXPORT_NAME': settings.EXPORT_NAME,
2367+
'script_url': script_url,
2368+
'script_url_node': script_url_node,
2369+
'src': src,
2370+
}
23582371
# Given the async nature of how the Module function and Module object
23592372
# come into existence in AudioWorkletGlobalScope, store the Module
23602373
# function under a different variable name so that AudioWorkletGlobalScope
@@ -2365,14 +2378,14 @@ def modularize():
23652378

23662379
# Export using a UMD style export, or ES6 exports if selected
23672380
if settings.EXPORT_ES6:
2368-
src += f'export default {settings.EXPORT_NAME};'
2381+
src += 'export default %s;' % settings.EXPORT_NAME
23692382
elif not settings.MINIMAL_RUNTIME:
2370-
src += f'''
2383+
src += '''\
23712384
if (typeof exports === 'object' && typeof module === 'object')
2372-
module.exports = {settings.EXPORT_NAME};
2385+
module.exports = %(EXPORT_NAME)s;
23732386
else if (typeof define === 'function' && define['amd'])
2374-
define([], () => {settings.EXPORT_NAME});
2375-
'''
2387+
define([], () => %(EXPORT_NAME)s);
2388+
''' % {'EXPORT_NAME': settings.EXPORT_NAME}
23762389

23772390
final_js += '.modular.js'
23782391
write_file(final_js, src)

0 commit comments

Comments
 (0)