diff options
author | Alon Zakai <alonzakai@gmail.com> | 2011-12-12 16:02:19 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2011-12-12 16:02:19 -0800 |
commit | 8d7e09462e4f4c5fa10725d4b04caa7be5778749 (patch) | |
tree | 04d9dbec50289a1bd95a8bd7645ab507713477fe /src/shell.js | |
parent | 94476d0fcde4f3b55dd05014c7394ba2d088f076 (diff) |
fixes to allow generated code to run in a web worker
Diffstat (limited to 'src/shell.js')
-rw-r--r-- | src/shell.js | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/shell.js b/src/shell.js index 038fde02..61f2d5cd 100644 --- a/src/shell.js +++ b/src/shell.js @@ -6,7 +6,8 @@ var arguments_ = []; var ENVIRONMENT_IS_NODE = typeof process === 'object'; var ENVIRONMENT_IS_WEB = typeof window === 'object'; -var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE; +var ENVIRONMENT_IS_WORKER = typeof importScripts === 'function'; +var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER; if (ENVIRONMENT_IS_NODE) { // Expose functionality in the same simple way that the shells work @@ -46,9 +47,6 @@ if (ENVIRONMENT_IS_NODE) { printErr = function(x) { console.log(x); }; - if (typeof print === 'undefined') { - print = printErr; - } read = function(url) { var xhr = new XMLHttpRequest(); @@ -60,6 +58,11 @@ if (ENVIRONMENT_IS_NODE) { if (this['arguments']) { arguments_ = arguments; } +} else if (ENVIRONMENT_IS_WORKER) { + // We can do very little here... + + load = importScripts; + } else { throw 'Unknown runtime environment. Where are we?'; } @@ -68,11 +71,19 @@ function globalEval(x) { eval.call(null, x); } -if (!this['load']) { +if (typeof load == 'undefined' && typeof read != 'undefined') { load = function(f) { globalEval(read(f)); }; } + +if (typeof printErr === 'undefined') { + printErr = function(){}; +} + +if (typeof print === 'undefined') { + print = printErr; +} // *** Environment setup code *** |