aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/compiler.js3
-rw-r--r--src/library.js18
-rw-r--r--src/library_sdl.js4
-rw-r--r--src/postamble.js2
-rw-r--r--src/preamble.js85
-rw-r--r--src/shell.js86
6 files changed, 76 insertions, 122 deletions
diff --git a/src/compiler.js b/src/compiler.js
index 2e95552d..c39927e7 100644
--- a/src/compiler.js
+++ b/src/compiler.js
@@ -8,7 +8,8 @@ try {
} catch(e) {}
-// The environment setup code appears here, in shell.js, in js_optimizer.js and in tests/hello_world.js because it can't be shared. Keep them in sync!
+// The environment setup code appears here, in js_optimizer.js and in tests/hello_world.js because it can't be shared. Keep them in sync!
+// It also appears, in modified form, in shell.js.
// *** Environment setup code ***
var arguments_ = [];
diff --git a/src/library.js b/src/library.js
index 8f4e5799..f7ae62cb 100644
--- a/src/library.js
+++ b/src/library.js
@@ -256,12 +256,12 @@ LibraryManager.library = {
if (typeof XMLHttpRequest !== 'undefined') {
// Browser.
assert('Cannot do synchronous binary XHRs in modern browsers. Use --embed-file or --preload-file in emcc');
- } else if (typeof read !== 'undefined') {
+ } else if (Module.read) {
// Command-line.
try {
// WARNING: Can't read binary files in V8's d8 or tracemonkey's js, as
// read() will try to parse UTF8.
- obj.contents = intArrayFromString(read(obj.url), true);
+ obj.contents = intArrayFromString(Module.read(obj.url), true);
} catch (e) {
success = false;
}
@@ -331,13 +331,13 @@ LibraryManager.library = {
stdoutOverridden = false;
output = simpleOutput;
}
- if (!output.printer) output.printer = print;
+ if (!output.printer) output.printer = Module['print'];
if (!output.buffer) output.buffer = [];
if (!error) {
stderrOverridden = false;
error = simpleOutput;
}
- if (!error.printer) error.printer = print;
+ if (!error.printer) error.printer = Module['print'];
if (!error.buffer) error.buffer = [];
// Create the temporary folder.
@@ -4405,7 +4405,7 @@ LibraryManager.library = {
___cxa_throw.initialized = true;
}
#if EXCEPTION_DEBUG
- print('Compiled code throwing an exception, ' + [ptr,type,destructor] + ', at ' + new Error().stack);
+ Module.printErr('Compiled code throwing an exception, ' + [ptr,type,destructor] + ', at ' + new Error().stack);
#endif
{{{ makeSetValue('_llvm_eh_exception.buf', '0', 'ptr', 'void*') }}}
{{{ makeSetValue('_llvm_eh_exception.buf', QUANTUM_SIZE, 'type', 'void*') }}}
@@ -4959,7 +4959,7 @@ LibraryManager.library = {
var lib_module = eval(lib_data)(FUNCTION_TABLE.length);
} catch (e) {
#if ASSERTIONS
- print('Error in loading dynamic library: ' + e);
+ Module.printErr('Error in loading dynamic library: ' + e);
#endif
DLFCN_DATA.errorMsg = 'Could not evaluate dynamic lib: ' + filename;
return 0;
@@ -5996,12 +5996,12 @@ LibraryManager.library = {
invalid: 0,
dump: function() {
if (Profiling.invalid) {
- print('Invalid # of calls to Profiling begin and end!');
+ Module.printErr('Invalid # of calls to Profiling begin and end!');
return;
}
- print('Profiling data:')
+ Module.printErr('Profiling data:')
for (var i = 0; i < Profiling.max_; i++) {
- print('Block ' + i + ': ' + Profiling.times[i]);
+ Module.printErr('Block ' + i + ': ' + Profiling.times[i]);
}
}
},
diff --git a/src/library_sdl.js b/src/library_sdl.js
index d1247f9e..4c125989 100644
--- a/src/library_sdl.js
+++ b/src/library_sdl.js
@@ -280,7 +280,7 @@ mergeInto(LibraryManager.library, {
},
SDL_Quit: function() {
- print('SDL_Quit called (and ignored)');
+ Module.print('SDL_Quit called (and ignored)');
},
SDL_LockSurface: function(surf) {
@@ -369,7 +369,7 @@ mergeInto(LibraryManager.library, {
},
SDL_Delay: function(delay) {
- print('SDL_Delay called! - potential infinite loop');
+ Module.print('SDL_Delay called! - potential infinite loop');
},
SDL_WM_SetCaption: function(title, icon) {
diff --git a/src/postamble.js b/src/postamble.js
index 7371ff05..4a2fbf60 100644
--- a/src/postamble.js
+++ b/src/postamble.js
@@ -59,7 +59,7 @@ addRunDependency();
if (runDependencies == 0) {
var ret = run();
#if CATCH_EXIT_CODE
- print('Exit Status: ' + ret);
+ Module.print('Exit Status: ' + ret);
#endif
}
diff --git a/src/preamble.js b/src/preamble.js
index 1c599836..db092045 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -14,7 +14,7 @@ var HEAP_WATCHED = [];
var HEAP_HISTORY = [];
function SAFE_HEAP_CLEAR(dest) {
#if SAFE_HEAP_LOG
- print('SAFE_HEAP clear: ' + dest);
+ Module.print('SAFE_HEAP clear: ' + dest);
#endif
HEAP_HISTORY[dest] = [];
}
@@ -22,7 +22,7 @@ var SAFE_HEAP_ERRORS = 0;
var ACCEPTABLE_SAFE_HEAP_ERRORS = 0;
function SAFE_HEAP_ACCESS(dest, type, store, ignore) {
- //if (dest === A_NUMBER) print ([dest, type, store] + ' ' + new Error().stack); // Something like this may be useful, in debugging
+ //if (dest === A_NUMBER) Module.print ([dest, type, store] + ' ' + new Error().stack); // Something like this may be useful, in debugging
#if USE_TYPED_ARRAYS
// When using typed arrays, reads over the top of TOTAL_MEMORY will fail silently, so we must
@@ -59,12 +59,12 @@ function SAFE_HEAP_ACCESS(dest, type, store, ignore) {
// assert((history && history[0]) /* || HEAP[dest] === 0 */, "Loading from where there was no store! " + dest + ',' + HEAP[dest] + ',' + type + ', \n\n' + new Error().stack + '\n');
// if (history[0].type !== type) {
if (history !== type && !ignore) {
- print('Load-store consistency assumption failure! ' + dest);
- print('\n');
- print(JSON.stringify(history));
- print('\n');
- print('LOAD: ' + type + ', ' + new Error().stack);
- print('\n');
+ Module.print('Load-store consistency assumption failure! ' + dest);
+ Module.print('\n');
+ Module.print(JSON.stringify(history));
+ Module.print('\n');
+ Module.print('LOAD: ' + type + ', ' + new Error().stack);
+ Module.print('\n');
SAFE_HEAP_ERRORS++;
assert(SAFE_HEAP_ERRORS <= ACCEPTABLE_SAFE_HEAP_ERRORS, 'Load-store consistency assumption failure!');
}
@@ -73,7 +73,7 @@ function SAFE_HEAP_ACCESS(dest, type, store, ignore) {
function SAFE_HEAP_STORE(dest, value, type, ignore) {
#if SAFE_HEAP_LOG
- print('SAFE_HEAP store: ' + [dest, type, value, ignore]);
+ Module.print('SAFE_HEAP store: ' + [dest, type, value, ignore]);
#endif
if (!ignore && !value && value !== 0 && value !== false && !isNaN(value)) { // false can be the result of a mathop comparator; NaN can be the result of a math function
@@ -81,7 +81,7 @@ function SAFE_HEAP_STORE(dest, value, type, ignore) {
}
SAFE_HEAP_ACCESS(dest, type, true, ignore);
if (dest in HEAP_WATCHED) {
- print((new Error()).stack);
+ Module.print((new Error()).stack);
throw "Bad store!" + dest;
}
@@ -107,7 +107,7 @@ function SAFE_HEAP_LOAD(dest, type, unsigned, ignore) {
SAFE_HEAP_ACCESS(dest, type, ignore);
#if SAFE_HEAP_LOG
- print('SAFE_HEAP load: ' + [dest, type, getValue(dest, type, 1), ignore]);
+ Module.print('SAFE_HEAP load: ' + [dest, type, getValue(dest, type, 1), ignore]);
#endif
#if USE_TYPED_ARRAYS == 2
@@ -132,7 +132,7 @@ function SAFE_HEAP_LOAD(dest, type, unsigned, ignore) {
function SAFE_HEAP_COPY_HISTORY(dest, src) {
#if SAFE_HEAP_LOG
- print('SAFE_HEAP copy: ' + [dest, src]);
+ Module.print('SAFE_HEAP copy: ' + [dest, src]);
#endif
HEAP_HISTORY[dest] = HEAP_HISTORY[src];
SAFE_HEAP_ACCESS(dest, HEAP_HISTORY[dest] || null, true, false);
@@ -160,7 +160,7 @@ var CorrectionsMonitor = {
sig = (new Error().stack).toString().split('\n')[2].split(':').slice(-1)[0]; // Spidermonkey-specific FIXME
sig = type + '|' + sig;
if (!this.sigs[sig]) {
- //print('Correction: ' + sig);
+ //Module.print('Correction: ' + sig);
this.sigs[sig] = [0, 0]; // fail, succeed
}
this.sigs[sig][succeed ? 1 : 0]++;
@@ -181,7 +181,7 @@ var CorrectionsMonitor = {
items.sort(function(x, y) { return y.total - x.total; });
for (var i = 0; i < items.length; i++) {
var item = items[i];
- print(item.sig + ' : ' + item.total + ' hits, %' + (Math.ceil(100*item.fails/item.total)) + ' failures');
+ Module.print(item.sig + ' : ' + item.total + ' hits, %' + (Math.ceil(100*item.fails/item.total)) + ' failures');
}
#endif
}
@@ -253,7 +253,7 @@ Module['stopProfiling'] = stopProfiling;
function printProfiling() {
function dumpData(name_, node, indent) {
- print(indent + ('________' + node.time).substr(-8) + ': ' + name_ + ' (' + node.calls + ')');
+ Module.print(indent + ('________' + node.time).substr(-8) + ': ' + name_ + ' (' + node.calls + ')');
var children = [];
for (var child in node.children) {
children.push(node.children[child]);
@@ -265,57 +265,6 @@ function printProfiling() {
dumpData('root', PROFILING_ROOT, ' ');
}
Module['printProfiling'] = printProfiling;
-
-function printXULProfiling() {
- function dumpData(name_, node, indent) {
- var children = [];
- for (var child in node.children) {
- children.push(node.children[child]);
- children[children.length-1].name_ = child;
- }
- print('<treeitem' + (children.length > 0 ? ' container="true"' : '') + '>');
- print(' <treerow>');
- print(' <treecell label="' + name_ + '"/>');
- print(' <treecell label="' + node.time + '"/>');
- print(' <treecell label="' + node.calls + '"/>');
- print(' </treerow>');
-
- if (children.length > 0) {
- print(' <treechildren>');
- children.sort(function(x, y) { return y.time - x.time });
- children.forEach(function(child) { dumpData(child.name_, child, indent + ' ') });
- print(' </treechildren>');
- }
-
- print('</treeitem>');
- }
-
- print('<?xml version="1.0"?>');
- print('<?xml-stylesheet href="chrome://global/skin/" type="text/css"?> ');
- print('<?xml-stylesheet href="file://C:/main.css" type="text/css"?> ');
- print('<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> ');
- print('<tree id="myTree" flex="1" hidecolumnpicker="false" seltype="single" class="tree"');
- print(' rows="5">');
- print(' <treecols id="myTree2-treeCols">');
- print(' <treecol id="myTree2-treeCol0" primary="true" flex="2" label="Name"');
- print(' persist="width" ordinal="1"/>');
- print(' <splitter class="tree-splitter" ordinal="2"/>');
- print(' <treecol id="myTree2-treeCol1" flex="1" label="Milliseconds"');
- print(' persist="width" ordinal="3"/>');
- print(' <treecol id="myTree2-treeCol2" flex="1" label="Calls"');
- print(' persist="width" ordinal="4"/>');
- print(' </treecols>');
- print(' <treechildren>');
-
- dumpData('root', PROFILING_ROOT, ' ');
-
- print(' </treechildren>');
- print('</tree>');
- print('</window>');
-
- // This requires dom.allow_XUL_XBL_for_file
-}
-Module['printXULProfiling'] = printXULProfiling;
#endif
//========================================
@@ -335,7 +284,7 @@ var tempI64, tempI64b;
#endif
function abort(text) {
- print(text + ':\n' + (new Error).stack);
+ Module.print(text + ':\n' + (new Error).stack);
ABORT = true;
throw "Assertion: " + text;
}
@@ -603,7 +552,7 @@ var STATICTOP;
function enlargeMemory() {
// TOTAL_MEMORY is the current size of the actual array, and STATICTOP is the new top.
#if ASSERTIONS
- printErr('Warning: Enlarging memory arrays, this is not fast! ' + [STATICTOP, TOTAL_MEMORY]);
+ Module.printErr('Warning: Enlarging memory arrays, this is not fast! ' + [STATICTOP, TOTAL_MEMORY]);
assert(STATICTOP >= TOTAL_MEMORY);
assert(TOTAL_MEMORY > 4); // So the loop below will not be infinite
#endif
diff --git a/src/shell.js b/src/shell.js
index 1648218a..5b6419c0 100644
--- a/src/shell.js
+++ b/src/shell.js
@@ -1,9 +1,13 @@
// TODO: " u s e s t r i c t ";
+try {
+ this['Module'] = Module;
+} catch(e) {
+ this['Module'] = Module = {};
+}
+// The environment setup code below is customized to use Module.
// *** Environment setup code ***
-var arguments_ = [];
-
var ENVIRONMENT_IS_NODE = typeof process === 'object';
var ENVIRONMENT_IS_WEB = typeof window === 'object';
var ENVIRONMENT_IS_WORKER = typeof importScripts === 'function';
@@ -12,16 +16,16 @@ var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIR
if (ENVIRONMENT_IS_NODE) {
// Expose functionality in the same simple way that the shells work
// Note that we pollute the global namespace here, otherwise we break in node
- print = function(x) {
+ Module['print'] = function(x) {
process['stdout'].write(x + '\n');
};
- printErr = function(x) {
+ Module['printErr'] = function(x) {
process['stderr'].write(x + '\n');
};
var nodeFS = require('fs');
- read = function(filename) {
+ Module['read'] = function(filename) {
var ret = nodeFS['readFileSync'](filename).toString();
if (!ret && filename[0] != '/') {
filename = __dirname.split('/').slice(0, -1).join('/') + '/src/' + filename;
@@ -30,43 +34,56 @@ if (ENVIRONMENT_IS_NODE) {
return ret;
};
- load = function(f) {
+ Module['load'] = function(f) {
globalEval(read(f));
};
- arguments_ = process['argv'].slice(2);
+ Module['arguments'] = process['argv'].slice(2);
} else if (ENVIRONMENT_IS_SHELL) {
+ Module['print'] = print;
+ Module['printErr'] = printErr;
+
// Polyfill over SpiderMonkey/V8 differences
- if (!this['read']) {
- this['read'] = function(f) { snarf(f) };
+ if (typeof read != 'undefined') {
+ Module['read'] = read;
+ } else {
+ Module['read'] = function(f) { snarf(f) };
}
if (typeof scriptArgs != 'undefined') {
- arguments_ = scriptArgs;
+ Module['arguments'] = scriptArgs;
} else if (typeof arguments != 'undefined') {
- arguments_ = arguments;
+ Module['arguments'] = arguments;
}
} else if (ENVIRONMENT_IS_WEB) {
- this['print'] = printErr = function(x) {
- console.log(x);
- };
+ if (!Module['print']) {
+ Module['print'] = function(x) {
+ console.log(x);
+ };
+ }
+
+ if (!Module['printErr']) {
+ Module['printErr'] = function(x) {
+ console.log(x);
+ };
+ }
- this['read'] = function(url) {
+ Module['read'] = function(url) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, false);
xhr.send(null);
return xhr.responseText;
};
- if (this['arguments']) {
- arguments_ = arguments;
+ if (typeof arguments != 'undefined') {
+ Module['arguments'] = arguments;
}
} else if (ENVIRONMENT_IS_WORKER) {
// We can do very little here...
- this['load'] = importScripts;
+ Module['load'] = importScripts;
} else {
throw 'Unknown runtime environment. Where are we?';
@@ -75,34 +92,21 @@ if (ENVIRONMENT_IS_NODE) {
function globalEval(x) {
eval.call(null, x);
}
-
-if (typeof load == 'undefined' && typeof read != 'undefined') {
- this['load'] = function(f) {
- globalEval(read(f));
+if (!Module['load'] == 'undefined' && Module['read']) {
+ Module['load'] = function(f) {
+ globalEval(Module['read'](f));
};
}
-
-if (typeof printErr === 'undefined') {
- this['printErr'] = function(){};
-}
-
-if (typeof print === 'undefined') {
- this['print'] = printErr;
-}
-// *** Environment setup code ***
-
-
-try {
- this['Module'] = Module;
-} catch(e) {
- this['Module'] = Module = {};
+if (!Module['printErr']) {
+ Module['printErr'] = function(){};
}
-if (!Module.arguments) {
- Module.arguments = arguments_;
+if (!Module['print']) {
+ Module['print'] = Module['printErr'];
}
-if (Module.print) {
- print = Module.print;
+if (!Module['arguments']) {
+ Module['arguments'] = [];
}
+// *** Environment setup code ***
{{BODY}}