Browse Source

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

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
7abad8b7b3
  1. 107
      doc/api.html
  2. 73
      doc/api.txt
  3. 105
      doc/api.xml
  4. 9
      doc/index.html
  5. 128
      doc/node.1
  6. 4
      lib/repl.js
  7. 28
      src/node.js
  8. 54
      src/util.js
  9. 1
      test/mjsunit/common.js
  10. 5
      test/mjsunit/fixtures/a.js
  11. 4
      test/mjsunit/fixtures/b/c.js
  12. 2
      test/mjsunit/fixtures/b/d.js
  13. 2
      test/mjsunit/test-buffered-file.js
  14. 4
      test/mjsunit/test-exec.js
  15. 4
      test/mjsunit/test-file-cat-noexist.js
  16. 16
      test/mjsunit/test-http-proxy.js
  17. 8
      test/mjsunit/test-http.js
  18. 4
      test/mjsunit/test-module-loading.js
  19. 4
      test/mjsunit/test-multipart.js
  20. 20
      test/mjsunit/test-tcp-binary.js
  21. 4
      test/mjsunit/test-tcp-pingpong-delay.js
  22. 2
      test/mjsunit/test-tcp-throttle.js

107
doc/api.html

@ -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,124 +60,122 @@ 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>
<tt>node.exit(code)</tt>
</dt>
<dd>
<p>
Outputs the <tt>string</tt> and a trailing new-line to <tt>stdout</tt>.
Immediately ends the process with the specified code.
</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>
<tt>node.cwd()</tt>
</dt>
<dd>
<p>
A synchronous output function. Will block the process and
output the string immediately to stdout.
Returns the current working directory of the process.
</p>
</dd>
<dt class="hdlist1">
<tt>node.inspect(object)</tt>
<tt>ARGV</tt>
</dt>
<dd>
<p>
Return a string representation of the <tt>object</tt>. (For debugging.)
An array containing the command line arguments.
</p>
</dd>
<dt class="hdlist1">
<tt>print(string)</tt>
<tt>ENV</tt>
</dt>
<dd>
<p>
Like <tt>puts()</tt> but without the trailing new-line.
An object containing the user environment. See environ(7).
</p>
</dd>
<dt class="hdlist1">
<tt>node.exit(code)</tt>
<tt>__filename</tt>
</dt>
<dd>
<p>
Immediately ends the process with the specified code.
The filename of the script being executed.
</p>
</dd>
<dt class="hdlist1">
<tt>node.exec(command)</tt>
<tt>process</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
A special global object. The <tt>process</tt> object is like the <tt>window</tt> object of
browser-side javascript.
</p>
</li>
</ul></div>
</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>node.cwd()</tt>
<tt>puts(string)</tt>
</dt>
<dd>
<p>
Returns the current working directory of the process.
Outputs the <tt>string</tt> and a trailing new-line to <tt>stdout</tt>.
</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>
<tt>print(string)</tt>
</dt>
<dd>
<p>
An array containing the command line arguments.
Like <tt>puts()</tt> but without the trailing new-line.
</p>
</dd>
<dt class="hdlist1">
<tt>ENV</tt>
<tt>debug(string)</tt>
</dt>
<dd>
<p>
An object containing the user environment. See environ(7).
A synchronous output function. Will block the process and
output the string immediately to stdout.
</p>
</dd>
<dt class="hdlist1">
<tt>__filename</tt>
<tt>inspect(object)</tt>
</dt>
<dd>
<p>
The filename of the script being executed.
Return a string representation of the <tt>object</tt>. (For debugging.)
</p>
</dd>
<dt class="hdlist1">
<tt>process</tt>
<tt>exec(command)</tt>
</dt>
<dd>
<p>
A special global object. The <tt>process</tt> object is like the <tt>window</tt> object of
browser-side javascript.
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>
@ -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>

73
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

105
doc/api.xml

@ -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,145 +32,143 @@ 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>
<literal>node.exit(code)</literal>
</term>
<listitem>
<simpara>
Outputs the <literal>string</literal> and a trailing new-line to <literal>stdout</literal>.
Immediately ends the process with the specified code.
</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>
<literal>node.cwd()</literal>
</term>
<listitem>
<simpara>
A synchronous output function. Will block the process and
output the string immediately to stdout.
Returns the current working directory of the process.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>node.inspect(object)</literal>
<literal>ARGV</literal>
</term>
<listitem>
<simpara>
Return a string representation of the <literal>object</literal>. (For debugging.)
An array containing the command line arguments.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>print(string)</literal>
<literal>ENV</literal>
</term>
<listitem>
<simpara>
Like <literal>puts()</literal> but without the trailing new-line.
An object containing the user environment. See environ(7).
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>node.exit(code)</literal>
<literal>__filename</literal>
</term>
<listitem>
<simpara>
Immediately ends the process with the specified code.
The filename of the script being executed.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>node.exec(command)</literal>
<literal>process</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
A special global object. The <literal>process</literal> object is like the <literal>window</literal> object of
browser-side javascript.
</simpara>
</listitem>
</itemizedlist>
</listitem>
</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>node.cwd()</literal>
<literal>puts(string)</literal>
</term>
<listitem>
<simpara>
Returns the current working directory of the process.
Outputs the <literal>string</literal> and a trailing new-line to <literal>stdout</literal>.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</refsect2>
<refsect2 id="_global_variables">
<title>Global Variables</title>
<variablelist>
<varlistentry>
<term>
<literal>ARGV</literal>
<literal>print(string)</literal>
</term>
<listitem>
<simpara>
An array containing the command line arguments.
Like <literal>puts()</literal> but without the trailing new-line.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>ENV</literal>
<literal>debug(string)</literal>
</term>
<listitem>
<simpara>
An object containing the user environment. See environ(7).
A synchronous output function. Will block the process and
output the string immediately to stdout.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>__filename</literal>
<literal>inspect(object)</literal>
</term>
<listitem>
<simpara>
The filename of the script being executed.
Return a string representation of the <literal>object</literal>. (For debugging.)
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>process</literal>
<literal>exec(command)</literal>
</term>
<listitem>
<simpara>
A special global object. The <literal>process</literal> object is like the <literal>window</literal> object of
browser-side javascript.
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>

9
doc/index.html

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

128
doc/node.1

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

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

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

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

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

5
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";

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

2
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";

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

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save