From 2b8ab7e24f2abc92474f44aad796b263582ab5d4 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 13 Oct 2009 13:26:00 +0200 Subject: [PATCH] utils.js links to sys.js instead of other way around --- lib/http.js | 16 ++++++------ lib/repl.js | 22 ++++++++--------- lib/sys.js | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++- lib/utils.js | 70 +--------------------------------------------------- src/node.js | 2 +- src/util.js | 10 ++++---- 6 files changed, 95 insertions(+), 95 deletions(-) mode change 120000 => 100644 lib/sys.js mode change 100644 => 120000 lib/utils.js diff --git a/lib/http.js b/lib/http.js index e6e416f363..6225aa7781 100644 --- a/lib/http.js +++ b/lib/http.js @@ -1,4 +1,4 @@ -var utils = require("/utils.js"); +var sys = require("/sys.js"); var CRLF = "\r\n"; var STATUS_CODES = { @@ -502,11 +502,11 @@ exports.createClient = function (port, host) { client._pushRequest = function (req) { req.addListener("flush", function () { 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 return; } - //utils.debug("client flush readyState = " + client.readyState); + //sys.debug("client flush readyState = " + client.readyState); if (req == requests[0]) flushMessageQueue(client, [req]); }); requests.push(req); @@ -517,7 +517,7 @@ exports.createClient = function (port, host) { }); client.addListener("eof", function () { - //utils.debug("client got eof closing. readyState = " + client.readyState); + //sys.debug("client got eof closing. readyState = " + client.readyState); client.close(); }); @@ -527,20 +527,20 @@ exports.createClient = function (port, host) { 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 (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 } }); createIncomingMessageStream(client, function (res) { - //utils.debug("incoming response!"); + //sys.debug("incoming response!"); res.addListener("complete", function ( ) { - //utils.debug("request complete disconnecting. readyState = " + client.readyState); + //sys.debug("request complete disconnecting. readyState = " + client.readyState); client.close(); }); diff --git a/lib/repl.js b/lib/repl.js index e163d944aa..bb76d8c04d 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -1,9 +1,9 @@ // A repl library that you can include in your own code to get a runtime // 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 = ''; @@ -49,7 +49,7 @@ function readline (cmd) { var ret = eval(buffered_cmd); if (ret !== undefined) { exports.scope['_'] = ret; - utils.p(ret); + sys.p(ret); } } @@ -60,9 +60,9 @@ function readline (cmd) { } catch (e) { // On error: Print the error and clear the buffer if (e.stack) { - utils.puts(e.stack); + sys.puts(e.stack); } else { - utils.puts(e.toString()); + sys.puts(e.toString()); } buffered_cmd = ''; } @@ -75,7 +75,7 @@ function readline (cmd) { * Used to display the prompt. */ function displayPrompt () { - utils.print(buffered_cmd.length ? '... ' : exports.prompt); + sys.print(buffered_cmd.length ? '... ' : exports.prompt); } /** @@ -91,7 +91,7 @@ function parseREPLKeyword (cmd) { displayPrompt(); return true; case ".clear": - utils.puts("Clearing Scope..."); + sys.puts("Clearing Scope..."); buffered_cmd = ''; exports.scope = {}; displayPrompt(); @@ -100,10 +100,10 @@ function parseREPLKeyword (cmd) { node.stdio.close(); return true; case ".help": - utils.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."); - utils.puts(".exit\tExit the prompt"); - utils.puts(".help\tShow repl options"); + sys.puts(".break\tSometimes you get stuck in a place you can't get out... This will get you out."); + sys.puts(".clear\tBreak, and also clear the local scope."); + sys.puts(".exit\tExit the prompt"); + sys.puts(".help\tShow repl options"); displayPrompt(); return true; } diff --git a/lib/sys.js b/lib/sys.js deleted file mode 120000 index f59ba89fef..0000000000 --- a/lib/sys.js +++ /dev/null @@ -1 +0,0 @@ -utils.js \ No newline at end of file diff --git a/lib/sys.js b/lib/sys.js new file mode 100644 index 0000000000..f85bb15fdb --- /dev/null +++ b/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; +}; diff --git a/lib/utils.js b/lib/utils.js deleted file mode 100644 index f85bb15fdb..0000000000 --- a/lib/utils.js +++ /dev/null @@ -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; -}; diff --git a/lib/utils.js b/lib/utils.js new file mode 120000 index 0000000000..67dae2eeff --- /dev/null +++ b/lib/utils.js @@ -0,0 +1 @@ +sys.js \ No newline at end of file diff --git a/src/node.js b/src/node.js index fbac941030..e5c8761d3a 100644 --- a/src/node.js +++ b/src/node.js @@ -24,7 +24,7 @@ node.createChildProcess = function (file, args, env) { }; 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 () { diff --git a/src/util.js b/src/util.js index 4c79f0a875..cac5d0ea00 100644 --- a/src/util.js +++ b/src/util.js @@ -70,21 +70,21 @@ node.path = new 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 () { - 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 () { - 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 () { - 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 () { - 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."); }