From 7abad8b7b360bc328243475fa59b899fcb902c60 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Mon, 28 Sep 2009 12:06:30 +0200 Subject: [PATCH] API: Move node.puts(), node.exec() and others to /utils.js --- doc/api.html | 107 ++++++++++---------- doc/api.txt | 73 +++++++------- doc/api.xml | 105 ++++++++++--------- doc/index.html | 9 +- doc/node.1 | 128 +++++++++++------------- lib/repl.js | 4 +- src/node.js | 28 +----- src/util.js | 54 +++------- test/mjsunit/common.js | 1 + test/mjsunit/fixtures/a.js | 5 +- test/mjsunit/fixtures/b/c.js | 4 +- test/mjsunit/fixtures/b/d.js | 2 +- test/mjsunit/test-buffered-file.js | 2 +- test/mjsunit/test-exec.js | 4 +- test/mjsunit/test-file-cat-noexist.js | 4 +- test/mjsunit/test-http-proxy.js | 16 +-- test/mjsunit/test-http.js | 8 +- test/mjsunit/test-module-loading.js | 4 +- test/mjsunit/test-multipart.js | 4 +- test/mjsunit/test-tcp-binary.js | 20 ++-- test/mjsunit/test-tcp-pingpong-delay.js | 4 +- test/mjsunit/test-tcp-throttle.js | 2 +- 22 files changed, 269 insertions(+), 319 deletions(-) diff --git a/doc/api.html b/doc/api.html index c303993214..fe7d4c1b16 100644 --- a/doc/api.html +++ b/doc/api.html @@ -36,7 +36,8 @@ window.onload = function(){generateToc(2)} World":

