diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-03-03 12:03:48 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-03-03 12:03:48 -0800 |
commit | d6cff2177ec065aa14f228ab547abc29ef37b248 (patch) | |
tree | 285c3d737500e8a3ed6be56dcaf9357ffd5c7cd9 /src/shell.js | |
parent | dfd9488e0094a6b5433b406517338e0f757c1e27 (diff) | |
parent | 6f57ea8f0eeb220fc81726b4e3a3c02f4232b667 (diff) |
Merge branch 'master' into llvmsvn
Diffstat (limited to 'src/shell.js')
-rw-r--r-- | src/shell.js | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/shell.js b/src/shell.js index d67cc45a..bc527192 100644 --- a/src/shell.js +++ b/src/shell.js @@ -11,6 +11,7 @@ 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) { process['stdout'].write(x + '\n'); }; @@ -29,12 +30,16 @@ if (ENVIRONMENT_IS_NODE) { return ret; }; + load = function(f) { + globalEval(read(f)); + }; + arguments_ = process['argv'].slice(2); } else if (ENVIRONMENT_IS_SHELL) { // Polyfill over SpiderMonkey/V8 differences if (!this['read']) { - read = function(f) { snarf(f) }; + this['read'] = function(f) { snarf(f) }; } if (!this['arguments']) { @@ -44,11 +49,11 @@ if (ENVIRONMENT_IS_NODE) { } } else if (ENVIRONMENT_IS_WEB) { - print = printErr = function(x) { + this['print'] = printErr = function(x) { console.log(x); }; - read = function(url) { + this['read'] = function(url) { var xhr = new XMLHttpRequest(); xhr.open('GET', url, false); xhr.send(null); @@ -61,7 +66,7 @@ if (ENVIRONMENT_IS_NODE) { } else if (ENVIRONMENT_IS_WORKER) { // We can do very little here... - load = importScripts; + this['load'] = importScripts; } else { throw 'Unknown runtime environment. Where are we?'; @@ -72,17 +77,17 @@ function globalEval(x) { } if (typeof load == 'undefined' && typeof read != 'undefined') { - load = function(f) { + this['load'] = function(f) { globalEval(read(f)); }; } if (typeof printErr === 'undefined') { - printErr = function(){}; + this['printErr'] = function(){}; } if (typeof print === 'undefined') { - print = printErr; + this['print'] = printErr; } // *** Environment setup code *** |