aboutsummaryrefslogtreecommitdiff
path: root/tests/hello_world.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-12-12 16:02:19 -0800
committerAlon Zakai <alonzakai@gmail.com>2011-12-12 16:02:19 -0800
commit8d7e09462e4f4c5fa10725d4b04caa7be5778749 (patch)
tree04d9dbec50289a1bd95a8bd7645ab507713477fe /tests/hello_world.js
parent94476d0fcde4f3b55dd05014c7394ba2d088f076 (diff)
fixes to allow generated code to run in a web worker
Diffstat (limited to 'tests/hello_world.js')
-rw-r--r--tests/hello_world.js21
1 files changed, 16 insertions, 5 deletions
diff --git a/tests/hello_world.js b/tests/hello_world.js
index 530f5d4c..24bc0fdd 100644
--- a/tests/hello_world.js
+++ b/tests/hello_world.js
@@ -3,7 +3,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
@@ -43,9 +44,6 @@ if (ENVIRONMENT_IS_NODE) {
printErr = function(x) {
console.log(x);
};
- if (typeof print === 'undefined') {
- print = printErr;
- }
read = function(url) {
var xhr = new XMLHttpRequest();
@@ -57,6 +55,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?';
}
@@ -65,11 +68,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 ***
print('hello, world!');