Browse Source

utils.js links to sys.js instead of other way around

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
2b8ab7e24f
  1. 16
      lib/http.js
  2. 22
      lib/repl.js
  3. 1
      lib/sys.js
  4. 69
      lib/sys.js
  5. 69
      lib/utils.js
  6. 1
      lib/utils.js
  7. 2
      src/node.js
  8. 10
      src/util.js

16
lib/http.js

@ -1,4 +1,4 @@
var utils = require("/utils.js"); var sys = require("/sys.js");
var CRLF = "\r\n"; var CRLF = "\r\n";
var STATUS_CODES = { var STATUS_CODES = {
@ -502,11 +502,11 @@ exports.createClient = function (port, host) {
client._pushRequest = function (req) { client._pushRequest = function (req) {
req.addListener("flush", function () { req.addListener("flush", function () {
if (client.readyState == "closed") { if (client.readyState == "closed") {
//utils.debug("HTTP CLIENT request flush. reconnect. readyState = " + client.readyState); //sys.debug("HTTP CLIENT request flush. reconnect. readyState = " + client.readyState);
client.connect(port, host); // reconnect client.connect(port, host); // reconnect
return; return;
} }
//utils.debug("client flush readyState = " + client.readyState); //sys.debug("client flush readyState = " + client.readyState);
if (req == requests[0]) flushMessageQueue(client, [req]); if (req == requests[0]) flushMessageQueue(client, [req]);
}); });
requests.push(req); requests.push(req);
@ -517,7 +517,7 @@ exports.createClient = function (port, host) {
}); });
client.addListener("eof", function () { client.addListener("eof", function () {
//utils.debug("client got eof closing. readyState = " + client.readyState); //sys.debug("client got eof closing. readyState = " + client.readyState);
client.close(); client.close();
}); });
@ -527,20 +527,20 @@ exports.createClient = function (port, host) {
return; return;
} }
//utils.debug("HTTP CLIENT onClose. readyState = " + client.readyState); //sys.debug("HTTP CLIENT onClose. readyState = " + client.readyState);
// If there are more requests to handle, reconnect. // If there are more requests to handle, reconnect.
if (requests.length > 0 && client.readyState != "opening") { if (requests.length > 0 && client.readyState != "opening") {
//utils.debug("HTTP CLIENT: reconnecting readyState = " + client.readyState); //sys.debug("HTTP CLIENT: reconnecting readyState = " + client.readyState);
client.connect(port, host); // reconnect client.connect(port, host); // reconnect
} }
}); });
createIncomingMessageStream(client, function (res) { createIncomingMessageStream(client, function (res) {
//utils.debug("incoming response!"); //sys.debug("incoming response!");
res.addListener("complete", function ( ) { res.addListener("complete", function ( ) {
//utils.debug("request complete disconnecting. readyState = " + client.readyState); //sys.debug("request complete disconnecting. readyState = " + client.readyState);
client.close(); client.close();
}); });

22
lib/repl.js

@ -1,9 +1,9 @@
// A repl library that you can include in your own code to get a runtime // A repl library that you can include in your own code to get a runtime
// interface to your program. Just require("/repl.js"). // interface to your program. Just require("/repl.js").
var utils = require("utils.js"); var sys = require("/sys.js");
utils.puts("Type '.help' for options."); sys.puts("Type '.help' for options.");
var buffered_cmd = ''; var buffered_cmd = '';
@ -49,7 +49,7 @@ function readline (cmd) {
var ret = eval(buffered_cmd); var ret = eval(buffered_cmd);
if (ret !== undefined) { if (ret !== undefined) {
exports.scope['_'] = ret; exports.scope['_'] = ret;
utils.p(ret); sys.p(ret);
} }
} }
@ -60,9 +60,9 @@ function readline (cmd) {
} catch (e) { } catch (e) {
// On error: Print the error and clear the buffer // On error: Print the error and clear the buffer
if (e.stack) { if (e.stack) {
utils.puts(e.stack); sys.puts(e.stack);
} else { } else {
utils.puts(e.toString()); sys.puts(e.toString());
} }
buffered_cmd = ''; buffered_cmd = '';
} }
@ -75,7 +75,7 @@ function readline (cmd) {
* Used to display the prompt. * Used to display the prompt.
*/ */
function displayPrompt () { function displayPrompt () {
utils.print(buffered_cmd.length ? '... ' : exports.prompt); sys.print(buffered_cmd.length ? '... ' : exports.prompt);
} }
/** /**
@ -91,7 +91,7 @@ function parseREPLKeyword (cmd) {
displayPrompt(); displayPrompt();
return true; return true;
case ".clear": case ".clear":
utils.puts("Clearing Scope..."); sys.puts("Clearing Scope...");
buffered_cmd = ''; buffered_cmd = '';
exports.scope = {}; exports.scope = {};
displayPrompt(); displayPrompt();
@ -100,10 +100,10 @@ function parseREPLKeyword (cmd) {
node.stdio.close(); node.stdio.close();
return true; return true;
case ".help": case ".help":
utils.puts(".break\tSometimes you get stuck in a place you can't get out... This will get you out."); sys.puts(".break\tSometimes you get stuck in a place you can't get out... This will get you out.");
utils.puts(".clear\tBreak, and also clear the local scope."); sys.puts(".clear\tBreak, and also clear the local scope.");
utils.puts(".exit\tExit the prompt"); sys.puts(".exit\tExit the prompt");
utils.puts(".help\tShow repl options"); sys.puts(".help\tShow repl options");
displayPrompt(); displayPrompt();
return true; return true;
} }

1
lib/sys.js

@ -1 +0,0 @@
utils.js

69
lib/sys.js

@ -0,0 +1,69 @@
exports.print = function (x) {
node.stdio.write(x);
};
exports.puts = function (x) {
node.stdio.write(x.toString() + "\n");
};
exports.debug = function (x) {
node.stdio.writeError("DEBUG: " + x.toString() + "\n");
};
exports.error = function (x) {
node.stdio.writeError(x.toString() + "\n");
};
/**
* Echos the value of a value. Trys to print the value out
* in the best way possible given the different types.
*
* @param {Object} value The object to print out
*/
exports.inspect = function (value) {
if (value === 0) return "0";
if (value === false) return "false";
if (value === "") return '""';
if (typeof(value) == "function") return "[Function]";
if (value === undefined) return;
try {
return JSON.stringify(value);
} catch (e) {
// TODO make this recusrive and do a partial JSON output of object.
if (e.message.search("circular")) {
return "[Circular Object]";
} else {
throw e;
}
}
};
exports.p = function (x) {
exports.error(exports.inspect(x));
};
exports.exec = function (command) {
var child = node.createChildProcess("/bin/sh", ["-c", command]);
var stdout = "";
var stderr = "";
var promise = new node.Promise();
child.addListener("output", function (chunk) {
if (chunk) stdout += chunk;
});
child.addListener("error", function (chunk) {
if (chunk) stderr += chunk;
});
child.addListener("exit", function (code) {
if (code == 0) {
promise.emitSuccess(stdout, stderr);
} else {
promise.emitError(code, stdout, stderr);
}
});
return promise;
};

69
lib/utils.js

@ -1,69 +0,0 @@
exports.print = function (x) {
node.stdio.write(x);
};
exports.puts = function (x) {
node.stdio.write(x.toString() + "\n");
};
exports.debug = function (x) {
node.stdio.writeError("DEBUG: " + x.toString() + "\n");
};
exports.error = function (x) {
node.stdio.writeError(x.toString() + "\n");
};
/**
* Echos the value of a value. Trys to print the value out
* in the best way possible given the different types.
*
* @param {Object} value The object to print out
*/
exports.inspect = function (value) {
if (value === 0) return "0";
if (value === false) return "false";
if (value === "") return '""';
if (typeof(value) == "function") return "[Function]";
if (value === undefined) return;
try {
return JSON.stringify(value);
} catch (e) {
// TODO make this recusrive and do a partial JSON output of object.
if (e.message.search("circular")) {
return "[Circular Object]";
} else {
throw e;
}
}
};
exports.p = function (x) {
exports.error(exports.inspect(x));
};
exports.exec = function (command) {
var child = node.createChildProcess("/bin/sh", ["-c", command]);
var stdout = "";
var stderr = "";
var promise = new node.Promise();
child.addListener("output", function (chunk) {
if (chunk) stdout += chunk;
});
child.addListener("error", function (chunk) {
if (chunk) stderr += chunk;
});
child.addListener("exit", function (code) {
if (code == 0) {
promise.emitSuccess(stdout, stderr);
} else {
promise.emitError(code, stdout, stderr);
}
});
return promise;
};

1
lib/utils.js

@ -0,0 +1 @@
sys.js

2
src/node.js

@ -24,7 +24,7 @@ node.createChildProcess = function (file, args, env) {
}; };
node.exec = function () { node.exec = function () {
throw new Error("node.exec() has moved. Use require('/utils.js') to bring it back."); throw new Error("node.exec() has moved. Use require('/sys.js') to bring it back.");
} }
node.http.createServer = function () { node.http.createServer = function () {

10
src/util.js

@ -70,21 +70,21 @@ node.path = new function () {
puts = function () { puts = function () {
throw new Error("puts() has moved. Use require('/utils.js') to bring it back."); throw new Error("puts() has moved. Use require('/sys.js') to bring it back.");
} }
print = function () { print = function () {
throw new Error("print() has moved. Use require('/utils.js') to bring it back."); throw new Error("print() has moved. Use require('/sys.js') to bring it back.");
} }
p = function () { p = function () {
throw new Error("p() has moved. Use require('/utils.js') to bring it back."); throw new Error("p() has moved. Use require('/sys.js') to bring it back.");
} }
node.debug = function () { node.debug = function () {
throw new Error("node.debug() has moved. Use require('/utils.js') to bring it back."); throw new Error("node.debug() has moved. Use require('/sys.js') to bring it back.");
} }
node.error = function () { node.error = function () {
throw new Error("node.error() has moved. Use require('/utils.js') to bring it back."); throw new Error("node.error() has moved. Use require('/sys.js') to bring it back.");
} }

Loading…
Cancel
Save