Avoid additional EXPORT_NAME variable inside the module scope. NFC
Within the module scope we still refer to the moduel as `Module`. The
EXPORT_NAME comes in when we define the name of the factory function
which creates the module.
diff --git a/emcc.py b/emcc.py
index c69c5cf..29c2495 100755
--- a/emcc.py
+++ b/emcc.py
@@ -3763,7 +3763,7 @@
shared.target_environment_may_be('web'):
async_emit = 'async '
- return_value = settings.EXPORT_NAME
+ return_value = 'Module'
if settings.WASM_ASYNC_COMPILATION:
return_value += '.ready'
if not settings.EXPORT_READY_PROMISE:
@@ -3775,7 +3775,7 @@
src = '''
%(maybe_async)sfunction(config) {
- var %(EXPORT_NAME)s = config || {};
+ var Module = config || {};
%(src)s
@@ -3783,7 +3783,6 @@
}
''' % {
'maybe_async': async_emit,
- 'EXPORT_NAME': settings.EXPORT_NAME,
'src': src,
'return_value': return_value
}
diff --git a/src/shell.js b/src/shell.js
index 887e3e3..56bde5e 100644
--- a/src/shell.js
+++ b/src/shell.js
@@ -34,8 +34,8 @@
}}
*/ Module;
if (!Module) /** @suppress{checkTypes}*/Module = {"__EMSCRIPTEN_PRIVATE_MODULE_EXPORT_NAME_SUBSTITUTION__":1};
-#else
-var Module = typeof {{{ EXPORT_NAME }}} != 'undefined' ? {{{ EXPORT_NAME }}} : {};
+#elif !MODULARIZE
+var Module = Module || {};
#endif // USE_CLOSURE_COMPILER
#if POLYFILL
diff --git a/src/shell_minimal.js b/src/shell_minimal.js
index c1e9b92..5fdf488 100644
--- a/src/shell_minimal.js
+++ b/src/shell_minimal.js
@@ -9,12 +9,10 @@
// otherwise replace every `Module` occurrence with the object below
var /** @type{Object} */ Module;
if (!Module) /** @suppress{checkTypes}*/Module = {"__EMSCRIPTEN_PRIVATE_MODULE_EXPORT_NAME_SUBSTITUTION__":1};
-#elif ENVIRONMENT_MAY_BE_NODE || ENVIRONMENT_MAY_BE_SHELL
+#elif !MODULARIZE && (ENVIRONMENT_MAY_BE_NODE || ENVIRONMENT_MAY_BE_SHELL)
// When running on the web we expect Module to be defined externally, in the
// HTML. Otherwise we must define it here before its first use
-var Module = typeof {{{ EXPORT_NAME }}} != 'undefined' ? {{{ EXPORT_NAME }}} : {};
-#else
-var Module = {{{ EXPORT_NAME }}};
+var Module = Module || {};
#endif // USE_CLOSURE_COMPILER
#if MODULARIZE && EXPORT_READY_PROMISE
diff --git a/test/common.py b/test/common.py
index 1dda74f..c028d83 100644
--- a/test/common.py
+++ b/test/common.py
@@ -836,7 +836,7 @@
if len(line) > 2048:
# Sanity check that this is really the emscripten program/module on
# a single line.
- assert line.startswith('var Module=typeof Module!="undefined"')
+ assert line.startswith('var Module=Module||{}')
long_lines.append(line)
line = '<REPLACED ENTIRE PROGRAM ON SINGLE LINE>'
return line
diff --git a/test/other/test_unoptimized_code_size.js.size b/test/other/test_unoptimized_code_size.js.size
index 8948c5d..020276d 100644
--- a/test/other/test_unoptimized_code_size.js.size
+++ b/test/other/test_unoptimized_code_size.js.size
@@ -1 +1 @@
-67126
+67096
diff --git a/test/other/test_unoptimized_code_size_no_asserts.js.size b/test/other/test_unoptimized_code_size_no_asserts.js.size
index c5baeb6..c6defb5 100644
--- a/test/other/test_unoptimized_code_size_no_asserts.js.size
+++ b/test/other/test_unoptimized_code_size_no_asserts.js.size
@@ -1 +1 @@
-38780
+38750
diff --git a/test/other/test_unoptimized_code_size_strict.js.size b/test/other/test_unoptimized_code_size_strict.js.size
index fc429de..3751d9c 100644
--- a/test/other/test_unoptimized_code_size_strict.js.size
+++ b/test/other/test_unoptimized_code_size_strict.js.size
@@ -1 +1 @@
-65992
+65962