aboutsummaryrefslogtreecommitdiff
path: root/src/compiler.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-02-29 11:36:59 -0800
committerAlon Zakai <alonzakai@gmail.com>2012-02-29 11:36:59 -0800
commitfa69915201b3689ba7ebc8ab411b4eef2046ca3a (patch)
tree3137300363d19000c3e492712fcb78f997d18622 /src/compiler.js
parent4c16a991274dd4f1e37a707b122640f1f844fdba (diff)
better fix for leaked globals
Diffstat (limited to 'src/compiler.js')
-rw-r--r--src/compiler.js24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/compiler.js b/src/compiler.js
index 9e239c1d..134ac5bd 100644
--- a/src/compiler.js
+++ b/src/compiler.js
@@ -17,13 +17,9 @@ var ENVIRONMENT_IS_WEB = typeof window === 'object';
var ENVIRONMENT_IS_WORKER = typeof importScripts === 'function';
var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER;
-if (!ENVIRONMENT_IS_NODE) {
- // Node needs these in the global scope, everywhere else, cleaner to not pollute the global scope
- eval('var print, printErr, read, load, arguments_;');
-}
-
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');
};
@@ -42,12 +38,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']) {
@@ -57,11 +57,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);
@@ -74,7 +74,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?';
@@ -85,17 +85,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 ***