Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 21 additions & 39 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1294,11 +1294,8 @@ def has_c_source(args):
else:
shared.Settings.EXPORTED_RUNTIME_METHODS += ['writeStackCookie', 'checkStackCookie', 'abortStackOverflow']

if shared.Settings.MODULARIZE_INSTANCE:
shared.Settings.MODULARIZE = 1

if shared.Settings.MODULARIZE:
assert not options.proxy_to_worker, '-s MODULARIZE=1 and -s MODULARIZE_INSTANCE=1 are not compatible with --proxy-to-worker (if you want to run in a worker with -s MODULARIZE=1, you likely want to do the worker side setup manually)'
assert not options.proxy_to_worker, '-s MODULARIZE=1 is not compatible with --proxy-to-worker (if you want to run in a worker with -s MODULARIZE=1, you likely want to do the worker side setup manually)'
# MODULARIZE's .then() method uses onRuntimeInitialized currently, so make sure
# it is expected to be used.
shared.Settings.INCOMING_MODULE_JS_API += ['onRuntimeInitialized']
Expand Down Expand Up @@ -1692,7 +1689,7 @@ def include_and_export(name):
if not shared.Settings.WASM and not shared.Settings.WASM_BACKEND:
options.memory_init_file = True

if shared.Settings.MODULARIZE and not shared.Settings.MODULARIZE_INSTANCE and shared.Settings.EXPORT_NAME == 'Module' and final_suffix == '.html' and \
if shared.Settings.MODULARIZE and shared.Settings.EXPORT_NAME == 'Module' and final_suffix == '.html' and \
(options.shell_path == shared.path_from_root('src', 'shell.html') or options.shell_path == shared.path_from_root('src', 'shell_minimal.html')):
exit_with_error('Due to collision in variable name "Module", the shell file "' + options.shell_path + '" is not compatible with build options "-s MODULARIZE=1 -s EXPORT_NAME=Module". Either provide your own shell file, change the name of the export to something else to avoid the name collision. (see https://github.com/emscripten-core/emscripten/issues/7950 for details)')

Expand Down Expand Up @@ -3399,47 +3396,32 @@ def modularize():
'exports_object': exports_object
}

