aboutsummaryrefslogtreecommitdiff
path: root/tests/hello_world.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-12-04 20:44:29 -0800
committerAlon Zakai <alonzakai@gmail.com>2011-12-04 20:44:29 -0800
commit08e7619a88c246baf022a9cfdeafc21db068b9d0 (patch)
tree674bd9c6f3b262d4454b34a16ab7aabf508e648d /tests/hello_world.js
parent51fbd38572cb1cd01950c038e7d7ab9fed8cac2a (diff)
sanity check for compiler engine in test runner
Diffstat (limited to 'tests/hello_world.js')
-rw-r--r--tests/hello_world.js73
1 files changed, 73 insertions, 0 deletions
diff --git a/tests/hello_world.js b/tests/hello_world.js
new file mode 100644
index 00000000..3fd19d53
--- /dev/null
+++ b/tests/hello_world.js
@@ -0,0 +1,73 @@
+// *** Environment setup code ***
+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;
+
+if (ENVIRONMENT_IS_NODE) {
+ // Expose functionality in the same simple way that the shells work
+ print = function(x) {
+ process['stdout'].write(x + '\n');
+ };
+ printErr = function(x) {
+ process['stderr'].write(x + '\n');
+ };
+
+ var nodeFS = require('fs');
+
+ read = function(filename) {
+ var ret = nodeFS['readFileSync'](filename).toString();
+ if (!ret && filename[0] != '/') {
+ filename = __dirname.split('/').slice(0, -1).join('/') + '/src/' + filename;
+ ret = nodeFS['readFileSync'](filename).toString();
+ }
+ return ret;
+ };
+
+ arguments_ = process['argv'].slice(2);
+
+} else if (ENVIRONMENT_IS_SHELL) {
+ // Polyfill over SpiderMonkey/V8 differences
+ if (!this['read']) {
+ read = function(f) { snarf(f) };
+ }
+
+ if (!this['arguments']) {
+ arguments_ = scriptArgs;
+ } else {
+ arguments_ = arguments;
+ }
+
+} else if (ENVIRONMENT_IS_WEB) {
+ printErr = function(x) {
+ console.log(x);
+ };
+
+ read = function(url) {
+ var xhr = new XMLHttpRequest();
+ xhr.open('GET', url, false);
+ xhr.send(null);
+ return xhr.responseText;
+ };
+
+ if (this['arguments']) {
+ arguments_ = arguments;
+ }
+} else {
+ throw 'Unknown runtime environment. Where are we?';
+}
+
+function globalEval(x) {
+ eval.call(null, x);
+}
+
+if (!this['load']) {
+ load = function(f) {
+ globalEval(read(f));
+ };
+}
+// *** Environment setup code ***
+
+print('hello, world!');
+