aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/preamble.js2
-rw-r--r--src/shell.js80
-rwxr-xr-xtests/runner.py6
3 files changed, 44 insertions, 44 deletions
diff --git a/src/preamble.js b/src/preamble.js
index 411abce6..218e0388 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -281,7 +281,7 @@ Module["ccall"] = ccall;
// Returns the C function with a specified identifier (for C++, you need to do manual name mangling)
function getCFunc(ident) {
try {
- var func = globalScope['Module']['_' + ident]; // closure exported function
+ var func = Module['_' + ident]; // closure exported function
if (!func) func = eval('_' + ident); // explicit lookup
} catch(e) {
}
diff --git a/src/shell.js b/src/shell.js
index 1f987926..679201d0 100644
--- a/src/shell.js
+++ b/src/shell.js
@@ -1,8 +1,14 @@
-try {
- this['Module'] = Module;
- Module.test;
-} catch(e) {
- this['Module'] = Module = {};
+// Sometimes an existing Module object exists with properties
+// meant to overwrite the default module functionality. Here
+// we collect those properties and reapply _after_ we configure
+// the current environment's defaults to avoid having to be so
+// defensive during initialization.
+var Module = typeof {{{ EXPORT_NAME }}} !== 'undefined' ? {{{ EXPORT_NAME }}} : {};
+var moduleOverrides = {};
+for (var key in Module) {
+ if (Module.hasOwnProperty(key)) {
+ moduleOverrides[key] = Module[key];
+ }
}
// The environment setup code below is customized to use Module.
@@ -43,9 +49,7 @@ if (ENVIRONMENT_IS_NODE) {
globalEval(read(f));
};
- if (!Module['arguments']) {
- Module['arguments'] = process['argv'].slice(2);
- }
+ Module['arguments'] = process['argv'].slice(2);
module.exports = Module;
}
@@ -59,29 +63,23 @@ if (ENVIRONMENT_IS_SHELL) {
return read(f, 'binary');
};
- if (!Module['arguments']) {
- if (typeof scriptArgs != 'undefined') {
- Module['arguments'] = scriptArgs;
- } else if (typeof arguments != 'undefined') {
- Module['arguments'] = arguments;
- }
+ if (typeof scriptArgs != 'undefined') {
+ Module['arguments'] = scriptArgs;
+ } else if (typeof arguments != 'undefined') {
+ Module['arguments'] = arguments;
}
-
+
this['{{{ EXPORT_NAME }}}'] = Module;
}
if (ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_WORKER) {
- if (!Module['print']) {
- Module['print'] = function(x) {
- console.log(x);
- };
- }
+ Module['print'] = function(x) {
+ console.log(x);
+ };
- if (!Module['printErr']) {
- Module['printErr'] = function(x) {
- console.log(x);
- };
- }
+ Module['printErr'] = function(x) {
+ console.log(x);
+ };
this['{{{ EXPORT_NAME }}}'] = Module;
}
@@ -94,23 +92,19 @@ if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
return xhr.responseText;
};
- if (!Module['arguments']) {
- if (typeof arguments != 'undefined') {
- Module['arguments'] = arguments;
- }
+ if (typeof arguments != 'undefined') {
+ Module['arguments'] = arguments;
}
}
if (ENVIRONMENT_IS_WORKER) {
// We can do very little here...
var TRY_USE_DUMP = false;
- if (!Module['print']) {
- Module['print'] = (TRY_USE_DUMP && (typeof(dump) !== "undefined") ? (function(x) {
- dump(x);
- }) : (function(x) {
- // self.postMessage(x); // enable this if you want stdout to be sent as messages
- }));
- }
+ Module['print'] = (TRY_USE_DUMP && (typeof(dump) !== "undefined") ? (function(x) {
+ dump(x);
+ }) : (function(x) {
+ // self.postMessage(x); // enable this if you want stdout to be sent as messages
+ }));
Module['load'] = importScripts;
}
@@ -144,10 +138,16 @@ Module.print = Module['print'];
Module.printErr = Module['printErr'];
// Callbacks
-if (!Module['preRun']) Module['preRun'] = [];
-if (!Module['postRun']) Module['postRun'] = [];
+Module['preRun'] = [];
+Module['postRun'] = [];
- {{BODY}}
+// Merge back in the overrides
+for (var key in moduleOverrides) {
+ if (moduleOverrides.hasOwnProperty(key)) {
+ Module[key] = moduleOverrides[key];
+ }
+}
- // {{MODULE_ADDITIONS}}
+{{BODY}}
+// {{MODULE_ADDITIONS}}
diff --git a/tests/runner.py b/tests/runner.py
index 6c890402..15f0070a 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -10507,11 +10507,11 @@ Options that are modified or new in %s include:
assert 'SAFE_HEAP' not in generated, 'safe heap should not be used by default'
assert ': while(' not in generated, 'when relooping we also js-optimize, so there should be no labelled whiles'
if closure:
- if opt_level == 0: assert 'Module._main =' in generated, 'closure compiler should have been run'
- elif opt_level >= 1: assert 'Module._main=' in generated, 'closure compiler should have been run (and output should be minified)'
+ if opt_level == 0: assert '._main =' in generated, 'closure compiler should have been run'
+ elif opt_level >= 1: assert '._main=' in generated, 'closure compiler should have been run (and output should be minified)'
else:
# closure has not been run, we can do some additional checks. TODO: figure out how to do these even with closure
- assert 'Module._main = ' not in generated, 'closure compiler should not have been run'
+ assert '._main = ' not in generated, 'closure compiler should not have been run'
if keep_debug:
assert ('(label)' in generated or '(label | 0)' in generated) == (opt_level <= 1), 'relooping should be in opt >= 2'
assert ('assert(STACKTOP < STACK_MAX' in generated) == (opt_level == 0), 'assertions should be in opt == 0'