if not shared.Settings.MODULARIZE_INSTANCE:
if shared.Settings.MINIMAL_RUNTIME and not shared.Settings.USE_PTHREADS:
# Single threaded MINIMAL_RUNTIME programs do not need access to
# document.currentScript, so a simple export declaration is enough.
src = 'var %s=%s' % (shared.Settings.EXPORT_NAME, src)
if shared.Settings.MINIMAL_RUNTIME and not shared.Settings.USE_PTHREADS:
# Single threaded MINIMAL_RUNTIME programs do not need access to
# document.currentScript, so a simple export declaration is enough.
src = 'var %s=%s' % (shared.Settings.EXPORT_NAME, src)
else:
script_url_node = ""
# When MODULARIZE this JS may be executed later,
# after document.currentScript is gone, so we save it.
# In EXPORT_ES6 + USE_PTHREADS the 'thread' is actually an ES6 module webworker running in strict mode,
# so doesn't have access to 'document'. In this case use 'import.meta' instead.
if shared.Settings.EXPORT_ES6 and shared.Settings.USE_ES6_IMPORT_META:
script_url = "import.meta.url"
else:
script_url_node = ""
# When MODULARIZE this JS may be executed later,
# after document.currentScript is gone, so we save it.
# (when MODULARIZE_INSTANCE, an instance is created
# immediately anyhow, like in non-modularize mode)
# In EXPORT_ES6 + USE_PTHREADS the 'thread' is actually an ES6 module webworker running in strict mode,
# so doesn't have access to 'document'. In this case use 'import.meta' instead.
if shared.Settings.EXPORT_ES6 and shared.Settings.USE_ES6_IMPORT_META:
script_url = "import.meta.url"
else:
script_url = "typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined"
if shared.Settings.target_environment_may_be('node'):
script_url_node = "if (typeof __filename !== 'undefined') _scriptDir = _scriptDir || __filename;"
src = '''
script_url = "typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined"
if shared.Settings.target_environment_may_be('node'):
script_url_node = "if (typeof __filename !== 'undefined') _scriptDir = _scriptDir || __filename;"
src = '''
var %(EXPORT_NAME)s = (function() {
var _scriptDir = %(script_url)s;
%(script_url_node)s
return (%(src)s);
})();
''' % {
'EXPORT_NAME': shared.Settings.EXPORT_NAME,
'script_url': script_url,
'script_url_node': script_url_node,
'src': src
}
else:
# Create the MODULARIZE_INSTANCE instance
# Note that we notice the global Module object, just like in normal
# non-MODULARIZE mode (while MODULARIZE has the user create the instances,
# and the user can decide whether to use Module there or something
# else etc.).
src = '''
var %(EXPORT_NAME)s = (%(src)s)(typeof %(EXPORT_NAME)s === 'object' ? %(EXPORT_NAME)s : {});
''' % {
'EXPORT_NAME': shared.Settings.EXPORT_NAME,
'script_url': script_url,
'script_url_node': script_url_node,
'src': src
}

Expand Down Expand Up @@ -3479,7 +3461,7 @@ def module_export_name_substitution():
src = re.sub(r'{[\'"]?__EMSCRIPTEN_PRIVATE_MODULE_EXPORT_NAME_SUBSTITUTION__[\'"]?:1}', replacement, src)
# For Node.js and other shell environments, create an unminified Module object so that
# loading external .asm.js file that assigns to Module['asm'] works even when Closure is used.
if shared.Settings.MINIMAL_RUNTIME and not shared.Settings.MODULARIZE_INSTANCE and (shared.Settings.target_environment_may_be('node') or shared.Settings.target_environment_may_be('shell')):
if shared.Settings.MINIMAL_RUNTIME and (shared.Settings.target_environment_may_be('node') or shared.Settings.target_environment_may_be('shell')):
src = 'if(typeof Module==="undefined"){var Module={};}' + src
f.write(src)
save_intermediate('module_export_name_substitution')
Expand Down
2 changes: 0 additions & 2 deletions src/postamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ if (memoryInitializer) {
var calledRun;

#if MODULARIZE
#if MODULARIZE_INSTANCE == 0
// Modularize mode returns a function, which can be called to
// create instances. The instances provide a then() method,
// must like a Promise, that receives a callback. The callback
Expand All @@ -149,7 +148,6 @@ Module['then'] = function(func) {
return Module;
};
#endif
#endif

/**
* @constructor
Expand Down
14 changes: 1 addition & 13 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1069,21 +1069,9 @@ var DETERMINISTIC = 0;
// Note that in MODULARIZE mode we do *not* look at the global `Module`
// object, so if you define things there they will be ignored. The reason
// is that you will be constructing the instances manually, and can
// provide Module there, or something else, as you want. This differs
// in MODULARIZE_INSTANCE mode, where we *do* look at the global, since
// as in non-MODULARIZE mode there is just one global instance, and it
// is constructed by the setup code.
// provide Module there, or something else, as you want.
var MODULARIZE = 0;

// Similar to MODULARIZE, but while that mode exports a function, with which you
// can create multiple instances, this option exports a singleton instance. In
// other words, it's the same as if you used MODULARIZE and did EXPORT_NAME =
// EXPORT_NAME() to create the instance manually.
//
// Note that the promise-like API MODULARIZE provides isn't available here
// (since you aren't creating the instance yourself).
var MODULARIZE_INSTANCE = 0;

// If we separate out asm.js with the --separate-asm option,
// this is the name of the variable where the generated asm.js
// Module is assigned to. This name can either be a property
Expand Down
6 changes: 3 additions & 3 deletions src/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ if (Module['ENVIRONMENT']) {
#include "shell_pthreads.js"
#endif

#if USE_PTHREADS && (!MODULARIZE || MODULARIZE_INSTANCE)
#if USE_PTHREADS && !MODULARIZE
// In MODULARIZE mode _scriptDir needs to be captured already at the very top of the page immediately when the page is parsed, so it is generated there
// before the page load. In non-MODULARIZE modes generate it here.
#if EXPORT_ES6
Expand Down Expand Up @@ -276,8 +276,8 @@ if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
} else if (document.currentScript) { // web
scriptDirectory = document.currentScript.src;
}
#if MODULARIZE && MODULARIZE_INSTANCE == 0
// When MODULARIZE (and not _INSTANCE), this JS may be executed later, after document.currentScript
#if MODULARIZE
// When MODULARIZE, this JS may be executed later, after document.currentScript
// is gone, so we saved it, and we use it here instead of any other info.
if (_scriptDir) {
scriptDirectory = _scriptDir;
Expand Down
2 changes: 1 addition & 1 deletion src/shell_minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function ready() {

#if USE_PTHREADS

#if !MODULARIZE || MODULARIZE_INSTANCE
#if !MODULARIZE
// In MODULARIZE mode _scriptDir needs to be captured already at the very top of the page immediately when the page is parsed, so it is generated there
// before the page load. In non-MODULARIZE modes generate it here.
var _scriptDir = (typeof document !== 'undefined' && document.currentScript) ? document.currentScript.src : undefined;
Expand Down
4 changes: 2 additions & 2 deletions src/shell_minimal_runtime.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<body>
<canvas style='display:block; margin:auto;'></canvas>
<script>
#if !MODULARIZE || MODULARIZE_INSTANCE
#if !MODULARIZE
var Module = {
#if USE_PTHREADS
worker: '{{{ PTHREAD_WORKER_FILE }}}'
Expand All @@ -23,7 +23,7 @@
// If we are doing a SINGLE_FILE=1 build, inlined JS runtime code follows here:
{{{ JS_CONTENTS_IN_SINGLE_FILE_BUILD }}}

#if MODULARIZE && !MODULARIZE_INSTANCE
#if MODULARIZE
// Launch the MODULARIZEd build.
{{{ EXPORT_NAME }}}({});
#endif
Expand Down
13 changes: 1 addition & 12 deletions src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ var parentThreadId = 0; // The ID of the parent pthread that launched this threa

var Module = {};

// If we use a custom export name, refer to Module from it as well, so that
// we connect properly to the modularized instance which is the only thing
// in the global scope.
#if MODULARIZE_INSTANCE && EXPORT_NAME != 'Module'
var {{{ EXPORT_NAME }}} = Module;
#endif

#if ASSERTIONS
function assert(condition, text) {
if (!condition) abort('Assertion failed: ' + text);
Expand Down Expand Up @@ -76,12 +69,8 @@ this.onmessage = function(e) {
try {
if (e.data.cmd === 'load') { // Preload command that is called once per worker to parse and load the Emscripten code.
#if MINIMAL_RUNTIME
#if MODULARIZE_INSTANCE
var imports = Module;
#else
var imports = {};
#endif
#endif

#if !WASM_BACKEND
// Initialize the thread-local field(s):
Expand Down Expand Up @@ -155,7 +144,7 @@ this.onmessage = function(e) {
importScripts(objectUrl);
URL.revokeObjectURL(objectUrl);
}
#if MODULARIZE && !MODULARIZE_INSTANCE
#if MODULARIZE
#if MINIMAL_RUNTIME
Module = {{{ EXPORT_NAME }}}(imports);
#else
Expand Down
11 changes: 0 additions & 11 deletions tests/browser/modularize_Module_input.cpp

This file was deleted.

154 changes: 0 additions & 154 deletions tests/browser/modularize_Module_input.html

This file was deleted.

Loading