aboutsummaryrefslogtreecommitdiff
path: root/src/compiler.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler.js')
-rw-r--r--src/compiler.js21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/compiler.js b/src/compiler.js
index 2015a09d..579cd98f 100644
--- a/src/compiler.js
+++ b/src/compiler.js
@@ -14,7 +14,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
@@ -54,9 +55,6 @@ if (ENVIRONMENT_IS_NODE) {
printErr = function(x) {
console.log(x);
};
- if (typeof print === 'undefined') {
- print = printErr;
- }
read = function(url) {
var xhr = new XMLHttpRequest();
@@ -68,6 +66,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?';
}
@@ -76,11 +79,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 ***