API: Move node.puts(), node.exec() and others to /utils.js

This commit is contained in:
Ryan Dahl 2009-09-28 12:06:30 +02:00
parent c35dfdfd5e
commit 7abad8b7b3
22 changed files with 320 additions and 370 deletions

View File

@ -36,7 +36,8 @@ window.onload = function(){generateToc(2)}
World":</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>node.http.createServer(function (request, response) {
<pre><tt>include("/utils.js");
node.http.createServer(function (request, response) {
response.sendHeader(200, {"Content-Type": "text/plain"});
response.sendBody("Hello World\n");
response.finish();
@ -59,47 +60,10 @@ of the 16bit javascript string characters. Both are relatively fast&#8212;use
them if you can. <tt>"utf8"</tt> is slower and should be avoided when possible.</p></div>
<div class="paragraph"><p>Unless otherwise noted, functions are all asynchronous and do not block
execution.</p></div>
<h3 id="_helpers">Helpers</h3><div style="clear:left"></div>
<h3 id="_helpers_and_global_variables">Helpers and Global Variables</h3><div style="clear:left"></div>
<div class="paragraph"><p>These objects are available to all programs.</p></div>
<div class="dlist"><dl>
<dt class="hdlist1">
<tt>puts(string)</tt>
</dt>
<dd>
<p>
Outputs the <tt>string</tt> and a trailing new-line to <tt>stdout</tt>.
</p>
<div class="paragraph"><p>Everything in node is asynchronous; <tt>puts()</tt> is no exception. This might
seem ridiculous but, if for example, one is piping <tt>stdout</tt> into an NFS
file, <tt>printf()</tt> will block from network latency. There is an internal
queue for <tt>puts()</tt> output, so you can be assured that output will be
displayed in the order it was called.</p></div>
</dd>
<dt class="hdlist1">
<tt>node.debug(string)</tt>
</dt>
<dd>
<p>
A synchronous output function. Will block the process and
output the string immediately to stdout.
</p>
</dd>
<dt class="hdlist1">
<tt>node.inspect(object)</tt>
</dt>
<dd>
<p>
Return a string representation of the <tt>object</tt>. (For debugging.)
</p>
</dd>
<dt class="hdlist1">
<tt>print(string)</tt>
</dt>
<dd>
<p>
Like <tt>puts()</tt> but without the trailing new-line.
</p>
</dd>
<dt class="hdlist1">
<tt>node.exit(code)</tt>
</dt>
<dd>
@ -108,33 +72,6 @@ Immediately ends the process with the specified code.
</p>
</dd>
<dt class="hdlist1">
<tt>node.exec(command)</tt>
</dt>
<dd>
<p>
Executes the command as a child process, buffers the output and returns it
in a promise callback.
</p>
<div class="listingblock">
<div class="content">
<pre><tt>node.exec("ls /").addCallback(function (stdout, stderr) {
puts(stdout);
});</tt></pre>
</div></div>
<div class="ulist"><ul>
<li>
<p>
on success: stdout buffer, stderr buffer
</p>
</li>
<li>
<p>
on error: exit code, stdout buffer, stderr buffer
</p>
</li>
</ul></div>
</dd>
<dt class="hdlist1">
<tt>node.cwd()</tt>
</dt>
<dd>
@ -142,9 +79,6 @@ on error: exit code, stdout buffer, stderr buffer
Returns the current working directory of the process.
</p>
</dd>
</dl></div>
<h3 id="_global_variables">Global Variables</h3><div style="clear:left"></div>
<div class="dlist"><dl>
<dt class="hdlist1">
<tt>ARGV</tt>
</dt>
@ -179,6 +113,71 @@ browser-side javascript.
</p>
</dd>
</dl></div>
<h3 id="_utilities">Utilities</h3><div style="clear:left"></div>
<div class="paragraph"><p>These function are in <tt>"/utils.js"</tt>. Use <tt>require("/utils.js")</tt> to access them.</p></div>
<div class="dlist"><dl>
<dt class="hdlist1">
<tt>puts(string)</tt>
</dt>
<dd>
<p>
Outputs the <tt>string</tt> and a trailing new-line to <tt>stdout</tt>.
</p>
</dd>
<dt class="hdlist1">
<tt>print(string)</tt>
</dt>
<dd>
<p>
Like <tt>puts()</tt> but without the trailing new-line.
</p>
</dd>
<dt class="hdlist1">
<tt>debug(string)</tt>
</dt>
<dd>
<p>
A synchronous output function. Will block the process and
output the string immediately to stdout.
</p>
</dd>
<dt class="hdlist1">
<tt>inspect(object)</tt>
</dt>
<dd>
<p>
Return a string representation of the <tt>object</tt>. (For debugging.)
</p>
</dd>
<dt class="hdlist1">
<tt>exec(command)</tt>
</dt>
<dd>
<p>
Executes the command as a child process, buffers the output and returns it
in a promise callback.
</p>
<div class="listingblock">
<div class="content">
<pre><tt>include("/utils.js");
exec("ls /").addCallback(function (stdout, stderr) {
puts(stdout);
});</tt></pre>
</div></div>
<div class="ulist"><ul>
<li>
<p>
on success: stdout buffer, stderr buffer
</p>
</li>
<li>
<p>
on error: exit code, stdout buffer, stderr buffer
</p>
</li>
</ul></div>
</dd>
</dl></div>
<h3 id="_events">Events</h3><div style="clear:left"></div>
<div class="paragraph"><p>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
@ -1944,7 +1943,7 @@ init (Handle&lt;Object&gt; target)
<div id="footer">
<div id="footer-text">
Version 0.1.12<br />
Last updated 2009-09-27 12:27:16 CEST
Last updated 2009-09-28 12:04:19 CEST
</div>
</div>
</body>

View File

@ -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,56 +46,16 @@ Unless otherwise noted, functions are all asynchronous and do not block
execution.
=== Helpers
+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.
+node.debug(string)+::
A synchronous output function. Will block the process and
output the string immediately to stdout.
+node.inspect(object)+ ::
Return a string representation of the +object+. (For debugging.)
+print(string)+::
Like +puts()+ but without the trailing new-line.
=== Helpers and Global Variables
These objects are available to all programs.
+node.exit(code)+::
Immediately ends the process with the specified code.
+node.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) {
puts(stdout);
});
----------------------------------------
+
- on success: stdout buffer, stderr buffer
- 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.
@ -109,6 +70,40 @@ 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.
+inspect(object)+ ::
Return a string representation of the +object+. (For debugging.)
+exec(command)+::
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
Many objects in Node emit events: a TCP server emits an event each time