-
node.http.createServer(function (request, response) {
+
include("/utils.js");
+node.http.createServer(function (request, response) {
   response.sendHeader(200, {"Content-Type": "text/plain"});
   response.sendBody("Hello World\n");
   response.finish();
@@ -59,124 +60,122 @@ of the 16bit javascript string characters. Both are relatively fast—use
 them if you can. "utf8" is slower and should be avoided when possible.

Unless otherwise noted, functions are all asynchronous and do not block execution.

-

Helpers

+

Helpers and Global Variables

+

These objects are available to all programs.

-puts(string) +node.exit(code)

-Outputs the string and a trailing new-line to stdout. +Immediately ends the process with the specified code.

-

Everything in node is asynchronous; puts() is no exception. This might -seem ridiculous but, if for example, one is piping stdout into an NFS -file, printf() will block from network latency. There is an internal -queue for puts() output, so you can be assured that output will be -displayed in the order it was called.

-node.debug(string) +node.cwd()

-A synchronous output function. Will block the process and -output the string immediately to stdout. +Returns the current working directory of the process.

-node.inspect(object) +ARGV

-Return a string representation of the object. (For debugging.) +An array containing the command line arguments.

-print(string) +ENV

-Like puts() but without the trailing new-line. +An object containing the user environment. See environ(7).

-node.exit(code) +__filename

-Immediately ends the process with the specified code. +The filename of the script being executed.

-node.exec(command) +process

-Executes the command as a child process, buffers the output and returns it -in a promise callback. -

-
-
-
node.exec("ls /").addCallback(function (stdout, stderr) {
-  puts(stdout);
-});
-
-
    -
  • -

    -on success: stdout buffer, stderr buffer -

    -
  • -
  • -

    -on error: exit code, stdout buffer, stderr buffer +A special global object. The process object is like the window object of +browser-side javascript.

    -
  • -
+
+

Utilities

+

These function are in "/utils.js". Use require("/utils.js") to access them.

+
-node.cwd() +puts(string)

-Returns the current working directory of the process. +Outputs the string and a trailing new-line to stdout.

-
-

Global Variables

-
-ARGV +print(string)

-An array containing the command line arguments. +Like puts() but without the trailing new-line.

-ENV +debug(string)

-An object containing the user environment. See environ(7). +A synchronous output function. Will block the process and +output the string immediately to stdout.

-__filename +inspect(object)

-The filename of the script being executed. +Return a string representation of the object. (For debugging.)

-process +exec(command)

-A special global object. The process object is like the window object of -browser-side javascript. +Executes the command as a child process, buffers the output and returns it +in a promise callback. +

+
+
+
include("/utils.js");
+exec("ls /").addCallback(function (stdout, stderr) {
+  puts(stdout);
+});
+
+
    +
  • +

    +on success: stdout buffer, stderr buffer +

    +
  • +
  • +

    +on error: exit code, stdout buffer, stderr buffer

    +
  • +

Events

@@ -1944,7 +1943,7 @@ init (Handle<Object> target) diff --git a/doc/api.txt b/doc/api.txt index fbc80ea57a..3f858c4002 100644 --- a/doc/api.txt +++ b/doc/api.txt @@ -16,6 +16,7 @@ An example of a web server written with Node which responds with "Hello World": ---------------------------------------- +include("/utils.js"); node.http.createServer(function (request, response) { response.sendHeader(200, {"Content-Type": "text/plain"}); response.sendBody("Hello World\n"); @@ -45,40 +46,55 @@ Unless otherwise noted, functions are all asynchronous and do not block execution. -=== Helpers +=== Helpers and Global Variables -+puts(string)+:: -Outputs the +string+ and a trailing new-line to +stdout+. -+ -Everything in node is asynchronous; +puts()+ is no exception. This might -seem ridiculous but, if for example, one is piping +stdout+ into an NFS -file, +printf()+ will block from network latency. There is an internal -queue for +puts()+ output, so you can be assured that output will be -displayed in the order it was called. +These objects are available to all programs. ++node.exit(code)+:: +Immediately ends the process with the specified code. -+node.debug(string)+:: -A synchronous output function. Will block the process and -output the string immediately to stdout. ++node.cwd()+:: +Returns the current working directory of the process. ++ARGV+ :: +An array containing the command line arguments. -+node.inspect(object)+ :: -Return a string representation of the +object+. (For debugging.) ++ENV+ :: +An object containing the user environment. See environ(7). + ++__filename+ :: +The filename of the script being executed. ++process+ :: +A special global object. The +process+ object is like the +window+ object of +browser-side javascript. + + + +=== Utilities + +These function are in +"/utils.js"+. Use +require("/utils.js")+ to access them. + ++puts(string)+:: +Outputs the +string+ and a trailing new-line to +stdout+. +print(string)+:: Like +puts()+ but without the trailing new-line. ++debug(string)+:: +A synchronous output function. Will block the process and +output the string immediately to stdout. -+node.exit(code)+:: -Immediately ends the process with the specified code. ++inspect(object)+ :: +Return a string representation of the +object+. (For debugging.) -+node.exec(command)+:: ++exec(command)+:: Executes the command as a child process, buffers the output and returns it in a promise callback. + ---------------------------------------- -node.exec("ls /").addCallback(function (stdout, stderr) { +include("/utils.js"); +exec("ls /").addCallback(function (stdout, stderr) { puts(stdout); }); ---------------------------------------- @@ -87,27 +103,6 @@ node.exec("ls /").addCallback(function (stdout, stderr) { - on error: exit code, stdout buffer, stderr buffer -+node.cwd()+:: -Returns the current working directory of the process. - - -=== Global Variables - - - -+ARGV+ :: -An array containing the command line arguments. - -+ENV+ :: -An object containing the user environment. See environ(7). - -+__filename+ :: -The filename of the script being executed. - -+process+ :: -A special global object. The +process+ object is like the +window+ object of -browser-side javascript. - === Events diff --git a/doc/api.xml b/doc/api.xml index 333ed843d2..470c079245 100644 --- a/doc/api.xml +++ b/doc/api.xml @@ -12,7 +12,8 @@ An example of a web server written with Node which responds with "Hello World": -node.http.createServer(function (request, response) { +include("/utils.js"); +node.http.createServer(function (request, response) { response.sendHeader(200, {"Content-Type": "text/plain"}); response.sendBody("Hello World\n"); response.finish(); @@ -31,145 +32,143 @@ of the 16bit javascript string characters. Both are relatively fast—use them if you can. "utf8" is slower and should be avoided when possible. Unless otherwise noted, functions are all asynchronous and do not block execution. - -Helpers + +Helpers and Global Variables +These objects are available to all programs. -puts(string) +node.exit(code) -Outputs the string and a trailing new-line to stdout. +Immediately ends the process with the specified code. -Everything in node is asynchronous; puts() is no exception. This might -seem ridiculous but, if for example, one is piping stdout into an NFS -file, printf() will block from network latency. There is an internal -queue for puts() output, so you can be assured that output will be -displayed in the order it was called. -node.debug(string) +node.cwd() -A synchronous output function. Will block the process and -output the string immediately to stdout. +Returns the current working directory of the process. -node.inspect(object) +ARGV -Return a string representation of the object. (For debugging.) +An array containing the command line arguments. -print(string) +ENV -Like puts() but without the trailing new-line. +An object containing the user environment. See environ(7). -node.exit(code) +__filename -Immediately ends the process with the specified code. +The filename of the script being executed. -node.exec(command) +process -Executes the command as a child process, buffers the output and returns it -in a promise callback. - -node.exec("ls /").addCallback(function (stdout, stderr) { - puts(stdout); -}); - - - -on success: stdout buffer, stderr buffer - - - - -on error: exit code, stdout buffer, stderr buffer +A special global object. The process object is like the window object of +browser-side javascript. - - + + + +Utilities +These function are in "/utils.js". Use require("/utils.js") to access them. + -node.cwd() +puts(string) -Returns the current working directory of the process. +Outputs the string and a trailing new-line to stdout. - - - -Global Variables - -ARGV +print(string) -An array containing the command line arguments. +Like puts() but without the trailing new-line. -ENV +debug(string) -An object containing the user environment. See environ(7). +A synchronous output function. Will block the process and +output the string immediately to stdout. -__filename +inspect(object) -The filename of the script being executed. +Return a string representation of the object. (For debugging.) -process +exec(command) -A special global object. The process object is like the window object of -browser-side javascript. +Executes the command as a child process, buffers the output and returns it +in a promise callback. +include("/utils.js"); +exec("ls /").addCallback(function (stdout, stderr) { + puts(stdout); +}); + + + +on success: stdout buffer, stderr buffer + + + + +on error: exit code, stdout buffer, stderr buffer + + + diff --git a/doc/index.html b/doc/index.html index 59bf583de3..dbce7afc15 100644 --- a/doc/index.html +++ b/doc/index.html @@ -41,14 +41,17 @@

-node.http.createServer(function (req, res) {
+utils = require("/utils.js");
+server = node.http.createServer(function (req, res) {
   setTimeout(function () {
     res.sendHeader(200, {"Content-Type": "text/plain"});
     res.sendBody("Hello World");
     res.finish();
   }, 2000);
-}).listen(8000);
-puts("Server running at http://127.0.0.1:8000/");
+}); +server.listen(8000); +utils.puts("Server running at http://127.0.0.1:8000/"); +

To run the server, put the code into a file diff --git a/doc/node.1 b/doc/node.1 index 1a982822ea..b36944316f 100644 --- a/doc/node.1 +++ b/doc/node.1 @@ -1,11 +1,11 @@ .\" Title: node .\" Author: .\" Generator: DocBook XSL Stylesheets v1.73.2 -.\" Date: 09/27/2009 +.\" Date: 09/28/2009 .\" Manual: .\" Source: .\" -.TH "NODE" "1" "09/27/2009" "" "" +.TH "NODE" "1" "09/28/2009" "" "" .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) @@ -18,6 +18,7 @@ An example of a web server written with Node which responds with "Hello World": .sp .RS 4 .nf +include("/utils\.js"); node\.http\.createServer(function (request, response) { response\.sendHeader(200, {"Content\-Type": "text/plain"}); response\.sendBody("Hello World\en"); @@ -40,35 +41,51 @@ Node supports 3 string encodings\. UTF\-8 ("utf8"), ASCII ("ascii"), and Binary .sp Unless otherwise noted, functions are all asynchronous and do not block execution\. .sp -.SS "Helpers" +.SS "Helpers and Global Variables" +These objects are available to all programs\. .PP -puts(string) +node\.exit(code) .RS 4 -Outputs the -string -and a trailing new\-line to -stdout\. -.sp -Everything in node is asynchronous; -puts() -is no exception\. This might seem ridiculous but, if for example, one is piping -stdout -into an NFS file, -printf() -will block from network latency\. There is an internal queue for -puts() -output, so you can be assured that output will be displayed in the order it was called\. +Immediately ends the process with the specified code\. .RE .PP -node\.debug(string) +node\.cwd() .RS 4 -A synchronous output function\. Will block the process and output the string immediately to stdout\. +Returns the current working directory of the process\. .RE .PP -node\.inspect(object) +ARGV .RS 4 -Return a string representation of the -object\. (For debugging\.) +An array containing the command line arguments\. +.RE +.PP +ENV +.RS 4 +An object containing the user environment\. See environ(7)\. +.RE +.PP +__filename +.RS 4 +The filename of the script being executed\. +.RE +.PP +process +.RS 4 +A special global object\. The +process +object is like the +window +object of browser\-side javascript\. +.RE +.SS "Utilities" +These function are in "/utils\.js"\. Use require("/utils\.js") to access them\. +.PP +puts(string) +.RS 4 +Outputs the +string +and a trailing new\-line to +stdout\. .RE .PP print(string) @@ -78,18 +95,25 @@ puts() but without the trailing new\-line\. .RE .PP -node\.exit(code) +debug(string) .RS 4 -Immediately ends the process with the specified code\. +A synchronous output function\. Will block the process and output the string immediately to stdout\. +.RE +.PP +inspect(object) +.RS 4 +Return a string representation of the +object\. (For debugging\.) .RE .PP -node\.exec(command) +exec(command) .RS 4 Executes the command as a child process, buffers the output and returns it in a promise callback\. .sp .RS 4 .nf -node\.exec("ls /")\.addCallback(function (stdout, stderr) { +include("/utils\.js"); +exec("ls /")\.addCallback(function (stdout, stderr) { puts(stdout); }); .fi @@ -103,36 +127,6 @@ node\.exec("ls /")\.addCallback(function (stdout, stderr) { \h'-04'\(bu\h'+03'on error: exit code, stdout buffer, stderr buffer .RE .RE -.PP -node\.cwd() -.RS 4 -Returns the current working directory of the process\. -.RE -.SS "Global Variables" -.PP -ARGV -.RS 4 -An array containing the command line arguments\. -.RE -.PP -ENV -.RS 4 -An object containing the user environment\. See environ(7)\. -.RE -.PP -__filename -.RS 4 -The filename of the script being executed\. -.RE -.PP -process -.RS 4 -A special global object\. The -process -object is like the -window -object of browser\-side javascript\. -.RE .SS "Events" Many objects in Node emit events: a TCP server emits an event each time there is a connection, a child process emits an event when it exits\. All objects which emit events are are instances of node\.EventEmitter\. .sp @@ -153,7 +147,7 @@ All EventEmitters emit the event "newListener" when new listeners are added\. .sp .TS allbox tab(:); -ltB ltB ltB. +ltB ltB ltBx. T{ Event T}:T{ @@ -209,7 +203,7 @@ node\.Promise inherits from node\.eventEmitter\. A promise emits one of two even .sp .TS allbox tab(:); -ltB ltB ltB. +ltB ltB ltBx. T{ Event T}:T{ @@ -308,7 +302,7 @@ Standard I/O is handled through a special object node\.stdio\. stdout and stdin .sp .TS allbox tab(:); -ltB ltB ltB. +ltB ltB ltBx. T{ Event T}:T{ @@ -494,7 +488,7 @@ node.ChildProcess .RS .TS allbox tab(:); -ltB ltB ltB. +ltB ltB ltBx. T{ Event T}:T{ @@ -850,7 +844,7 @@ node.http.Server .RS .TS allbox tab(:); -ltB ltB ltB. +ltB ltB ltBx. T{ Event T}:T{ @@ -934,7 +928,7 @@ This object is created internally by a HTTP server\(emnot by the user\(emand pas .sp .TS allbox tab(:); -ltB ltB ltB. +ltB ltB ltBx. T{ Event T}:T{ @@ -1191,7 +1185,7 @@ This object is created internally and returned from the request methods of a nod .sp .TS allbox tab(:); -ltB ltB ltB. +ltB ltB ltBx. T{ Event T}:T{ @@ -1289,7 +1283,7 @@ This object is created internally and passed to the "response" event\. .sp .TS allbox tab(:); -ltB ltB ltB. +ltB ltB ltBx. T{ Event T}:T{ @@ -1398,7 +1392,7 @@ server\.listen(7000, "localhost"); .RE .TS allbox tab(:); -ltB ltB ltB. +ltB ltB ltBx. T{ Event T}:T{ @@ -1480,7 +1474,7 @@ This object is used as a TCP client and also as a server\-side socket for node\. .sp .TS allbox tab(:); -ltB ltB ltB. +ltB ltB ltBx. T{ Event T}:T{ diff --git a/lib/repl.js b/lib/repl.js index a55df4ef76..a1fce7f005 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -1,6 +1,8 @@ // 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"); + puts("Type '.help' for options."); node.stdio.open(); @@ -42,7 +44,7 @@ function readline (cmd) { with (exports.scope) { var ret = eval(buffered_cmd); exports.scope['_'] = ret; - puts(node.inspect(ret)); + utils.p(ret); } buffered_cmd = ''; diff --git a/src/node.js b/src/node.js index 257c5e8bcf..1f5dfee8a5 100644 --- a/src/node.js +++ b/src/node.js @@ -15,30 +15,9 @@ node.createChildProcess = function (command) { return child; }; -node.exec = function (command) { - var child = node.createChildProcess(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; -}; +node.exec = function () { + throw new Error("node.exec() has moved. Use include('/utils.js') to bring it back."); +} node.tcp.createConnection = function (port, host) { var connection = new node.tcp.Connection(); @@ -220,7 +199,6 @@ node.Module.prototype.loadObject = function (loadPromise) { node.dlopen(self.filename, self.target); // FIXME synchronus loadPromise.emitSuccess(self.target); } else { - node.error("Error reading " + self.filename + "\n"); loadPromise.emitError(new Error("Error reading " + self.filename)); node.exit(1); } diff --git a/src/util.js b/src/util.js index a90e9a93c0..930e65bccb 100644 --- a/src/util.js +++ b/src/util.js @@ -64,47 +64,23 @@ node.path = new function () { }; }; -print = function (x) { - node.stdio.write(x); -}; -puts = function (x) { - print(x.toString() + "\n"); -}; +puts = function () { + throw new Error("puts() has moved. Use include('/utils.js') to bring it back."); +} -node.debug = function (x) { - node.stdio.writeError("DEBUG: " + x.toString() + "\n"); -}; +print = function () { + throw new Error("print() has moved. Use include('/utils.js') to bring it back."); +} -node.error = function (x) { - node.stdio.writeError(x.toString() + "\n"); -}; +p = function () { + throw new Error("p() has moved. Use include('/utils.js') to bring it back."); +} -/** - * 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 - */ -node.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; - } - } -}; +node.debug = function () { + throw new Error("node.debug() has moved. Use include('/utils.js') to bring it back."); +} -p = function (x) { - node.error(node.inspect(x)); -}; +node.error = function () { + throw new Error("node.error() has moved. Use include('/utils.js') to bring it back."); +} diff --git a/test/mjsunit/common.js b/test/mjsunit/common.js index d7e0808035..b74dac6209 100644 --- a/test/mjsunit/common.js +++ b/test/mjsunit/common.js @@ -5,6 +5,7 @@ exports.libDir = node.path.join(exports.testDir, "../../lib"); node.libraryPaths.unshift(exports.libDir); var mjsunit = require("/mjsunit.js"); +include("/utils.js"); // Copy mjsunit namespace out for (var prop in mjsunit) { if (mjsunit.hasOwnProperty(prop)) exports[prop] = mjsunit[prop]; diff --git a/test/mjsunit/fixtures/a.js b/test/mjsunit/fixtures/a.js index 80a079845e..ed1da113b0 100644 --- a/test/mjsunit/fixtures/a.js +++ b/test/mjsunit/fixtures/a.js @@ -1,6 +1,7 @@ -node.debug("load fixtures/a.js"); - var c = require("b/c.js"); + +debug("load fixtures/a.js"); + var string = "A"; diff --git a/test/mjsunit/fixtures/b/c.js b/test/mjsunit/fixtures/b/c.js index a90ea9eddd..a9dd96b846 100644 --- a/test/mjsunit/fixtures/b/c.js +++ b/test/mjsunit/fixtures/b/c.js @@ -1,7 +1,7 @@ -node.debug("load fixtures/b/c.js"); - var d = require("d.js"); +debug("load fixtures/b/c.js"); + var string = "C"; exports.C = function () { diff --git a/test/mjsunit/fixtures/b/d.js b/test/mjsunit/fixtures/b/d.js index c9e0e7bc8c..076d96af74 100644 --- a/test/mjsunit/fixtures/b/d.js +++ b/test/mjsunit/fixtures/b/d.js @@ -1,4 +1,4 @@ -node.debug("load fixtures/b/d.js"); +debug("load fixtures/b/d.js"); var string = "D"; diff --git a/test/mjsunit/test-buffered-file.js b/test/mjsunit/test-buffered-file.js index f6efc481b9..dc10100f8b 100644 --- a/test/mjsunit/test-buffered-file.js +++ b/test/mjsunit/test-buffered-file.js @@ -15,7 +15,7 @@ setTimeout(function () { file.write("hello\n"); file.write("world\n"); file.close().addCallback(function () { - node.error("file closed..."); + error("file closed..."); var out = node.fs.cat(testTxt).wait(); print("the file contains: "); p(out); diff --git a/test/mjsunit/test-exec.js b/test/mjsunit/test-exec.js index 942002406a..7e386fdd68 100644 --- a/test/mjsunit/test-exec.js +++ b/test/mjsunit/test-exec.js @@ -3,7 +3,7 @@ include("common.js"); success_count = 0; error_count = 0; -node.exec("ls /").addCallback(function (out) { +exec("ls /").addCallback(function (out) { success_count++; p(out); }).addErrback(function (code, out, err) { @@ -15,7 +15,7 @@ node.exec("ls /").addCallback(function (out) { -node.exec("ls /DOES_NOT_EXIST").addCallback(function (out) { +exec("ls /DOES_NOT_EXIST").addCallback(function (out) { success_count++; p(out); assertTrue(out != ""); diff --git a/test/mjsunit/test-file-cat-noexist.js b/test/mjsunit/test-file-cat-noexist.js index c36b99146e..6b652d97a3 100644 --- a/test/mjsunit/test-file-cat-noexist.js +++ b/test/mjsunit/test-file-cat-noexist.js @@ -5,8 +5,8 @@ var filename = node.path.join(fixturesDir, "does_not_exist.txt"); var promise = node.fs.cat(filename, "raw"); promise.addCallback(function (content) { - node.debug("cat returned some content: " + content); - node.debug("this shouldn't happen as the file doesn't exist..."); + debug("cat returned some content: " + content); + debug("this shouldn't happen as the file doesn't exist..."); assertTrue(false); }); diff --git a/test/mjsunit/test-http-proxy.js b/test/mjsunit/test-http-proxy.js index f02f21e773..04743d934b 100644 --- a/test/mjsunit/test-http-proxy.js +++ b/test/mjsunit/test-http-proxy.js @@ -4,17 +4,17 @@ var PROXY_PORT = 8869; var BACKEND_PORT = 8870; var backend = node.http.createServer(function (req, res) { - // node.debug("backend"); + // debug("backend"); res.sendHeader(200, {"content-type": "text/plain"}); res.sendBody("hello world\n"); res.finish(); }); -// node.debug("listen backend") +// debug("listen backend") backend.listen(BACKEND_PORT); var proxy_client = node.http.createClient(BACKEND_PORT); var proxy = node.http.createServer(function (req, res) { - node.debug("proxy req headers: " + JSON.stringify(req.headers)); + debug("proxy req headers: " + JSON.stringify(req.headers)); var proxy_req = proxy_client.get(req.uri.path); proxy_req.finish(function(proxy_res) { res.sendHeader(proxy_res.statusCode, proxy_res.headers); @@ -23,27 +23,27 @@ var proxy = node.http.createServer(function (req, res) { }); proxy_res.addListener("complete", function() { res.finish(); - // node.debug("proxy res"); + // debug("proxy res"); }); }); }); -// node.debug("listen proxy") +// debug("listen proxy") proxy.listen(PROXY_PORT); var body = ""; var client = node.http.createClient(PROXY_PORT); var req = client.get("/test"); -// node.debug("client req") +// debug("client req") req.finish(function (res) { - // node.debug("got res"); + // debug("got res"); assertEquals(200, res.statusCode); res.setBodyEncoding("utf8"); res.addListener("body", function (chunk) { body += chunk; }); res.addListener("complete", function () { proxy.close(); backend.close(); - // node.debug("closed both"); + // debug("closed both"); }); }); diff --git a/test/mjsunit/test-http.js b/test/mjsunit/test-http.js index 89f273bd82..a2e339edb2 100644 --- a/test/mjsunit/test-http.js +++ b/test/mjsunit/test-http.js @@ -42,7 +42,7 @@ req.finish(function (res) { responses_recvd += 1; res.setBodyEncoding("ascii"); res.addListener("body", function (chunk) { body0 += chunk; }); - node.debug("Got /hello response"); + debug("Got /hello response"); }); setTimeout(function () { @@ -52,15 +52,15 @@ setTimeout(function () { responses_recvd += 1; res.setBodyEncoding("utf8"); res.addListener("body", function (chunk) { body1 += chunk; }); - node.debug("Got /world response"); + debug("Got /world response"); }); }, 1); process.addListener("exit", function () { - node.debug("responses_recvd: " + responses_recvd); + debug("responses_recvd: " + responses_recvd); assertEquals(2, responses_recvd); - node.debug("responses_sent: " + responses_sent); + debug("responses_sent: " + responses_sent); assertEquals(2, responses_sent); assertEquals("The path was /hello", body0); diff --git a/test/mjsunit/test-module-loading.js b/test/mjsunit/test-module-loading.js index 4eb45626ae..814f7006f0 100644 --- a/test/mjsunit/test-module-loading.js +++ b/test/mjsunit/test-module-loading.js @@ -1,5 +1,7 @@ -node.debug("load test-module-loading.js"); include("common.js"); + +debug("load test-module-loading.js"); + var a = require("fixtures/a.js"); var d = require("fixtures/b/d.js"); var d2 = require("fixtures/b/d.js"); diff --git a/test/mjsunit/test-multipart.js b/test/mjsunit/test-multipart.js index 40f78ffd3c..33a74f7662 100644 --- a/test/mjsunit/test-multipart.js +++ b/test/mjsunit/test-multipart.js @@ -44,8 +44,8 @@ var server = node.http.createServer(function(req, res) { server.listen(port); var cmd = 'curl -H "Expect:" -F "test-field=foobar" -F test-file=@'+__filename+' http://localhost:'+port+'/'; -var result = node.exec(cmd).wait(); +var result = exec(cmd).wait(); process.addListener('exit', function() { assertEquals(2, parts_complete); -}); \ No newline at end of file +}); diff --git a/test/mjsunit/test-tcp-binary.js b/test/mjsunit/test-tcp-binary.js index 0cf2b358c3..0758d9ac31 100644 --- a/test/mjsunit/test-tcp-binary.js +++ b/test/mjsunit/test-tcp-binary.js @@ -5,14 +5,14 @@ binaryString = ""; for (var i = 255; i >= 0; i--) { var s = "'\\" + i.toString(8) + "'"; S = eval(s); - node.error( s - + " " - + JSON.stringify(S) - + " " - + JSON.stringify(String.fromCharCode(i)) - + " " - + S.charCodeAt(0) - ); + error( s + + " " + + JSON.stringify(S) + + " " + + JSON.stringify(String.fromCharCode(i)) + + " " + + S.charCodeAt(0) + ); node.assert(S.charCodeAt(0) == i); node.assert(S == String.fromCharCode(i)); binaryString += S; @@ -21,7 +21,7 @@ for (var i = 255; i >= 0; i--) { var echoServer = node.tcp.createServer(function (connection) { connection.setEncoding("binary"); connection.addListener("receive", function (chunk) { - node.error("recved: " + JSON.stringify(chunk)); + error("recved: " + JSON.stringify(chunk)); connection.send(chunk, "binary"); }); connection.addListener("eof", function () { @@ -38,7 +38,7 @@ var c = node.tcp.createConnection(PORT); c.setEncoding("binary"); c.addListener("receive", function (chunk) { if (j < 256) { - node.error("send " + j); + error("send " + j); c.send(String.fromCharCode(j), "binary"); j++; } else { diff --git a/test/mjsunit/test-tcp-pingpong-delay.js b/test/mjsunit/test-tcp-pingpong-delay.js index af980e4cbd..fd0149b5aa 100644 --- a/test/mjsunit/test-tcp-pingpong-delay.js +++ b/test/mjsunit/test-tcp-pingpong-delay.js @@ -24,7 +24,7 @@ function pingPongTest (port, host, on_complete) { }); socket.addListener("timeout", function () { - node.debug("server-side timeout!!"); + debug("server-side timeout!!"); assertFalse(true); }); @@ -70,7 +70,7 @@ function pingPongTest (port, host, on_complete) { }); client.addListener("timeout", function () { - node.debug("client-side timeout!!"); + debug("client-side timeout!!"); assertFalse(true); }); diff --git a/test/mjsunit/test-tcp-throttle.js b/test/mjsunit/test-tcp-throttle.js index 05ad0df42e..063019df50 100644 --- a/test/mjsunit/test-tcp-throttle.js +++ b/test/mjsunit/test-tcp-throttle.js @@ -63,5 +63,5 @@ client.addListener("eof", function () { process.addListener("exit", function () { assertEquals(N, recv.length); - node.debug("Exit"); + debug("Exit"); });