aboutsummaryrefslogtreecommitdiff
path: root/src/shell.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-10-22 15:18:13 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-10-22 15:18:13 -0700
commitdafd2a3f15a530e1fd79fa9bf432947ab78a8501 (patch)
tree3dab09e9217bb57ad0c054b68543de77e90448c7 /src/shell.js
parente2575e4a5c49f8c644e7055074775db3fa91358a (diff)
parent11a4926fc6c2bfe43fef3c66ad30e4b2df612616 (diff)
Merge branch 'incoming'
Diffstat (limited to 'src/shell.js')
-rw-r--r--src/shell.js26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/shell.js b/src/shell.js
index 891a6328..d6dc0fb5 100644
--- a/src/shell.js
+++ b/src/shell.js
@@ -44,7 +44,9 @@ if (ENVIRONMENT_IS_NODE) {
if (!Module['arguments']) {
Module['arguments'] = process['argv'].slice(2);
}
-} else if (ENVIRONMENT_IS_SHELL) {
+}
+
+if (ENVIRONMENT_IS_SHELL) {
Module['print'] = print;
if (typeof printErr != 'undefined') Module['printErr'] = printErr; // not present in v8 or older sm
@@ -62,7 +64,9 @@ if (ENVIRONMENT_IS_NODE) {
Module['arguments'] = arguments;
}
}
-} else if (ENVIRONMENT_IS_WEB) {
+}
+
+if (ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_WORKER) {
if (!Module['print']) {
Module['print'] = function(x) {
console.log(x);
@@ -74,7 +78,9 @@ if (ENVIRONMENT_IS_NODE) {
console.log(x);
};
}
+}
+if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
Module['read'] = function(url) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, false);
@@ -87,12 +93,24 @@ if (ENVIRONMENT_IS_NODE) {
Module['arguments'] = arguments;
}
}
-} else if (ENVIRONMENT_IS_WORKER) {
+}
+
+if (ENVIRONMENT_IS_WORKER) {
// We can do very little here...
+ var TRY_USE_DUMP = false;
+ if (!Module['print']) {
+ Module['print'] = (TRY_USE_DUMP && (typeof(dump) !== "undefined") ? (function(x) {
+ dump(x);
+ }) : (function(x) {
+ // self.postMessage(x); // enable this if you want stdout to be sent as messages
+ }));
+ }
Module['load'] = importScripts;
+}
-} else {
+if (!ENVIRONMENT_IS_WORKER && !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_SHELL) {
+ // Unreachable because SHELL is dependant on the others
throw 'Unknown runtime environment. Where are we?';
}