From e38eb0c5a4d4e8497f5815be81994ddb01fbceb7 Mon Sep 17 00:00:00 2001 From: Micheil Smith Date: Tue, 12 Oct 2010 08:04:09 +1100 Subject: [PATCH] Soft migration of sys -> util, Removal of deprecated utils module. --- benchmark/io.js | 4 +- benchmark/process_loop.js | 4 +- benchmark/run.js | 4 +- doc/api.markdown | 66 +-- lib/assert.js | 4 +- lib/child_process.js | 4 +- lib/crypto.js | 1 - lib/dgram.js | 4 +- lib/fs.js | 12 +- lib/http.js | 22 +- lib/net.js | 10 +- lib/readline.js | 4 +- lib/repl.js | 14 +- lib/stream.js | 4 +- lib/sys.js | 402 +----------------- lib/util.js | 390 +++++++++++++++++ lib/utils.js | 1 - src/node.cc | 2 +- src/node.js | 8 +- test/common.js | 4 +- test/disabled/test-dns.js | 3 +- test/disabled/test-fs-sendfile.js | 2 +- .../disabled/test-http-big-proxy-responses.js | 2 +- test/disabled/test-http-head-request.js | 2 +- test/disabled/test-remote-module-loading.js | 4 +- test/disabled/tls_client.js | 2 +- test/disabled/tls_server.js | 2 +- .../child_process_should_emit_error.js | 3 +- test/fixtures/print-10-lines.js | 1 - test/fixtures/recvfd.js | 1 - test/fixtures/stdio-filter.js | 2 +- test/message/2100bytes.js | 2 +- test/pummel/test-http-client-reconnect-bug.js | 2 +- test/simple/test-child-process-custom-fds.js | 1 - test/simple/test-child-process-exec-env.js | 3 +- test/simple/test-crypto.js | 1 - test/simple/test-dgram-multicast.js | 6 +- test/simple/test-http-expect-continue.js | 2 - test/simple/test-http-head-request.js | 2 +- .../test-http-keep-alive-close-on-header.js | 2 +- test/simple/test-http-keep-alive.js | 2 +- test/simple/test-http-tls.js | 1 - test/simple/test-http-upgrade-server.js | 4 +- test/simple/test-net-tls.js | 1 - test/simple/test-next-tick-ordering.js | 2 +- test/simple/test-pump-file2tcp-noexist.js | 8 +- test/simple/test-pump-file2tcp.js | 4 +- .../test-regression-object-prototype.js | 2 - test/simple/test-repl.js | 3 +- test/simple/test-sendfd.js | 1 - test/simple/test-signal-unregister.js | 2 +- test/simple/test-url.js | 2 +- tools/ronnjs/bin/ronn.js | 17 +- tools/ronnjs/lib/ext/opts.js | 18 +- tools/ronnjs/lib/ronn.js | 8 +- 55 files changed, 543 insertions(+), 541 deletions(-) create mode 100644 lib/util.js delete mode 120000 lib/utils.js diff --git a/benchmark/io.js b/benchmark/io.js index a91bdbbe67b..505d8d03aae 100644 --- a/benchmark/io.js +++ b/benchmark/io.js @@ -1,5 +1,5 @@ var fs = require('fs'); -var sys = require('sys'); +var util = require('util'); var Buffer = require('buffer').Buffer; var path = "/tmp/wt.dat"; @@ -43,7 +43,7 @@ function writetest(size, bsize) { s.on('drain', function () { dowrite(); - if (c++ % 2000 == 0) sys.print("."); + if (c++ % 2000 == 0) util.print("."); }); dowrite(); diff --git a/benchmark/process_loop.js b/benchmark/process_loop.js index 18cc1695640..eeba06ab972 100644 --- a/benchmark/process_loop.js +++ b/benchmark/process_loop.js @@ -1,4 +1,4 @@ -var sys = require("sys"), +var util = require("util"), childProcess = require("child_process"); function next (i) { @@ -7,7 +7,7 @@ function next (i) { var child = childProcess.spawn("echo", ["hello"]); child.stdout.addListener("data", function (chunk) { - sys.print(chunk); + util.print(chunk); }); child.addListener("exit", function (code) { diff --git a/benchmark/run.js b/benchmark/run.js index b1479b6006c..28916873760 100644 --- a/benchmark/run.js +++ b/benchmark/run.js @@ -1,5 +1,5 @@ var path = require("path"); -var sys = require("sys"); +var util = require("util"); var childProcess = require("child_process"); var benchmarks = [ "timers.js" , "process_loop.js" @@ -19,7 +19,7 @@ function exec (script, callback) { function runNext (i) { if (i >= benchmarks.length) return; - sys.print(benchmarks[i] + ": "); + util.print(benchmarks[i] + ": "); exec(benchmarks[i], function (elapsed, code) { if (code != 0) { console.log("ERROR "); diff --git a/doc/api.markdown b/doc/api.markdown index 7b95ab286ea..26842224e2e 100644 --- a/doc/api.markdown +++ b/doc/api.markdown @@ -34,7 +34,7 @@ variable with the same name as the module. Example: - var sys = require('sys'); + var util = require('util'); It is possible to extend node with other modules. See `'Modules'` @@ -271,7 +271,7 @@ manipulated, e.g. to remove listeners. server.on('stream', function (stream) { console.log('someone connected!'); }); - console.log(sys.inspect(server.listeners('stream')); + console.log(util.inspect(server.listeners('stream')); // [ [Function] ] @@ -766,9 +766,9 @@ What platform you're running on. `'linux2'`, `'darwin'`, etc. Returns an object describing the memory usage of the Node process. - var sys = require('sys'); + var util = require('util'); - console.log(sys.inspect(process.memoryUsage())); + console.log(util.inspect(process.memoryUsage())); This will generate: @@ -806,35 +806,35 @@ given, otherwise returns the current mask. -## sys +## util -These functions are in the module `'sys'`. Use `require('sys')` to access +These functions are in the module `'util'`. Use `require('util')` to access them. -### sys.print(string) +### util.print(string) Like `console.log()` but without the trailing newline. - require('sys').print('String with no newline'); + require('util').print('String with no newline'); -### sys.debug(string) +### util.debug(string) A synchronous output function. Will block the process and output `string` immediately to `stderr`. - require('sys').debug('message on stderr'); + require('util').debug('message on stderr'); -### sys.log(string) +### util.log(string) Output with timestamp on `stdout`. - require('sys').log('Timestmaped message.'); + require('util').log('Timestmaped message.'); -### sys.inspect(object, showHidden=false, depth=2) +### util.inspect(object, showHidden=false, depth=2) Return a string representation of `object`, which is useful for debugging. @@ -847,14 +847,14 @@ formatting the object. This is useful for inspecting large complicated objects. The default is to only recurse twice. To make it recurse indefinitely, pass in `null` for `depth`. -Example of inspecting all properties of the `sys` object: +Example of inspecting all properties of the `util` object: - var sys = require('sys'); + var util = require('util'); - console.log(sys.inspect(sys, true, null)); + console.log(util.inspect(util, true, null)); -### sys.pump(readableStream, writeableStream, [callback]) +### util.pump(readableStream, writeableStream, [callback]) Experimental @@ -962,16 +962,16 @@ existing streams; `-1` means that a new stream should be created. Example of running `ls -lh /usr`, capturing `stdout`, `stderr`, and the exit code: - var sys = require('sys'), + var util = require('util'), spawn = require('child_process').spawn, ls = spawn('ls', ['-lh', '/usr']); ls.stdout.on('data', function (data) { - sys.print('stdout: ' + data); + util.print('stdout: ' + data); }); ls.stderr.on('data', function (data) { - sys.print('stderr: ' + data); + util.print('stderr: ' + data); }); ls.on('exit', function (code) { @@ -981,7 +981,7 @@ Example of running `ls -lh /usr`, capturing `stdout`, `stderr`, and the exit cod Example: A very elaborate way to run 'ps ax | grep ssh' - var sys = require('sys'), + var util = require('util'), spawn = require('child_process').spawn, ps = spawn('ps', ['ax']), grep = spawn('grep', ['ssh']); @@ -991,7 +991,7 @@ Example: A very elaborate way to run 'ps ax | grep ssh' }); ps.stderr.on('data', function (data) { - sys.print('ps stderr: ' + data); + util.print('ps stderr: ' + data); }); ps.on('exit', function (code) { @@ -1002,11 +1002,11 @@ Example: A very elaborate way to run 'ps ax | grep ssh' }); grep.stdout.on('data', function (data) { - sys.print(data); + util.print(data); }); grep.stderr.on('data', function (data) { - sys.print('grep stderr: ' + data); + util.print('grep stderr: ' + data); }); grep.on('exit', function (code) { @@ -1035,14 +1035,14 @@ See also: `child_process.exec()` High-level way to execute a command as a child process, buffer the output, and return it all in a callback. - var sys = require('sys'), + var util = require('util'), exec = require('child_process').exec, child; child = exec('cat *.js bad_file | wc -l', function (error, stdout, stderr) { - sys.print('stdout: ' + stdout); - sys.print('stderr: ' + stderr); + util.print('stdout: ' + stdout); + util.print('stderr: ' + stderr); if (error !== null) { console.log('exec error: ' + error); } @@ -1140,7 +1140,7 @@ the object `sandbox` will be used as the global object for `code`. Example: compile and execute code that increments a global variable and sets a new one. These globals are contained in the sandbox. - var sys = require('sys'), + var util = require('util'), Script = process.binding('evals').Script, sandbox = { animal: 'cat', @@ -1149,7 +1149,7 @@ These globals are contained in the sandbox. Script.runInNewContext( 'count += 1; name = "kitty"', sandbox, 'myfile.js'); - console.log(sys.inspect(sandbox)); + console.log(util.inspect(sandbox)); // { animal: 'cat', count: 3, name: 'kitty' } @@ -1207,7 +1207,7 @@ Running code does not have access to local scope. `sandbox` is optional. Example: compile code that increments a global variable and sets one, then execute this code multiple times. These globals are contained in the sandbox. - var sys = require('sys'), + var util = require('util'), Script = process.binding('evals').Script, scriptObj, i, sandbox = { @@ -1222,7 +1222,7 @@ These globals are contained in the sandbox. scriptObj.runInNewContext(sandbox); } - console.log(sys.inspect(sandbox)); + console.log(util.inspect(sandbox)); // { animal: 'cat', count: 12, name: 'kitty' } @@ -2963,7 +2963,7 @@ the first character, then it returns an empty string. Examples: Test whether or not the given path exists. Then, call the `callback` argument with either true or false. Example: path.exists('/etc/passwd', function (exists) { - sys.debug(exists ? "it's there" : "no passwd!"); + util.debug(exists ? "it's there" : "no passwd!"); }); @@ -3214,7 +3214,7 @@ The module `circle.js` has exported the functions `area()` and `circumference()`. To export an object, add to the special `exports` object. (Alternatively, one can use `this` instead of `exports`.) Variables local to the module will be private. In this example the variable `PI` is -private to `circle.js`. The function `puts()` comes from the module `'sys'`, +private to `circle.js`. The function `puts()` comes from the module `'util'`, which is a built-in module. Modules which are not prefixed by `'./'` are built-in module--more about this later. diff --git a/lib/assert.js b/lib/assert.js index 6d1ffcd6700..4b89f29f84c 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -23,7 +23,7 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // UTILITY -var inherits = require('sys').inherits; +var util = require('util'); var pSlice = Array.prototype.slice; // 1. The assert module provides functions that throw @@ -47,7 +47,7 @@ assert.AssertionError = function AssertionError (options) { Error.captureStackTrace(this, stackStartFunction); } }; -inherits(assert.AssertionError, Error); +util.inherits(assert.AssertionError, Error); assert.AssertionError.prototype.toString = function() { if (this.message) { diff --git a/lib/child_process.js b/lib/child_process.js index 81cd1f67f10..a53aefd7cbe 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -1,4 +1,4 @@ -var inherits = require('sys').inherits; +var util = require('util'); var EventEmitter = require('events').EventEmitter; var Stream = require('net').Stream; var InternalChildProcess = process.binding('child_process').ChildProcess; @@ -155,7 +155,7 @@ function ChildProcess () { this.__defineGetter__('pid', function () { return internal.pid; }); } -inherits(ChildProcess, EventEmitter); +util.inherits(ChildProcess, EventEmitter); ChildProcess.prototype.kill = function (sig) { diff --git a/lib/crypto.js b/lib/crypto.js index 206a2014084..32d33c788b9 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -3582,7 +3582,6 @@ var RootCaCerts = [ +"-----END CERTIFICATE-----\n" ]; -var sys = require("sys"); try { var binding = process.binding('crypto'); var SecureContext = binding.SecureContext; diff --git a/lib/dgram.js b/lib/dgram.js index 5ec5e64b56b..493d58db9e7 100644 --- a/lib/dgram.js +++ b/lib/dgram.js @@ -1,4 +1,4 @@ -var sys = require("sys"); +var util = require("util"); var fs = require("fs"); var events = require("events"); var dns = require('dns'); @@ -72,7 +72,7 @@ function Socket (type, listener) { } } -sys.inherits(Socket, events.EventEmitter); +util.inherits(Socket, events.EventEmitter); exports.Socket = Socket; exports.createSocket = function (type, listener) { diff --git a/lib/fs.js b/lib/fs.js index c1d5891ee67..178197ce579 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -1,4 +1,4 @@ -var sys = require('sys'); +var util = require('util'); var events = require('events'); var binding = process.binding('fs'); @@ -666,7 +666,7 @@ var ReadStream = fs.ReadStream = function(path, options) { self._read(); }); }; -sys.inherits(ReadStream, events.EventEmitter); +util.inherits(ReadStream, events.EventEmitter); fs.FileReadStream = fs.ReadStream; // support the legacy name @@ -761,7 +761,7 @@ var readStreamForceCloseWarning; ReadStream.prototype.forceClose = function (cb) { if (!readStreamForceCloseWarning) { readStreamForceCloseWarning = "ReadStream.prototype.forceClose renamed to destroy()"; - sys.error(readStreamForceCloseWarning); + util.error(readStreamForceCloseWarning); } return this.destroy(cb); }; @@ -844,7 +844,7 @@ var WriteStream = fs.WriteStream = function(path, options) { this.flush(); } }; -sys.inherits(WriteStream, events.EventEmitter); +util.inherits(WriteStream, events.EventEmitter); fs.FileWriteStream = fs.WriteStream; // support the legacy name @@ -940,7 +940,7 @@ var writeStreamCloseWarning; WriteStream.prototype.close = function (cb) { if (!writeStreamCloseWarning) { writeStreamCloseWarning = "WriteStream.prototype.close renamed to end()"; - sys.error(writeStreamCloseWarning); + util.error(writeStreamCloseWarning); } return this.end(cb); }; @@ -958,7 +958,7 @@ var writeStreamForceCloseWarning; WriteStream.prototype.forceClose = function (cb) { if (!writeStreamForceCloseWarning) { writeStreamForceCloseWarning = "WriteStream.prototype.forceClose renamed to destroy()"; - sys.error(writeStreamForceCloseWarning); + util.error(writeStreamForceCloseWarning); } return this.destroy(cb); }; diff --git a/lib/http.js b/lib/http.js index ecf67749c31..5ab28cb177e 100755 --- a/lib/http.js +++ b/lib/http.js @@ -1,9 +1,9 @@ -var sys = require('sys'); +var util = require('util'); var debug; var debugLevel = parseInt(process.env.NODE_DEBUG, 16); if (debugLevel & 0x4) { - debug = function (x) { sys.error('HTTP: ' + x); }; + debug = function (x) { util.error('HTTP: ' + x); }; } else { debug = function () { }; } @@ -207,7 +207,7 @@ function IncomingMessage (socket) { this.statusCode = null; this.client = this.socket; } -sys.inherits(IncomingMessage, stream.Stream); +util.inherits(IncomingMessage, stream.Stream); exports.IncomingMessage = IncomingMessage; IncomingMessage.prototype._parseQueryString = function () { @@ -305,7 +305,7 @@ function OutgoingMessage (socket) { this.finished = false; } -sys.inherits(OutgoingMessage, stream.Stream); +util.inherits(OutgoingMessage, stream.Stream); exports.OutgoingMessage = OutgoingMessage; // This abstract either writing directly to the socket or buffering it. @@ -499,7 +499,7 @@ OutgoingMessage.prototype.write = function (chunk, encoding) { if (typeof(chunk) === 'string') { len = Buffer.byteLength(chunk, encoding); var chunk = len.toString(16) + CRLF + chunk + CRLF; - debug('string chunk = ' + sys.inspect(chunk)); + debug('string chunk = ' + util.inspect(chunk)); ret = this._send(chunk, encoding); } else { // buffer @@ -605,7 +605,7 @@ function ServerResponse (req) { this.shouldKeepAlive = false; } } -sys.inherits(ServerResponse, OutgoingMessage); +util.inherits(ServerResponse, OutgoingMessage); exports.ServerResponse = ServerResponse; ServerResponse.prototype.writeContinue = function () { @@ -678,7 +678,7 @@ function ClientRequest (socket, method, url, headers) { this._storeHeader(method + " " + url + " HTTP/1.1\r\n", headers); } -sys.inherits(ClientRequest, OutgoingMessage); +util.inherits(ClientRequest, OutgoingMessage); exports.ClientRequest = ClientRequest; ClientRequest.prototype.finish = function () { @@ -769,7 +769,7 @@ function Server (requestListener) { this.addListener("connection", connectionListener); } -sys.inherits(Server, net.Server); +util.inherits(Server, net.Server); Server.prototype.setSecure = function (credentials) { this.secure = true; @@ -934,14 +934,14 @@ function Client ( ) { this.setSecure(this.credentials); } else { self._initParser(); - debug('requests: ' + sys.inspect(self._outgoing)); + debug('requests: ' + util.inspect(self._outgoing)); outgoingFlush(self); } }); self.addListener("secure", function () { self._initParser(); - debug('requests: ' + sys.inspect(self._outgoing)); + debug('requests: ' + util.inspect(self._outgoing)); outgoingFlush(self); }); @@ -968,7 +968,7 @@ function Client ( ) { } }); }; -sys.inherits(Client, net.Stream); +util.inherits(Client, net.Stream); exports.Client = Client; diff --git a/lib/net.js b/lib/net.js index 5813ca96deb..0b9426cd56a 100644 --- a/lib/net.js +++ b/lib/net.js @@ -1,4 +1,4 @@ -var sys = require("sys"); +var util = require("util"); var fs = require("fs"); var events = require("events"); var stream = require("stream"); @@ -9,7 +9,7 @@ var kPoolSize = 40*1024; var debugLevel = parseInt(process.env.NODE_DEBUG, 16); function debug () { - if (debugLevel & 0x2) sys.error.apply(this, arguments); + if (debugLevel & 0x2) util.error.apply(this, arguments); } var binding = process.binding('net'); @@ -532,7 +532,7 @@ function Stream (fd, type) { setImplmentationMethods(this); } }; -sys.inherits(Stream, stream.Stream); +util.inherits(Stream, stream.Stream); exports.Stream = Stream; @@ -783,7 +783,7 @@ Stream.prototype._writeOut = function (data, encoding, fd) { var leftOver = buffer.slice(off + bytesWritten, off + len); leftOver.used = leftOver.length; // used the whole thing... - // sys.error('data.used = ' + data.used); + // util.error('data.used = ' + data.used); //if (!this._writeQueue) initWriteStream(this); // data should be the next thing to write. @@ -1093,7 +1093,7 @@ function Server (listener) { } }; } -sys.inherits(Server, events.EventEmitter); +util.inherits(Server, events.EventEmitter); exports.Server = Server; diff --git a/lib/readline.js b/lib/readline.js index d3b63e7d7c9..a031c1cea26 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -7,8 +7,8 @@ var kHistorySize = 30; var kBufSize = 10*1024; -var sys = require('sys'); -var inherits = require('sys').inherits; +var util = require('util'); +var inherits = require('util').inherits; var EventEmitter = require('events').EventEmitter; var stdio = process.binding('stdio'); diff --git a/lib/repl.js b/lib/repl.js index ce231ef82fa..78171dab635 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -12,7 +12,7 @@ // repl.start("node > ").context.foo = "stdin is fun"; // expose foo to repl context -var sys = require('sys'); +var util = require('util'); var Script = process.binding('evals').Script; var evalcx = Script.runInContext; var path = require("path"); @@ -41,7 +41,7 @@ function resetContext() { // Can overridden with custom print functions, such as `probe` or `eyes.js` -exports.writer = sys.inspect; +exports.writer = util.inspect; function REPLServer(prompt, stream) { var self = this; @@ -59,7 +59,7 @@ function REPLServer(prompt, stream) { if (rli.enabled && !disableColors) { // Turn on ANSI coloring. exports.writer = function(obj, showHidden, depth) { - return sys.inspect(obj, showHidden, depth, true); + return util.inspect(obj, showHidden, depth, true); }; } @@ -167,9 +167,9 @@ REPLServer.prototype.readline = function (cmd) { * (2) the leading text completed. * * Example: - * complete('var foo = sys.') - * -> [['sys.print', 'sys.debug', 'sys.log', 'sys.inspect', 'sys.pump'], - * 'sys.' ] + * complete('var foo = util.') + * -> [['util.print', 'util.debug', 'util.log', 'util.inspect', 'util.pump'], + * 'util.' ] * * Warning: This eval's code like "foo.bar.baz", so it will run property * getter code. @@ -253,7 +253,7 @@ REPLServer.prototype.complete = function (line) { // Intentionally excluding moved modules: posix, utils. var builtinLibs = ['assert', 'buffer', 'child_process', 'crypto', 'dgram', 'dns', 'events', 'file', 'freelist', 'fs', 'http', 'net', 'path', - 'querystring', 'readline', 'repl', 'string_decoder', 'sys', 'tcp', 'url']; + 'querystring', 'readline', 'repl', 'string_decoder', 'util', 'tcp', 'url']; completionGroups.push(builtinLibs); } } diff --git a/lib/stream.js b/lib/stream.js index 189708a93fa..97f4fa60222 100644 --- a/lib/stream.js +++ b/lib/stream.js @@ -1,10 +1,10 @@ var events = require('events'); -var inherits = require('sys').inherits; +var util = require('util'); function Stream () { events.EventEmitter.call(this); } -inherits(Stream, events.EventEmitter); +util.inherits(Stream, events.EventEmitter); exports.Stream = Stream; Stream.prototype.pipe = function (dest, options) { diff --git a/lib/sys.js b/lib/sys.js index 4ffa1ea73ff..304207ced1d 100644 --- a/lib/sys.js +++ b/lib/sys.js @@ -1,390 +1,18 @@ -var events = require('events'); +var util = require("util"); - -exports.print = function () { - for (var i = 0, len = arguments.length; i < len; ++i) { - process.stdout.write(String(arguments[i])); - } -}; - - -exports.puts = function () { - for (var i = 0, len = arguments.length; i < len; ++i) { - process.stdout.write(arguments[i] + '\n'); - } -}; - - -exports.debug = function (x) { - process.binding('stdio').writeError("DEBUG: " + x + "\n"); -}; - - -var error = exports.error = function (x) { - for (var i = 0, len = arguments.length; i < len; ++i) { - process.binding('stdio').writeError(arguments[i] + '\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 - * @param {Boolean} showHidden Flag that shows hidden (not enumerable) - * properties of objects. - * @param {Number} depth Depth in which to descend in object. Default is 2. - * @param {Boolean} colors Flag to turn on ANSI escape codes to color the - * output. Default is false (no coloring). - */ -exports.inspect = function (obj, showHidden, depth, colors) { - var seen = []; - - var stylize = function (str, styleType) { - // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics - var styles = { 'bold' : [1, 22] - , 'italic' : [3, 23] - , 'underline' : [4, 24] - , 'inverse' : [7, 27] - , 'white' : [37, 39] - , 'grey' : [90, 39] - , 'black' : [30, 39] - , 'blue' : [34, 39] - , 'cyan' : [36, 39] - , 'green' : [32, 39] - , 'magenta' : [35, 39] - , 'red' : [31, 39] - , 'yellow' : [33, 39] - }; - var style = { "special": "grey" - , "number": "blue" - , "boolean": "blue" - , "undefined": "red" - , "null": "red" - , "string": "green" - , "date": "magenta" - //, "name": intentionally not styling - , "regexp": "cyan" - }[styleType]; - if (style) { - return '\033[' + styles[style][0] + 'm' + str + - '\033[' + styles[style][1] + 'm'; - } else { - return str; - } - }; - if (! colors) { - stylize = function(str, styleType) { return str; }; - } - - function format(value, recurseTimes) { - // Provide a hook for user-specified inspect functions. - // Check that value is an object with an inspect function on it - if (value && typeof value.inspect === 'function' && - // Filter out the sys module, it's inspect function is special - value !== exports && - // Also filter out any prototype objects using the circular check. - !(value.constructor && value.constructor.prototype === value)) { - return value.inspect(recurseTimes); - } - - // Primitive types cannot have properties - switch (typeof value) { - case 'undefined': return stylize('undefined', 'undefined'); - case 'string': return stylize( - JSON.stringify(value).replace(/'/g, "\\'") - .replace(/\\"/g, '"') - .replace(/(^"|"$)/g, "'"), - 'string'); - case 'number': return stylize('' + value, 'number'); - case 'boolean': return stylize('' + value, 'boolean'); - } - // For some reason typeof null is "object", so special case here. - if (value === null) { - return stylize('null', 'null'); - } - - // Look up the keys of the object. - var visible_keys = Object.keys(value); - var keys = showHidden ? Object.getOwnPropertyNames(value) : visible_keys; - - // Functions without properties can be shortcutted. - if (typeof value === 'function' && keys.length === 0) { - if (isRegExp(value)) { - return stylize('' + value, 'regexp'); - } else { - return stylize('[Function'+ (value.name ? ': '+ value.name : '')+ ']', 'special'); - } - } - - // Dates without properties can be shortcutted - if (isDate(value) && keys.length === 0) { - return stylize(value.toUTCString(), 'date'); - } - - var base, type, braces; - // Determine the object type - if (isArray(value)) { - type = 'Array'; - braces = ["[", "]"]; - } else { - type = 'Object'; - braces = ["{", "}"]; - } - - // Make functions say that they are functions - if (typeof value === 'function') { - base = (isRegExp(value)) ? ' ' + value : ' [Function'+ (value.name ? ': '+ value.name : '')+ ']'; - } else { - base = ""; - } - - // Make dates with properties first say the date - if (isDate(value)) { - base = ' ' + value.toUTCString(); - } - - seen.push(value); - - if (keys.length === 0) { - return braces[0] + base + braces[1]; - } - - if (recurseTimes < 0) { - if (isRegExp(value)) { - return stylize('' + value, "regexp"); - } else { - return stylize("[Object]", "special"); - } - } - - var output = keys.map(function (key) { - var name, str; - if (value.__lookupGetter__) { - if (value.__lookupGetter__(key)) { - if (value.__lookupSetter__(key)) { - str = stylize("[Getter/Setter]", "special"); - } else { - str = stylize("[Getter]", "special"); - } - } else { - if (value.__lookupSetter__(key)) { - str = stylize("[Setter]", "special"); - } - } - } - if (visible_keys.indexOf(key) < 0) { - name = "[" + key + "]"; - } - if (!str) { - if (seen.indexOf(value[key]) < 0) { - if ( recurseTimes === null) { - str = format(value[key]); - } else { - str = format(value[key], recurseTimes - 1); - } - if (str.indexOf('\n') > -1) { - if (isArray(value)) { - str = str.split('\n').map(function(line) { - return ' ' + line; - }).join('\n').substr(2); - } else { - str = '\n' + str.split('\n').map(function(line) { - return ' ' + line; - }).join('\n'); - } - } - } else { - str = stylize('[Circular]', 'special'); - } - } - if (typeof name === 'undefined') { - if (type === 'Array' && key.match(/^\d+$/)) { - return str; - } - name = JSON.stringify('' + key); - if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { - name = name.substr(1, name.length-2); - name = stylize(name, "name"); - } else { - name = name.replace(/'/g, "\\'") - .replace(/\\"/g, '"') - .replace(/(^"|"$)/g, "'"); - name = stylize(name, "string"); - } - } - - return name + ": " + str; - }); - - var numLinesEst = 0; - var length = output.reduce(function(prev, cur) { - numLinesEst++; - if( cur.indexOf('\n') >= 0 ) { - numLinesEst++; - } - return prev + cur.length + 1; - },0); - - if (length > (require('readline').columns || 50)) { - output = braces[0] - + (base === '' ? '' : base + '\n ') - + ' ' - + output.join(',\n ') - + ' ' - + braces[1] - ; - } else { - output = braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; - } - - return output; - } - return format(obj, (typeof depth === 'undefined' ? 2 : depth)); -}; - - -function isArray (ar) { - return ar instanceof Array - || Array.isArray(ar) - || (ar && ar !== Object.prototype && isArray(ar.__proto__)); +var sysWarning; +if (!sysWarning) { + sysWarning = "The 'sys' module is now called 'util'. It should have a similar interface."; + util.error(sysWarning); } - -function isRegExp (re) { - var s = ""+re; - return re instanceof RegExp // easy case - || typeof(re) === "function" // duck-type for context-switching evalcx case - && re.constructor.name === "RegExp" - && re.compile - && re.test - && re.exec - && s.match(/^\/.*\/[gim]{0,3}$/); -} - - -function isDate (d) { - if (d instanceof Date) return true; - if (typeof d !== "object") return false; - var properties = Date.prototype && Object.getOwnPropertyNames(Date.prototype); - var proto = d.__proto__ && Object.getOwnPropertyNames(d.__proto__); - return JSON.stringify(proto) === JSON.stringify(properties); -} - - -var pWarning; - -exports.p = function () { - if (!pWarning) { - pWarning = "sys.p will be removed in future versions of Node. Use sys.puts(sys.inspect()) instead.\n"; - exports.error(pWarning); - } - for (var i = 0, len = arguments.length; i < len; ++i) { - error(exports.inspect(arguments[i])); - } -}; - - -function pad (n) { - return n < 10 ? '0' + n.toString(10) : n.toString(10); -} - - -var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; - -// 26 Feb 16:19:34 -function timestamp () { - var d = new Date(); - return [ d.getDate() - , months[d.getMonth()] - , [pad(d.getHours()), pad(d.getMinutes()), pad(d.getSeconds())].join(':') - ].join(' '); -} - - -exports.log = function (msg) { - exports.puts(timestamp() + ' - ' + msg.toString()); -}; - - -var execWarning; -exports.exec = function () { - if (!execWarning) { - execWarning = 'sys.exec has moved to the "child_process" module. Please update your source code.'; - error(execWarning); - } - return require('child_process').exec.apply(this, arguments); -}; - - -exports.pump = function (readStream, writeStream, callback) { - var callbackCalled = false; - - function call (a, b, c) { - if (callback && !callbackCalled) { - callback(a, b, c); - callbackCalled = true; - } - } - - if (!readStream.pause) readStream.pause = function () {readStream.emit("pause");}; - if (!readStream.resume) readStream.resume = function () {readStream.emit("resume");}; - - readStream.addListener("data", function (chunk) { - if (writeStream.write(chunk) === false) readStream.pause(); - }); - - writeStream.addListener("pause", function () { - readStream.pause(); - }); - - writeStream.addListener("drain", function () { - readStream.resume(); - }); - - writeStream.addListener("resume", function () { - readStream.resume(); - }); - - readStream.addListener("end", function () { - writeStream.end(); - }); - - readStream.addListener("close", function () { - call(); - }); - - readStream.addListener("error", function (err) { - writeStream.end(); - call(err); - }); - - writeStream.addListener("error", function (err) { - readStream.destroy(); - call(err); - }); -}; - -/** - * Inherit the prototype methods from one constructor into another. - * - * The Function.prototype.inherits from lang.js rewritten as a standalone - * function (not on Function.prototype). NOTE: If this file is to be loaded - * during bootstrapping this function needs to be revritten using some native - * functions as prototype setup using normal JavaScript does not work as - * expected during bootstrapping (see mirror.js in r114903). - * - * @param {function} ctor Constructor function which needs to inherit the - * prototype - * @param {function} superCtor Constructor function to inherit prototype from - */ -exports.inherits = function (ctor, superCtor) { - ctor.super_ = superCtor; - ctor.prototype = Object.create(superCtor.prototype, { - constructor: { - value: ctor, - enumerable: false - } - }); -}; +exports.print = util.print; +exports.puts = util.puts; +exports.debug = util.debug; +exports.error = util.error; +exports.inspect = util.inspect; +exports.p = util.p; +exports.log = util.log; +exports.exec = util.exec; +exports.pump = util.pump; +exports.inherits = util.inherits; \ No newline at end of file diff --git a/lib/util.js b/lib/util.js new file mode 100644 index 00000000000..ac051c34d95 --- /dev/null +++ b/lib/util.js @@ -0,0 +1,390 @@ +var events = require('events'); + + +exports.print = function () { + for (var i = 0, len = arguments.length; i < len; ++i) { + process.stdout.write(String(arguments[i])); + } +}; + + +exports.puts = function () { + for (var i = 0, len = arguments.length; i < len; ++i) { + process.stdout.write(arguments[i] + '\n'); + } +}; + + +exports.debug = function (x) { + process.binding('stdio').writeError("DEBUG: " + x + "\n"); +}; + + +var error = exports.error = function (x) { + for (var i = 0, len = arguments.length; i < len; ++i) { + process.binding('stdio').writeError(arguments[i] + '\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 + * @param {Boolean} showHidden Flag that shows hidden (not enumerable) + * properties of objects. + * @param {Number} depth Depth in which to descend in object. Default is 2. + * @param {Boolean} colors Flag to turn on ANSI escape codes to color the + * output. Default is false (no coloring). + */ +exports.inspect = function (obj, showHidden, depth, colors) { + var seen = []; + + var stylize = function (str, styleType) { + // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics + var styles = { 'bold' : [1, 22] + , 'italic' : [3, 23] + , 'underline' : [4, 24] + , 'inverse' : [7, 27] + , 'white' : [37, 39] + , 'grey' : [90, 39] + , 'black' : [30, 39] + , 'blue' : [34, 39] + , 'cyan' : [36, 39] + , 'green' : [32, 39] + , 'magenta' : [35, 39] + , 'red' : [31, 39] + , 'yellow' : [33, 39] + }; + var style = { "special": "grey" + , "number": "blue" + , "boolean": "blue" + , "undefined": "red" + , "null": "red" + , "string": "green" + , "date": "magenta" + //, "name": intentionally not styling + , "regexp": "cyan" + }[styleType]; + if (style) { + return '\033[' + styles[style][0] + 'm' + str + + '\033[' + styles[style][1] + 'm'; + } else { + return str; + } + }; + if (! colors) { + stylize = function(str, styleType) { return str; }; + } + + function format(value, recurseTimes) { + // Provide a hook for user-specified inspect functions. + // Check that value is an object with an inspect function on it + if (value && typeof value.inspect === 'function' && + // Filter out the util module, it's inspect function is special + value !== exports && + // Also filter out any prototype objects using the circular check. + !(value.constructor && value.constructor.prototype === value)) { + return value.inspect(recurseTimes); + } + + // Primitive types cannot have properties + switch (typeof value) { + case 'undefined': return stylize('undefined', 'undefined'); + case 'string': return stylize( + JSON.stringify(value).replace(/'/g, "\\'") + .replace(/\\"/g, '"') + .replace(/(^"|"$)/g, "'"), + 'string'); + case 'number': return stylize('' + value, 'number'); + case 'boolean': return stylize('' + value, 'boolean'); + } + // For some reason typeof null is "object", so special case here. + if (value === null) { + return stylize('null', 'null'); + } + + // Look up the keys of the object. + var visible_keys = Object.keys(value); + var keys = showHidden ? Object.getOwnPropertyNames(value) : visible_keys; + + // Functions without properties can be shortcutted. + if (typeof value === 'function' && keys.length === 0) { + if (isRegExp(value)) { + return stylize('' + value, 'regexp'); + } else { + return stylize('[Function'+ (value.name ? ': '+ value.name : '')+ ']', 'special'); + } + } + + // Dates without properties can be shortcutted + if (isDate(value) && keys.length === 0) { + return stylize(value.toUTCString(), 'date'); + } + + var base, type, braces; + // Determine the object type + if (isArray(value)) { + type = 'Array'; + braces = ["[", "]"]; + } else { + type = 'Object'; + braces = ["{", "}"]; + } + + // Make functions say that they are functions + if (typeof value === 'function') { + base = (isRegExp(value)) ? ' ' + value : ' [Function'+ (value.name ? ': '+ value.name : '')+ ']'; + } else { + base = ""; + } + + // Make dates with properties first say the date + if (isDate(value)) { + base = ' ' + value.toUTCString(); + } + + seen.push(value); + + if (keys.length === 0) { + return braces[0] + base + braces[1]; + } + + if (recurseTimes < 0) { + if (isRegExp(value)) { + return stylize('' + value, "regexp"); + } else { + return stylize("[Object]", "special"); + } + } + + var output = keys.map(function (key) { + var name, str; + if (value.__lookupGetter__) { + if (value.__lookupGetter__(key)) { + if (value.__lookupSetter__(key)) { + str = stylize("[Getter/Setter]", "special"); + } else { + str = stylize("[Getter]", "special"); + } + } else { + if (value.__lookupSetter__(key)) { + str = stylize("[Setter]", "special"); + } + } + } + if (visible_keys.indexOf(key) < 0) { + name = "[" + key + "]"; + } + if (!str) { + if (seen.indexOf(value[key]) < 0) { + if ( recurseTimes === null) { + str = format(value[key]); + } else { + str = format(value[key], recurseTimes - 1); + } + if (str.indexOf('\n') > -1) { + if (isArray(value)) { + str = str.split('\n').map(function(line) { + return ' ' + line; + }).join('\n').substr(2); + } else { + str = '\n' + str.split('\n').map(function(line) { + return ' ' + line; + }).join('\n'); + } + } + } else { + str = stylize('[Circular]', 'special'); + } + } + if (typeof name === 'undefined') { + if (type === 'Array' && key.match(/^\d+$/)) { + return str; + } + name = JSON.stringify('' + key); + if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { + name = name.substr(1, name.length-2); + name = stylize(name, "name"); + } else { + name = name.replace(/'/g, "\\'") + .replace(/\\"/g, '"') + .replace(/(^"|"$)/g, "'"); + name = stylize(name, "string"); + } + } + + return name + ": " + str; + }); + + var numLinesEst = 0; + var length = output.reduce(function(prev, cur) { + numLinesEst++; + if( cur.indexOf('\n') >= 0 ) { + numLinesEst++; + } + return prev + cur.length + 1; + },0); + + if (length > (require('readline').columns || 50)) { + output = braces[0] + + (base === '' ? '' : base + '\n ') + + ' ' + + output.join(',\n ') + + ' ' + + braces[1] + ; + } else { + output = braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; + } + + return output; + } + return format(obj, (typeof depth === 'undefined' ? 2 : depth)); +}; + + +function isArray (ar) { + return ar instanceof Array + || Array.isArray(ar) + || (ar && ar !== Object.prototype && isArray(ar.__proto__)); +} + + +function isRegExp (re) { + var s = ""+re; + return re instanceof RegExp // easy case + || typeof(re) === "function" // duck-type for context-switching evalcx case + && re.constructor.name === "RegExp" + && re.compile + && re.test + && re.exec + && s.match(/^\/.*\/[gim]{0,3}$/); +} + + +function isDate (d) { + if (d instanceof Date) return true; + if (typeof d !== "object") return false; + var properties = Date.prototype && Object.getOwnPropertyNames(Date.prototype); + var proto = d.__proto__ && Object.getOwnPropertyNames(d.__proto__); + return JSON.stringify(proto) === JSON.stringify(properties); +} + + +var pWarning; + +exports.p = function () { + if (!pWarning) { + pWarning = "util.p will be removed in future versions of Node. Use util.puts(util.inspect()) instead.\n"; + exports.error(pWarning); + } + for (var i = 0, len = arguments.length; i < len; ++i) { + error(exports.inspect(arguments[i])); + } +}; + + +function pad (n) { + return n < 10 ? '0' + n.toString(10) : n.toString(10); +} + + +var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; + +// 26 Feb 16:19:34 +function timestamp () { + var d = new Date(); + return [ d.getDate() + , months[d.getMonth()] + , [pad(d.getHours()), pad(d.getMinutes()), pad(d.getSeconds())].join(':') + ].join(' '); +} + + +exports.log = function (msg) { + exports.puts(timestamp() + ' - ' + msg.toString()); +}; + + +var execWarning; +exports.exec = function () { + if (!execWarning) { + execWarning = 'util.exec has moved to the "child_process" module. Please update your source code.'; + error(execWarning); + } + return require('child_process').exec.apply(this, arguments); +}; + + +exports.pump = function (readStream, writeStream, callback) { + var callbackCalled = false; + + function call (a, b, c) { + if (callback && !callbackCalled) { + callback(a, b, c); + callbackCalled = true; + } + } + + if (!readStream.pause) readStream.pause = function () {readStream.emit("pause");}; + if (!readStream.resume) readStream.resume = function () {readStream.emit("resume");}; + + readStream.addListener("data", function (chunk) { + if (writeStream.write(chunk) === false) readStream.pause(); + }); + + writeStream.addListener("pause", function () { + readStream.pause(); + }); + + writeStream.addListener("drain", function () { + readStream.resume(); + }); + + writeStream.addListener("resume", function () { + readStream.resume(); + }); + + readStream.addListener("end", function () { + writeStream.end(); + }); + + readStream.addListener("close", function () { + call(); + }); + + readStream.addListener("error", function (err) { + writeStream.end(); + call(err); + }); + + writeStream.addListener("error", function (err) { + readStream.destroy(); + call(err); + }); +}; + +/** + * Inherit the prototype methods from one constructor into another. + * + * The Function.prototype.inherits from lang.js rewritten as a standalone + * function (not on Function.prototype). NOTE: If this file is to be loaded + * during bootstrapping this function needs to be revritten using some native + * functions as prototype setup using normal JavaScript does not work as + * expected during bootstrapping (see mirror.js in r114903). + * + * @param {function} ctor Constructor function which needs to inherit the + * prototype + * @param {function} superCtor Constructor function to inherit prototype from + */ +exports.inherits = function (ctor, superCtor) { + ctor.super_ = superCtor; + ctor.prototype = Object.create(superCtor.prototype, { + constructor: { + value: ctor, + enumerable: false + } + }); +}; diff --git a/lib/utils.js b/lib/utils.js deleted file mode 120000 index 67dae2eeff3..00000000000 --- a/lib/utils.js +++ /dev/null @@ -1 +0,0 @@ -sys.js \ No newline at end of file diff --git a/src/node.cc b/src/node.cc index 9c6b4babb58..91fff804932 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1520,7 +1520,7 @@ static Handle Binding(const Arguments& args) { exports->Set(String::New("readline"), String::New(native_readline)); exports->Set(String::New("sys"), String::New(native_sys)); exports->Set(String::New("url"), String::New(native_url)); - exports->Set(String::New("utils"), String::New(native_utils)); + exports->Set(String::New("util"), String::New(native_util)); exports->Set(String::New("path"), String::New(native_path)); exports->Set(String::New("string_decoder"), String::New(native_string_decoder)); exports->Set(String::New("stream"), String::New(native_stream)); diff --git a/src/node.js b/src/node.js index 187351839a4..647bb30cd8c 100644 --- a/src/node.js +++ b/src/node.js @@ -483,9 +483,9 @@ process.openStdin = function () { var formatRegExp = /%[sdj]/g; function format (f) { if (typeof f !== 'string') { - var objects = [], sys = module.requireNative('sys'); + var objects = [], util = module.requireNative('util'); for (var i = 0; i < arguments.length; i++) { - objects.push(sys.inspect(arguments[i])); + objects.push(util.inspect(arguments[i])); } return objects.join(' '); } @@ -523,8 +523,8 @@ global.console.warn = function () { global.console.error = global.console.warn; global.console.dir = function(object){ - var sys = module.requireNative('sys'); - process.stdout.write(sys.inspect(object) + '\n'); + var util = module.requireNative('util'); + process.stdout.write(util.inspect(object) + '\n'); }; var times = {}; diff --git a/test/common.js b/test/common.js index cd688b7ba0a..c510eb338cb 100644 --- a/test/common.js +++ b/test/common.js @@ -8,8 +8,8 @@ exports.PORT = 12346; exports.assert = require('assert'); -var sys = require("sys"); -for (var i in sys) exports[i] = sys[i]; +var util = require("util"); +for (var i in util) exports[i] = util[i]; //for (var i in exports) global[i] = exports[i]; function protoCtrChain (o) { diff --git a/test/disabled/test-dns.js b/test/disabled/test-dns.js index e9cd0e6ee85..c5c2795781e 100644 --- a/test/disabled/test-dns.js +++ b/test/disabled/test-dns.js @@ -2,8 +2,7 @@ common = require("../common"); assert = common.assert; var dns = require("dns"), - child_process = require("child_process"), - sys = require("sys"); + child_process = require("child_process"); // Try resolution without callback diff --git a/test/disabled/test-fs-sendfile.js b/test/disabled/test-fs-sendfile.js index b442841fde1..3aa218ca714 100644 --- a/test/disabled/test-fs-sendfile.js +++ b/test/disabled/test-fs-sendfile.js @@ -2,7 +2,7 @@ common = require("../common"); assert = common.assert; tcp = require("tcp"); -sys = require("sys"); +util = require("util"); var x = path.join(common.fixturesDir, "x.txt"); var expected = "xyz"; diff --git a/test/disabled/test-http-big-proxy-responses.js b/test/disabled/test-http-big-proxy-responses.js index b1ccc7e79c3..47840eba053 100644 --- a/test/disabled/test-http-big-proxy-responses.js +++ b/test/disabled/test-http-big-proxy-responses.js @@ -1,6 +1,6 @@ common = require("../common"); assert = common.assert; -var sys = require("sys"), +var util = require("util"), fs = require("fs"), http = require("http"), url = require("url"); diff --git a/test/disabled/test-http-head-request.js b/test/disabled/test-http-head-request.js index da288be16cb..49276475611 100644 --- a/test/disabled/test-http-head-request.js +++ b/test/disabled/test-http-head-request.js @@ -3,7 +3,7 @@ assert = common.assert; var assert = require("assert"); var http = require("http"); -var sys = require("sys"); +var util = require("util"); var body = "hello world"; diff --git a/test/disabled/test-remote-module-loading.js b/test/disabled/test-remote-module-loading.js index c0842dccbfd..e207f4e5bd1 100644 --- a/test/disabled/test-remote-module-loading.js +++ b/test/disabled/test-remote-module-loading.js @@ -2,7 +2,7 @@ common = require("../common"); assert = common.assert; var http = require('http'); -var sys = require('sys'); +var util = require('util'); var url = require("url"); var modulesLoaded = 0; @@ -26,7 +26,7 @@ assert.throws(function () { var nodeBinary = process.ARGV[0]; var cmd = 'NODE_PATH='+libDir+' '+nodeBinary+' http://localhost:'+common.PORT+'/moduleB.js'; -sys.exec(cmd, function (err, stdout, stderr) { +util.exec(cmd, function (err, stdout, stderr) { if (err) throw err; console.log('success!'); modulesLoaded++; diff --git a/test/disabled/tls_client.js b/test/disabled/tls_client.js index 17e77696bd3..e2a36aea143 100644 --- a/test/disabled/tls_client.js +++ b/test/disabled/tls_client.js @@ -1,6 +1,6 @@ common = require("../common"); assert = common.assert; -var sys=require('sys'); +var util=require('util'); var net=require('net'); var fs=require('fs'); var crypto=require('crypto'); diff --git a/test/disabled/tls_server.js b/test/disabled/tls_server.js index 892be69b530..37f06561d72 100644 --- a/test/disabled/tls_server.js +++ b/test/disabled/tls_server.js @@ -1,7 +1,7 @@ common = require("../common"); assert = common.assert; -var sys=require('sys'); +var util=require('util'); var net=require('net'); var fs=require('fs'); var crypto=require('crypto'); diff --git a/test/fixtures/child_process_should_emit_error.js b/test/fixtures/child_process_should_emit_error.js index 8f795839071..3bfdc69a2a5 100644 --- a/test/fixtures/child_process_should_emit_error.js +++ b/test/fixtures/child_process_should_emit_error.js @@ -1,5 +1,4 @@ -var exec = require('child_process').exec, - puts = require('sys').puts; +var exec = require('child_process').exec; [0, 1].forEach(function(i) { exec('ls', function(err, stdout, stderr) { diff --git a/test/fixtures/print-10-lines.js b/test/fixtures/print-10-lines.js index c8e16d0acbc..0aaf3ef2930 100644 --- a/test/fixtures/print-10-lines.js +++ b/test/fixtures/print-10-lines.js @@ -1,4 +1,3 @@ -puts = require('sys').puts; for (var i = 0; i < 10; i++) { console.log('count ' + i); } diff --git a/test/fixtures/recvfd.js b/test/fixtures/recvfd.js index 27e8fc644a3..09b2864b7ed 100644 --- a/test/fixtures/recvfd.js +++ b/test/fixtures/recvfd.js @@ -2,7 +2,6 @@ // script is doing and how it fits into the test as a whole. var net = require('net'); -var sys = require('sys'); var receivedData = []; var receivedFDs = []; diff --git a/test/fixtures/stdio-filter.js b/test/fixtures/stdio-filter.js index ed5dfbfe42f..b3e481330e1 100644 --- a/test/fixtures/stdio-filter.js +++ b/test/fixtures/stdio-filter.js @@ -1,4 +1,4 @@ -sys = require('sys'); +var util = require('util'); var regexIn = process.argv[2]; var replacement = process.argv[3]; diff --git a/test/message/2100bytes.js b/test/message/2100bytes.js index 13778b055ad..cc371f0db02 100644 --- a/test/message/2100bytes.js +++ b/test/message/2100bytes.js @@ -1,7 +1,7 @@ common = require("../common"); assert = common.assert -sys = require('sys'); +util = require('util'); console.log([ '_______________________________________________50', '______________________________________________100', diff --git a/test/pummel/test-http-client-reconnect-bug.js b/test/pummel/test-http-client-reconnect-bug.js index e4a1606381f..bf26a7b018b 100644 --- a/test/pummel/test-http-client-reconnect-bug.js +++ b/test/pummel/test-http-client-reconnect-bug.js @@ -2,7 +2,7 @@ common = require("../common"); assert = common.assert var net = require("net"), - sys = require("sys"), + util = require("util"), http = require("http"); var errorCount = 0; diff --git a/test/simple/test-child-process-custom-fds.js b/test/simple/test-child-process-custom-fds.js index 5e3b9b8621b..135ac0299b7 100644 --- a/test/simple/test-child-process-custom-fds.js +++ b/test/simple/test-child-process-custom-fds.js @@ -5,7 +5,6 @@ var assert = require('assert'); var spawn = require('child_process').spawn; var path = require('path'); var fs = require('fs'); -var sys = require('sys'); function fixtPath(p) { return path.join(common.fixturesDir, p); diff --git a/test/simple/test-child-process-exec-env.js b/test/simple/test-child-process-exec-env.js index cc8d2f98739..4da8563268f 100644 --- a/test/simple/test-child-process-exec-env.js +++ b/test/simple/test-child-process-exec-env.js @@ -1,7 +1,6 @@ common = require('../common'); assert = common.assert; -var exec = require('child_process').exec, - sys = require('sys'); +var exec = require('child_process').exec; success_count = 0; error_count = 0; response = ""; diff --git a/test/simple/test-crypto.js b/test/simple/test-crypto.js index 99f855f1870..012c1a613a8 100644 --- a/test/simple/test-crypto.js +++ b/test/simple/test-crypto.js @@ -9,7 +9,6 @@ try { } var fs = require('fs'); -var sys = require('sys'); var path = require('path'); // Test Certificates diff --git a/test/simple/test-dgram-multicast.js b/test/simple/test-dgram-multicast.js index 14c86f5617c..a493c0d0eee 100644 --- a/test/simple/test-dgram-multicast.js +++ b/test/simple/test-dgram-multicast.js @@ -2,7 +2,7 @@ common = require("../common"); assert = common.assert var dgram = require("dgram"), - sys = require('sys'), + util = require('util'), assert = require('assert'), Buffer = require("buffer").Buffer; var LOCAL_BROADCAST_HOST = '224.0.0.1'; @@ -35,7 +35,7 @@ sendSocket.sendNext = function () { sendSocket.send(buf, 0, buf.length, common.PORT, LOCAL_BROADCAST_HOST, function (err) { if (err) throw err; - console.error('sent %s to %s', sys.inspect(buf.toString()), + console.error('sent %s to %s', util.inspect(buf.toString()), LOCAL_BROADCAST_HOST+common.PORT); process.nextTick(sendSocket.sendNext); }); @@ -48,7 +48,7 @@ function mkListener() { var listenSocket = dgram.createSocket('udp4') listenSocket.on('message', function(buf, rinfo) { - console.error('received %s from %j', sys.inspect(buf.toString()), rinfo); + console.error('received %s from %j', util.inspect(buf.toString()), rinfo); receivedMessages.push(buf); if (receivedMessages.length == sendMessages.length) { diff --git a/test/simple/test-http-expect-continue.js b/test/simple/test-http-expect-continue.js index 705b66d7dd7..6ccaadc241c 100644 --- a/test/simple/test-http-expect-continue.js +++ b/test/simple/test-http-expect-continue.js @@ -1,6 +1,5 @@ var common = require("../common"); var assert = common.assert; -var sys = require("sys"); var http = require("http"); var outstanding_reqs = 0; @@ -55,7 +54,6 @@ server.addListener("listening", function() { res.addListener('end', function () { common.debug("Got full response."); assert.equal(body, test_res_body, "Response body doesn't match."); -// common.debug(sys.inspect(res.headers)); assert.ok("abcd" in res.headers, "Response headers missing."); outstanding_reqs--; if (outstanding_reqs == 0) { diff --git a/test/simple/test-http-head-request.js b/test/simple/test-http-head-request.js index 2bab5ee55b8..bde0b85c2f8 100644 --- a/test/simple/test-http-head-request.js +++ b/test/simple/test-http-head-request.js @@ -3,7 +3,7 @@ assert = common.assert assert = require("assert"); http = require("http"); -sys = require("sys"); +util = require("util"); body = "hello world\n"; diff --git a/test/simple/test-http-keep-alive-close-on-header.js b/test/simple/test-http-keep-alive-close-on-header.js index 995b7a8452b..329fe39816b 100644 --- a/test/simple/test-http-keep-alive-close-on-header.js +++ b/test/simple/test-http-keep-alive-close-on-header.js @@ -3,7 +3,7 @@ assert = common.assert assert = require("assert"); http = require("http"); -sys = require("sys"); +util = require("util"); body = "hello world\n"; headers = {'connection':'keep-alive'} diff --git a/test/simple/test-http-keep-alive.js b/test/simple/test-http-keep-alive.js index edcb2095977..6aa3f485ca6 100644 --- a/test/simple/test-http-keep-alive.js +++ b/test/simple/test-http-keep-alive.js @@ -3,7 +3,7 @@ assert = common.assert assert = require("assert"); http = require("http"); -sys = require("sys"); +util = require("util"); body = "hello world\n"; headers = {'connection':'keep-alive'} diff --git a/test/simple/test-http-tls.js b/test/simple/test-http-tls.js index d5d3b444048..4c0ebe18e3d 100644 --- a/test/simple/test-http-tls.js +++ b/test/simple/test-http-tls.js @@ -5,7 +5,6 @@ http = require("http"); url = require("url"); qs = require("querystring"); var fs = require('fs'); -var sys = require('sys'); var have_openssl; try { diff --git a/test/simple/test-http-upgrade-server.js b/test/simple/test-http-upgrade-server.js index be516b16fdb..9d2f07597ff 100644 --- a/test/simple/test-http-upgrade-server.js +++ b/test/simple/test-http-upgrade-server.js @@ -1,7 +1,7 @@ common = require("../common"); assert = common.assert -var sys = require("sys"); +var util = require("util"); var net = require("net"); var http = require("http"); @@ -48,7 +48,7 @@ function testServer(){ }); }; -sys.inherits(testServer, http.Server); +util.inherits(testServer, http.Server); function writeReq(socket, data, encoding){ diff --git a/test/simple/test-net-tls.js b/test/simple/test-net-tls.js index c10645157a0..ce9f9873667 100644 --- a/test/simple/test-net-tls.js +++ b/test/simple/test-net-tls.js @@ -1,7 +1,6 @@ common = require("../common"); assert = common.assert var fs = require('fs'); -var sys = require('sys'); var net = require('net'); var have_openssl; diff --git a/test/simple/test-next-tick-ordering.js b/test/simple/test-next-tick-ordering.js index b6df02136a0..5621272a65f 100644 --- a/test/simple/test-next-tick-ordering.js +++ b/test/simple/test-next-tick-ordering.js @@ -1,6 +1,6 @@ common = require("../common"); assert = common.assert -var sys = require('sys'), i; +var i; var N = 30; var done = []; diff --git a/test/simple/test-pump-file2tcp-noexist.js b/test/simple/test-pump-file2tcp-noexist.js index 618b0a89449..61fc6c4f903 100644 --- a/test/simple/test-pump-file2tcp-noexist.js +++ b/test/simple/test-pump-file2tcp-noexist.js @@ -2,7 +2,7 @@ common = require("../common"); assert = common.assert net = require("net"); fs = require("fs"); -sys = require("sys"); +util = require("util"); path = require("path"); fn = path.join(common.fixturesDir, 'does_not_exist.txt'); @@ -11,12 +11,12 @@ var conn_closed = false; server = net.createServer(function (stream) { common.error('pump!'); - sys.pump(fs.createReadStream(fn), stream, function (err) { - common.error("sys.pump's callback fired"); + util.pump(fs.createReadStream(fn), stream, function (err) { + common.error("util.pump's callback fired"); if (err) { got_error = true; } else { - common.debug("sys.pump's callback fired with no error"); + common.debug("util.pump's callback fired with no error"); common.debug("this shouldn't happen as the file doesn't exist..."); assert.equal(true, false); } diff --git a/test/simple/test-pump-file2tcp.js b/test/simple/test-pump-file2tcp.js index 1db0bd5f6f0..96c5167101d 100644 --- a/test/simple/test-pump-file2tcp.js +++ b/test/simple/test-pump-file2tcp.js @@ -2,7 +2,7 @@ common = require("../common"); assert = common.assert net = require("net"); fs = require("fs"); -sys = require("sys"); +util = require("util"); path = require("path"); fn = path.join(common.fixturesDir, 'elipses.txt'); @@ -10,7 +10,7 @@ expected = fs.readFileSync(fn, 'utf8'); server = net.createServer(function (stream) { common.error('pump!'); - sys.pump(fs.createReadStream(fn), stream, function () { + util.pump(fs.createReadStream(fn), stream, function () { common.error('server stream close'); common.error('server close'); server.close(); diff --git a/test/simple/test-regression-object-prototype.js b/test/simple/test-regression-object-prototype.js index 913e12053c3..4491afaae02 100644 --- a/test/simple/test-regression-object-prototype.js +++ b/test/simple/test-regression-object-prototype.js @@ -1,5 +1,3 @@ -var sys = require('sys'); - //console.log('puts before'); Object.prototype.xadsadsdasasdxx = function () { diff --git a/test/simple/test-repl.js b/test/simple/test-repl.js index e0f8b320f92..6db7c01c35f 100644 --- a/test/simple/test-repl.js +++ b/test/simple/test-repl.js @@ -1,8 +1,7 @@ common = require("../common"); assert = common.assert -var sys = require("sys"), - net = require("net"), +var net = require("net"), repl = require("repl"), message = "Read, Eval, Print Loop", unix_socket_path = "/tmp/node-repl-sock", diff --git a/test/simple/test-sendfd.js b/test/simple/test-sendfd.js index 20d0f9273c0..7ed7b02c1a9 100644 --- a/test/simple/test-sendfd.js +++ b/test/simple/test-sendfd.js @@ -34,7 +34,6 @@ var fs = require('fs'); var net = require('net'); var netBinding = process.binding('net'); var path = require('path'); -var sys = require('sys'); var DATA = { 'ppid' : process.pid, diff --git a/test/simple/test-signal-unregister.js b/test/simple/test-signal-unregister.js index 2fbf9696d88..6a3874649b2 100644 --- a/test/simple/test-signal-unregister.js +++ b/test/simple/test-signal-unregister.js @@ -3,7 +3,7 @@ assert = common.assert var childKilled = false, done = false, spawn = require('child_process').spawn, - sys = require("sys"), + util = require("util"), child; var join = require('path').join; diff --git a/test/simple/test-url.js b/test/simple/test-url.js index 312c939b029..0ecc0353042 100644 --- a/test/simple/test-url.js +++ b/test/simple/test-url.js @@ -2,7 +2,7 @@ common = require("../common"); assert = common.assert var url = require("url"), - sys = require("sys"); + util = require("util"); // URLs to parse, and expected data // { url : parsed } diff --git a/tools/ronnjs/bin/ronn.js b/tools/ronnjs/bin/ronn.js index 5087b8e2f15..73fc673d3fe 100755 --- a/tools/ronnjs/bin/ronn.js +++ b/tools/ronnjs/bin/ronn.js @@ -3,10 +3,12 @@ var opts = require(__dirname + '/../lib/ext/opts'); var ronn = require(__dirname + '/../lib/ronn'); +var util = require("util"); + var options = [ { short : 'V' , description : 'Show version and exit' - , callback : function () { sys.puts('0.1'); process.exit(1); } + , callback : function () { util.puts('0.1'); process.exit(1); } }, { short : 'b' , long : 'build' @@ -50,7 +52,6 @@ var arguments = [ opts.parse(options, arguments, true); -var sys = require('sys'); var fs = require('fs'); var path = require('path'); @@ -64,10 +65,10 @@ if (opts.get("man") && !opts.get("build")) { var spawn = require('child_process').spawn; var man = spawn('man', ['--warnings', '-E UTF-8', '-l', '-'], {"LANG":"C"}); man.stdout.addListener('data', function (data) { - sys.puts(data); + util.puts(data); }); man.stderr.addListener('data', function (data) { - sys.puts(data); + util.puts(data); }); man.addListener('exit', function() { process.exit(0); @@ -84,7 +85,7 @@ if (opts.get("man") && !opts.get("build")) { if (opts.get("html")) fHtml = ronn.html(); if (opts.get("fragment")) { if (opts.get("html")) { - sys.debug("Can't use both --fragment and --html"); + util.debug("Can't use both --fragment and --html"); process.exit(-1); } fFrag = ronn.fragment(); @@ -95,8 +96,8 @@ if (opts.get("man") && !opts.get("build")) { if (fHtml) fs.writeFileSync(fBase + ".html", fHtml, 'utf8'); if (fFrag) fs.writeFileSync(fBase + ".fragment", fFrag, 'utf8'); } else { - if (fRoff) sys.puts(fRoff); - if (fHtml) sys.puts(fHtml); - if (fFrag) sys.puts(fFrag); + if (fRoff) util.puts(fRoff); + if (fHtml) util.puts(fHtml); + if (fFrag) util.puts(fFrag); } } diff --git a/tools/ronnjs/lib/ext/opts.js b/tools/ronnjs/lib/ext/opts.js index 92263b0bc9c..0c77e05af93 100755 --- a/tools/ronnjs/lib/ext/opts.js +++ b/tools/ronnjs/lib/ext/opts.js @@ -34,7 +34,7 @@ of the authors and should not be interpreted as representing official policies, either expressed or implied, of Joey Mazzarelli. ***************************************************************************/ -var puts = require('sys').puts +var util = require('util') , values = {} , args = {} , argv = [] @@ -133,8 +133,8 @@ exports.parse = function (options, params, help) { } } } else { - puts('Conflicting flags: ' + prefix + name + '\n'); - puts(helpString()); + util.puts('Conflicting flags: ' + prefix + name + '\n'); + util.puts(helpString()); process.exit(1); } } @@ -173,8 +173,8 @@ exports.parse = function (options, params, help) { // No match. If it starts with a dash, show an error. Otherwise // add it to the extra params. if (inp[0] == '-') { - puts('Unknown option: ' + inp); - if (opts['--help']) puts('Try --help'); + util.puts('Unknown option: ' + inp); + if (opts['--help']) util.puts('Try --help'); process.exit(1); } else { argv.push(inp); @@ -198,8 +198,8 @@ exports.parse = function (options, params, help) { } } if (errors.length) { - for (var i=0; i