Skip to content

Commit 68771c3

Browse files
committed
Only export user-requests symbols on the Module object. NFC
Some exports are only needed internally and those don't need to be exported on the Module object. This is save some space and avoids unexpected exports on the public-facing Module.
1 parent 794362a commit 68771c3

29 files changed

+165
-73
lines changed

emscripten.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,15 @@ def make_export_wrappers(exports, delay_assignment):
799799
if name == '__cpp_exception':
800800
continue
801801
mangled = asmjs_mangle(name)
802+
# We only export onto the Module object of the user requested the export.
803+
# Some exports are used internally by library functions and don't need to be
804+
# publically exported.
805+
# The exception is `dynCall_` functions, which are dynamically used via the
806+
# Module object (see dynCallLegacy in library.js).
807+
if mangled in building.user_requested_exports or name.startswith('dynCall_'):
808+
lhs = f'{mangled} = Module["{mangled}"]'
809+
else:
810+
lhs = f'{mangled}'
802811
# The emscripten stack functions are called very early (by writeStackCookie) before
803812
# the runtime is initialized so we can't create these wrappers that check for
804813
# runtimeInitialized.
@@ -808,27 +817,27 @@ def make_export_wrappers(exports, delay_assignment):
808817
if delay_assignment:
809818
wrappers.append('''\
810819
/** @type {function(...*):?} */
811-
var %(mangled)s = Module["%(mangled)s"] = createExportWrapper("%(name)s");
812-
''' % {'mangled': mangled, 'name': name})
820+
var %(lhs)s = createExportWrapper("%(name)s");
821+
''' % {'lhs': lhs, 'name': name})
813822
else:
814823
wrappers.append('''\
815824
/** @type {function(...*):?} */
816-
var %(mangled)s = Module["%(mangled)s"] = createExportWrapper("%(name)s", asm);
817-
''' % {'mangled': mangled, 'name': name})
825+
var %(lhs)s = createExportWrapper("%(name)s", asm);
826+
''' % {'lhs': lhs, 'name': name})
818827
elif delay_assignment:
819828
# With assertions disabled the wrapper will replace the global var and Module var on
820829
# first use.
821830
wrappers.append('''\
822831
/** @type {function(...*):?} */
823-
var %(mangled)s = Module["%(mangled)s"] = function() {
824-
return (%(mangled)s = Module["%(mangled)s"] = Module["asm"]["%(name)s"]).apply(null, arguments);
832+
var %(lhs)s = function() {
833+
return (%(lhs)s = Module["asm"]["%(name)s"]).apply(null, arguments);
825834
};
826-
''' % {'mangled': mangled, 'name': name})
835+
''' % {'lhs': lhs, 'name': name})
827836
else:
828837
wrappers.append('''\
829838
/** @type {function(...*):?} */
830-
var %(mangled)s = Module["%(mangled)s"] = asm["%(name)s"]
831-
''' % {'mangled': mangled, 'name': name})
839+
var %(lhs)s = asm["%(name)s"]
840+
''' % {'lhs': lhs, 'name': name})
832841
return wrappers
833842

834843

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"a.html": 12854,
3-
"a.html.gz": 6948,
4-
"total": 12854,
5-
"total_gz": 6948
2+
"a.html": 12862,
3+
"a.html.gz": 6952,
4+
"total": 12862,
5+
"total_gz": 6952
66
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"a.html": 17360,
3-
"a.html.gz": 7495,
4-
"total": 17360,
5-
"total_gz": 7495
2+
"a.html": 17362,
3+
"a.html.gz": 7499,
4+
"total": 17362,
5+
"total_gz": 7499
66
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
26202
1+
25730
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
26166
1+
25694
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
31595
1+
31079
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
26356
1+
25708
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
31695
1+
31079
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
26202
1+
25730
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
26698
1+
26111

0 commit comments

Comments
 (0)