View File

@ -12,7 +12,8 @@
<refsynopsisdiv id="_synopsis">
<simpara>An example of a web server written with Node which responds with "Hello
World":</simpara>
<screen>node.http.createServer(function (request, response) {
<screen>include("/utils.js");
node.http.createServer(function (request, response) {
response.sendHeader(200, {"Content-Type": "text/plain"});
response.sendBody("Hello World\n");
response.finish();
@ -31,57 +32,12 @@ of the 16bit javascript string characters. Both are relatively fast&#8212;use
them if you can. <literal>"utf8"</literal> is slower and should be avoided when possible.</simpara>
<simpara>Unless otherwise noted, functions are all asynchronous and do not block
execution.</simpara>
<refsect2 id="_helpers">
<title>Helpers</title>
<refsect2 id="_helpers_and_global_variables">
<title>Helpers and Global Variables</title>
<simpara>These objects are available to all programs.</simpara>
<variablelist>
<varlistentry>
<term>
<literal>puts(string)</literal>
</term>
<listitem>
<simpara>
Outputs the <literal>string</literal> and a trailing new-line to <literal>stdout</literal>.
</simpara>
<simpara>Everything in node is asynchronous; <literal>puts()</literal> is no exception. This might
seem ridiculous but, if for example, one is piping <literal>stdout</literal> into an NFS
file, <literal>printf()</literal> will block from network latency. There is an internal
queue for <literal>puts()</literal> output, so you can be assured that output will be
displayed in the order it was called.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>node.debug(string)</literal>
</term>
<listitem>
<simpara>
A synchronous output function. Will block the process and
output the string immediately to stdout.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>node.inspect(object)</literal>
</term>
<listitem>
<simpara>
Return a string representation of the <literal>object</literal>. (For debugging.)
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>print(string)</literal>
</term>
<listitem>
<simpara>
Like <literal>puts()</literal> but without the trailing new-line.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>node.exit(code)</literal>
</term>
<listitem>
@ -92,32 +48,6 @@ Immediately ends the process with the specified code.
</varlistentry>
<varlistentry>
<term>
<literal>node.exec(command)</literal>
</term>
<listitem>
<simpara>
Executes the command as a child process, buffers the output and returns it
in a promise callback.
</simpara>
<screen>node.exec("ls /").addCallback(function (stdout, stderr) {
puts(stdout);
});</screen>
<itemizedlist>
<listitem>
<simpara>
on success: stdout buffer, stderr buffer
</simpara>
</listitem>
<listitem>
<simpara>
on error: exit code, stdout buffer, stderr buffer
</simpara>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>node.cwd()</literal>
</term>
<listitem>
@ -126,11 +56,6 @@ Returns the current working directory of the process.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</refsect2>
<refsect2 id="_global_variables">
<title>Global Variables</title>
<variablelist>
<varlistentry>
<term>
<literal>ARGV</literal>
@ -174,6 +99,80 @@ browser-side javascript.
</varlistentry>
</variablelist>
</refsect2>
<refsect2 id="_utilities">
<title>Utilities</title>
<simpara>These function are in <literal>"/utils.js"</literal>. Use <literal>require("/utils.js")</literal> to access them.</simpara>
<variablelist>
<varlistentry>
<term>
<literal>puts(string)</literal>
</term>
<listitem>
<simpara>
Outputs the <literal>string</literal> and a trailing new-line to <literal>stdout</literal>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>print(string)</literal>
</term>
<listitem>
<simpara>
Like <literal>puts()</literal> but without the trailing new-line.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>debug(string)</literal>
</term>
<listitem>
<simpara>
A synchronous output function. Will block the process and
output the string immediately to stdout.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>inspect(object)</literal>
</term>
<listitem>
<simpara>
Return a string representation of the <literal>object</literal>. (For debugging.)
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>exec(command)</literal>
</term>
<listitem>
<simpara>
Executes the command as a child process, buffers the output and returns it
in a promise callback.
</simpara>
<screen>include("/utils.js");
exec("ls /").addCallback(function (stdout, stderr) {
puts(stdout);
});</screen>
<itemizedlist>
<listitem>
<simpara>
on success: stdout buffer, stderr buffer
</simpara>
</listitem>
<listitem>
<simpara>
on error: exit code, stdout buffer, stderr buffer
</simpara>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
</variablelist>
</refsect2>
<refsect2 id="_events">
<title>Events</title>
<simpara>Many objects in Node emit events: a TCP server emits an event each time

View File

@ -41,14 +41,17 @@
</p>
<pre>
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/");</pre>
});
server.listen(8000);
utils.puts("Server running at http://127.0.0.1:8000/");</pre>
</pre>
<p>
To run the server, put the code into a file

View File

@ -1,11 +1,11 @@
.\" Title: node
.\" Author:
.\" Generator: DocBook XSL Stylesheets v1.73.2 <http://docbook.sf.net/>
.\" 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,75 +41,18 @@ 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"
.PP
puts(string)
.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\.
.RE
.PP
node\.debug(string)
.RS 4
A synchronous output function\. Will block the process and output the string immediately to stdout\.
.RE
.PP
node\.inspect(object)
.RS 4
Return a string representation of the
object\. (For debugging\.)
.RE
.PP
print(string)
.RS 4
Like
puts()
but without the trailing new\-line\.
.RE
.SS "Helpers and Global Variables"
These objects are available to all programs\.
.PP
node\.exit(code)
.RS 4
Immediately ends the process with the specified code\.
.RE
.PP
node\.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) {
puts(stdout);
});
.fi
.RE
.sp
.RS 4
\h'-04'\(bu\h'+03'on success: stdout buffer, stderr buffer
.RE
.sp
.RS 4
\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
@ -133,6 +77,56 @@ 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)
.RS 4
Like
puts()
but without the trailing new\-line\.
.RE
.PP
debug(string)
.RS 4
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
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
include("/utils\.js");
exec("ls /")\.addCallback(function (stdout, stderr) {
puts(stdout);
});
.fi
.RE
.sp
.RS 4
\h'-04'\(bu\h'+03'on success: stdout buffer, stderr buffer
.RE
.sp
.RS 4
\h'-04'\(bu\h'+03'on error: exit code, stdout buffer, stderr buffer
.RE
.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{

View File

@ -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 = '';

View File

@ -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);
}

View File

@ -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.");
}

View File

@ -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];

View File

@ -1,6 +1,7 @@
node.debug("load fixtures/a.js");
var c = require("b/c.js");
debug("load fixtures/a.js");
var string = "A";

View File

@ -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 () {

View File

@ -1,4 +1,4 @@
node.debug("load fixtures/b/d.js");
debug("load fixtures/b/d.js");
var string = "D";

View File

@ -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);

View File

@ -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 != "");

View File

@ -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);
});

View File

@ -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");
});
});

View File

@ -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);

View File

@ -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");

View File

@ -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);
});
});

View File

@ -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 {

View File

@ -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);
});

View File

@ -63,5 +63,5 @@ client.addListener("eof", function () {
process.addListener("exit", function () {
assertEquals(N, recv.length);
node.debug("Exit");
debug("Exit");
});