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> World":</p></div>
<div class="listingblock"> <div class="listingblock">
<div class="content"> <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.sendHeader(200, {"Content-Type": "text/plain"});
response.sendBody("Hello World\n"); response.sendBody("Hello World\n");
response.finish(); 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> 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 <div class="paragraph"><p>Unless otherwise noted, functions are all asynchronous and do not block
execution.</p></div> 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> <div class="dlist"><dl>
<dt class="hdlist1"> <dt class="hdlist1">
<tt>puts(string)</tt> <tt>node.exit(code)</tt>
</dt> </dt>
<dd> <dd>
<p> <p>
Outputs the <tt>string</tt> and a trailing new-line to <tt>stdout</tt>. Immediately ends the process with the specified code.
</p> </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> </dd>
<dt class="hdlist1"> <dt class="hdlist1">
<tt>node.debug(string)</tt> <tt>node.cwd()</tt>
</dt> </dt>
<dd> <dd>
<p> <p>
A synchronous output function. Will block the process and Returns the current working directory of the process.
output the string immediately to stdout.
</p> </p>
</dd> </dd>
<dt class="hdlist1"> <dt class="hdlist1">
<tt>node.inspect(object)</tt> <tt>ARGV</tt>
</dt> </dt>
<dd> <dd>
<p> <p>
Return a string representation of the <tt>object</tt>. (For debugging.) An array containing the command line arguments.
</p> </p>
</dd> </dd>
<dt class="hdlist1"> <dt class="hdlist1">
<tt>print(string)</tt> <tt>ENV</tt>
</dt> </dt>
<dd> <dd>
<p> <p>
Like <tt>puts()</tt> but without the trailing new-line. An object containing the user environment. See environ(7).
</p> </p>
</dd> </dd>
<dt class="hdlist1"> <dt class="hdlist1">
<tt>node.exit(code)</tt> <tt>__filename</tt>
</dt> </dt>
<dd> <dd>
<p> <p>
Immediately ends the process with the specified code. The filename of the script being executed.
</p> </p>
</dd> </dd>
<dt class="hdlist1"> <dt class="hdlist1">
<tt>node.exec(command)</tt> <tt>process</tt>
</dt> </dt>
<dd> <dd>
<p> <p>
Executes the command as a child process, buffers the output and returns it A special global object. The <tt>process</tt> object is like the <tt>window</tt> object of
in a promise callback. browser-side javascript.
</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> </p>
</li>
</ul></div>
</dd> </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"> <dt class="hdlist1">
<tt>node.cwd()</tt> <tt>puts(string)</tt>
</dt> </dt>
<dd> <dd>
<p> <p>
Returns the current working directory of the process. Outputs the <tt>string</tt> and a trailing new-line to <tt>stdout</tt>.
</p> </p>
</dd> </dd>
</dl></div>
<h3 id="_global_variables">Global Variables</h3><div style="clear:left"></div>
<div class="dlist"><dl>
<dt class="hdlist1"> <dt class="hdlist1">
<tt>ARGV</tt> <tt>print(string)</tt>
</dt> </dt>
<dd> <dd>
<p> <p>
An array containing the command line arguments. Like <tt>puts()</tt> but without the trailing new-line.
</p> </p>
</dd> </dd>
<dt class="hdlist1"> <dt class="hdlist1">
<tt>ENV</tt> <tt>debug(string)</tt>
</dt> </dt>
<dd> <dd>
<p> <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> </p>
</dd> </dd>
<dt class="hdlist1"> <dt class="hdlist1">
<tt>__filename</tt> <tt>inspect(object)</tt>
</dt> </dt>
<dd> <dd>
<p> <p>
The filename of the script being executed. Return a string representation of the <tt>object</tt>. (For debugging.)
</p> </p>
</dd> </dd>
<dt class="hdlist1"> <dt class="hdlist1">
<tt>process</tt> <tt>exec(command)</tt>
</dt> </dt>
<dd> <dd>
<p> <p>
A special global object. The <tt>process</tt> object is like the <tt>window</tt> object of Executes the command as a child process, buffers the output and returns it
browser-side javascript. 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> </p>
</li>
</ul></div>
</dd> </dd>
</dl></div> </dl></div>
<h3 id="_events">Events</h3><div style="clear:left"></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">
<div id="footer-text"> <div id="footer-text">
Version 0.1.12<br /> 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>
</div> </div>
</body> </body>

73
doc/api.txt

@ -16,6 +16,7 @@ An example of a web server written with Node which responds with "Hello
World": World":
---------------------------------------- ----------------------------------------
include("/utils.js");
node.http.createServer(function (request, response) { node.http.createServer(function (request, response) {
response.sendHeader(200, {"Content-Type": "text/plain"}); response.sendHeader(200, {"Content-Type": "text/plain"});
response.sendBody("Hello World\n"); response.sendBody("Hello World\n");
@ -45,40 +46,55 @@ Unless otherwise noted, functions are all asynchronous and do not block
execution. execution.
=== Helpers === Helpers and Global Variables
+puts(string)+:: These objects are available to all programs.
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.exit(code)+::
Immediately ends the process with the specified code.
+node.debug(string)+:: +node.cwd()+::
A synchronous output function. Will block the process and Returns the current working directory of the process.
output the string immediately to stdout.
+ARGV+ ::
An array containing the command line arguments.
+node.inspect(object)+ :: +ENV+ ::
Return a string representation of the +object+. (For debugging.) 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)+:: +print(string)+::
Like +puts()+ but without the trailing new-line. 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)+:: +inspect(object)+ ::
Immediately ends the process with the specified code. 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 Executes the command as a child process, buffers the output and returns it
in a promise callback. in a promise callback.
+ +
---------------------------------------- ----------------------------------------
node.exec("ls /").addCallback(function (stdout, stderr) { include("/utils.js");
exec("ls /").addCallback(function (stdout, stderr) {
puts(stdout); puts(stdout);
}); });
---------------------------------------- ----------------------------------------
@ -87,27 +103,6 @@ node.exec("ls /").addCallback(function (stdout, stderr) {
- on error: exit code, 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.
+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 === Events

105
doc/api.xml

@ -12,7 +12,8 @@
<refsynopsisdiv id="_synopsis"> <refsynopsisdiv id="_synopsis">
<simpara>An example of a web server written with Node which responds with "Hello <simpara>An example of a web server written with Node which responds with "Hello
World":</simpara> 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.sendHeader(200, {"Content-Type": "text/plain"});
response.sendBody("Hello World\n"); response.sendBody("Hello World\n");
response.finish(); 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> 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 <simpara>Unless otherwise noted, functions are all asynchronous and do not block
execution.</simpara> execution.</simpara>
<refsect2 id="_helpers"> <refsect2 id="_helpers_and_global_variables">
<title>Helpers</title> <title>Helpers and Global Variables</title>
<simpara>These objects are available to all programs.</simpara>
<variablelist> <variablelist>
<varlistentry> <varlistentry>
<term> <term>
<literal>puts(string)</literal> <literal>node.exit(code)</literal>
</term> </term>
<listitem> <listitem>
<simpara> <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>
<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> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term> <term>
<literal>node.debug(string)</literal> <literal>node.cwd()</literal>
</term> </term>
<listitem> <listitem>
<simpara> <simpara>
A synchronous output function. Will block the process and Returns the current working directory of the process.
output the string immediately to stdout.
</simpara> </simpara>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term> <term>
<literal>node.inspect(object)</literal> <literal>ARGV</literal>
</term> </term>
<listitem> <listitem>
<simpara> <simpara>
Return a string representation of the <literal>object</literal>. (For debugging.) An array containing the command line arguments.
</simpara> </simpara>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term> <term>
<literal>print(string)</literal> <literal>ENV</literal>
</term> </term>
<listitem> <listitem>
<simpara> <simpara>
Like <literal>puts()</literal> but without the trailing new-line. An object containing the user environment. See environ(7).
</simpara> </simpara>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term> <term>
<literal>node.exit(code)</literal> <literal>__filename</literal>
</term> </term>
<listitem> <listitem>
<simpara> <simpara>
Immediately ends the process with the specified code. The filename of the script being executed.
</simpara> </simpara>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term> <term>
<literal>node.exec(command)</literal> <literal>process</literal>
</term> </term>
<listitem> <listitem>
<simpara> <simpara>
Executes the command as a child process, buffers the output and returns it A special global object. The <literal>process</literal> object is like the <literal>window</literal> object of
in a promise callback. browser-side javascript.
</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> </simpara>
</listitem> </listitem>
</itemizedlist>
</listitem>
</varlistentry> </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> <varlistentry>
<term> <term>
<literal>node.cwd()</literal> <literal>puts(string)</literal>
</term> </term>
<listitem> <listitem>
<simpara> <simpara>
Returns the current working directory of the process. Outputs the <literal>string</literal> and a trailing new-line to <literal>stdout</literal>.
</simpara> </simpara>
</listitem> </listitem>
</varlistentry> </varlistentry>
</variablelist>
</refsect2>
<refsect2 id="_global_variables">
<title>Global Variables</title>
<variablelist>
<varlistentry> <varlistentry>
<term> <term>
<literal>ARGV</literal> <literal>print(string)</literal>
</term> </term>
<listitem> <listitem>
<simpara> <simpara>
An array containing the command line arguments. Like <literal>puts()</literal> but without the trailing new-line.
</simpara> </simpara>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term> <term>
<literal>ENV</literal> <literal>debug(string)</literal>
</term> </term>
<listitem> <listitem>
<simpara> <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> </simpara>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term> <term>
<literal>__filename</literal> <literal>inspect(object)</literal>
</term> </term>
<listitem> <listitem>
<simpara> <simpara>
The filename of the script being executed. Return a string representation of the <literal>object</literal>. (For debugging.)
</simpara> </simpara>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term> <term>
<literal>process</literal> <literal>exec(command)</literal>
</term> </term>
<listitem> <listitem>
<simpara> <simpara>
A special global object. The <literal>process</literal> object is like the <literal>window</literal> object of Executes the command as a child process, buffers the output and returns it
browser-side javascript. in a promise callback.
</simpara> </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> </listitem>
</varlistentry> </varlistentry>
</variablelist> </variablelist>

9
doc/index.html

@ -41,14 +41,17 @@
</p> </p>
<pre> <pre>
node.http.createServer(function (req, res) { utils = require("/utils.js");
server = node.http.createServer(function (req, res) {
setTimeout(function () { setTimeout(function () {
res.sendHeader(200, {"Content-Type": "text/plain"}); res.sendHeader(200, {"Content-Type": "text/plain"});
res.sendBody("Hello World"); res.sendBody("Hello World");
res.finish(); res.finish();
}, 2000); }, 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> <p>
To run the server, put the code into a file To run the server, put the code into a file

128
doc/node.1

@ -1,11 +1,11 @@
.\" Title: node .\" Title: node
.\" Author: .\" Author:
.\" Generator: DocBook XSL Stylesheets v1.73.2 <http://docbook.sf.net/> .\" Generator: DocBook XSL Stylesheets v1.73.2 <http://docbook.sf.net/>
.\" Date: 09/27/2009 .\" Date: 09/28/2009
.\" Manual: .\" Manual:
.\" Source: .\" Source:
.\" .\"
.TH "NODE" "1" "09/27/2009" "" "" .TH "NODE" "1" "09/28/2009" "" ""
.\" disable hyphenation .\" disable hyphenation
.nh .nh
.\" disable justification (adjust text to left margin only) .\" 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 .sp
.RS 4 .RS 4
.nf .nf
include("/utils\.js");
node\.http\.createServer(function (request, response) { node\.http\.createServer(function (request, response) {
response\.sendHeader(200, {"Content\-Type": "text/plain"}); response\.sendHeader(200, {"Content\-Type": "text/plain"});
response\.sendBody("Hello World\en"); response\.sendBody("Hello World\en");
@ -40,35 +41,51 @@ Node supports 3 string encodings\. UTF\-8 ("utf8"), ASCII ("ascii"), and Binary
.sp .sp
Unless otherwise noted, functions are all asynchronous and do not block execution\. Unless otherwise noted, functions are all asynchronous and do not block execution\.
.sp .sp
.SS "Helpers" .SS "Helpers and Global Variables"
These objects are available to all programs\.
.PP .PP
puts(string) node\.exit(code)
.RS 4 .RS 4
Outputs the Immediately ends the process with the specified code\.
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 .RE
.PP .PP
node\.debug(string) node\.cwd()
.RS 4 .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 .RE
.PP .PP
node\.inspect(object) ARGV
.RS 4 .RS 4
Return a string representation of the An array containing the command line arguments\.
object\. (For debugging\.) .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 .RE
.PP .PP
print(string) print(string)
@ -78,18 +95,25 @@ puts()
but without the trailing new\-line\. but without the trailing new\-line\.
.RE .RE
.PP .PP
node\.exit(code) debug(string)
.RS 4 .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 .RE
.PP .PP
node\.exec(command) exec(command)
.RS 4 .RS 4
Executes the command as a child process, buffers the output and returns it in a promise callback\. Executes the command as a child process, buffers the output and returns it in a promise callback\.
.sp .sp
.RS 4 .RS 4
.nf .nf
node\.exec("ls /")\.addCallback(function (stdout, stderr) { include("/utils\.js");
exec("ls /")\.addCallback(function (stdout, stderr) {
puts(stdout); puts(stdout);
}); });
.fi .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 \h'-04'\(bu\h'+03'on error: exit code, stdout buffer, stderr buffer
.RE .RE
.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" .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\. 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 .sp
@ -153,7 +147,7 @@ All EventEmitters emit the event "newListener" when new listeners are added\.
.sp .sp
.TS .TS
allbox tab(:); allbox tab(:);
ltB ltB ltB. ltB ltB ltBx.
T{ T{
Event Event
T}:T{ T}:T{
@ -209,7 +203,7 @@ node\.Promise inherits from node\.eventEmitter\. A promise emits one of two even
.sp .sp
.TS .TS
allbox tab(:); allbox tab(:);
ltB ltB ltB. ltB ltB ltBx.
T{ T{
Event Event
T}:T{ T}:T{
@ -308,7 +302,7 @@ Standard I/O is handled through a special object node\.stdio\. stdout and stdin
.sp .sp
.TS .TS
allbox tab(:); allbox tab(:);
ltB ltB ltB. ltB ltB ltBx.
T{ T{
Event Event
T}:T{ T}:T{
@ -494,7 +488,7 @@ node.ChildProcess
.RS .RS
.TS .TS
allbox tab(:); allbox tab(:);
ltB ltB ltB. ltB ltB ltBx.
T{ T{
Event Event
T}:T{ T}:T{
@ -850,7 +844,7 @@ node.http.Server
.RS .RS
.TS .TS
allbox tab(:); allbox tab(:);
ltB ltB ltB. ltB ltB ltBx.
T{ T{
Event Event
T}:T{ T}:T{
@ -934,7 +928,7 @@ This object is created internally by a HTTP server\(emnot by the user\(emand pas
.sp .sp
.TS .TS
allbox tab(:); allbox tab(:);
ltB ltB ltB. ltB ltB ltBx.
T{ T{
Event Event
T}:T{ T}:T{
@ -1191,7 +1185,7 @@ This object is created internally and returned from the request methods of a nod
.sp .sp
.TS .TS
allbox tab(:); allbox tab(:);
ltB ltB ltB. ltB ltB ltBx.
T{ T{
Event Event
T}:T{ T}:T{
@ -1289,7 +1283,7 @@ This object is created internally and passed to the "response" event\.
.sp .sp
.TS .TS
allbox tab(:); allbox tab(:);
ltB ltB ltB. ltB ltB ltBx.
T{ T{
Event Event
T}:T{ T}:T{
@ -1398,7 +1392,7 @@ server\.listen(7000, "localhost");
.RE .RE
.TS .TS
allbox tab(:); allbox tab(:);
ltB ltB ltB. ltB ltB ltBx.
T{ T{
Event Event
T}:T{ T}:T{
@ -1480,7 +1474,7 @@ This object is used as a TCP client and also as a server\-side socket for node\.
.sp .sp
.TS .TS
allbox tab(:); allbox tab(:);
ltB ltB ltB. ltB ltB ltBx.
T{ T{
Event Event
T}:T{ 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 // A repl library that you can include in your own code to get a runtime
// interface to your program. Just require("/repl.js"). // interface to your program. Just require("/repl.js").
var utils = require("utils.js");
puts("Type '.help' for options."); puts("Type '.help' for options.");
node.stdio.open(); node.stdio.open();
@ -42,7 +44,7 @@ function readline (cmd) {
with (exports.scope) { with (exports.scope) {
var ret = eval(buffered_cmd); var ret = eval(buffered_cmd);
exports.scope['_'] = ret; exports.scope['_'] = ret;
puts(node.inspect(ret)); utils.p(ret);
} }
buffered_cmd = ''; buffered_cmd = '';

28
src/node.js

@ -15,30 +15,9 @@ node.createChildProcess = function (command) {
return child; return child;
}; };
node.exec = function (command) { node.exec = function () {
var child = node.createChildProcess(command); throw new Error("node.exec() has moved. Use include('/utils.js') to bring it back.");
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.tcp.createConnection = function (port, host) { node.tcp.createConnection = function (port, host) {
var connection = new node.tcp.Connection(); var connection = new node.tcp.Connection();
@ -220,7 +199,6 @@ node.Module.prototype.loadObject = function (loadPromise) {
node.dlopen(self.filename, self.target); // FIXME synchronus node.dlopen(self.filename, self.target); // FIXME synchronus
loadPromise.emitSuccess(self.target); loadPromise.emitSuccess(self.target);
} else { } else {
node.error("Error reading " + self.filename + "\n");
loadPromise.emitError(new Error("Error reading " + self.filename)); loadPromise.emitError(new Error("Error reading " + self.filename));
node.exit(1); 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) { puts = function () {
print(x.toString() + "\n"); throw new Error("puts() has moved. Use include('/utils.js') to bring it back.");
}; }
node.debug = function (x) { print = function () {
node.stdio.writeError("DEBUG: " + x.toString() + "\n"); throw new Error("print() has moved. Use include('/utils.js') to bring it back.");
}; }
node.error = function (x) { p = function () {
node.stdio.writeError(x.toString() + "\n"); throw new Error("p() has moved. Use include('/utils.js') to bring it back.");
}; }
/** node.debug = function () {
* Echos the value of a value. Trys to print the value out throw new Error("node.debug() has moved. Use include('/utils.js') to bring it back.");
* 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;
}
}
};
p = function (x) { node.error = function () {
node.error(node.inspect(x)); 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); node.libraryPaths.unshift(exports.libDir);
var mjsunit = require("/mjsunit.js"); var mjsunit = require("/mjsunit.js");
include("/utils.js");
// Copy mjsunit namespace out // Copy mjsunit namespace out
for (var prop in mjsunit) { for (var prop in mjsunit) {
if (mjsunit.hasOwnProperty(prop)) exports[prop] = mjsunit[prop]; 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"); var c = require("b/c.js");
debug("load fixtures/a.js");
var string = "A"; 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"); var d = require("d.js");
debug("load fixtures/b/c.js");
var string = "C"; var string = "C";
exports.C = function () { 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"; var string = "D";

2
test/mjsunit/test-buffered-file.js

@ -15,7 +15,7 @@ setTimeout(function () {
file.write("hello\n"); file.write("hello\n");
file.write("world\n"); file.write("world\n");
file.close().addCallback(function () { file.close().addCallback(function () {
node.error("file closed..."); error("file closed...");
var out = node.fs.cat(testTxt).wait(); var out = node.fs.cat(testTxt).wait();
print("the file contains: "); print("the file contains: ");
p(out); p(out);

4
test/mjsunit/test-exec.js

@ -3,7 +3,7 @@ include("common.js");
success_count = 0; success_count = 0;
error_count = 0; error_count = 0;
node.exec("ls /").addCallback(function (out) { exec("ls /").addCallback(function (out) {
success_count++; success_count++;
p(out); p(out);
}).addErrback(function (code, out, err) { }).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++; success_count++;
p(out); p(out);
assertTrue(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"); var promise = node.fs.cat(filename, "raw");
promise.addCallback(function (content) { promise.addCallback(function (content) {
node.debug("cat returned some content: " + content); debug("cat returned some content: " + content);
node.debug("this shouldn't happen as the file doesn't exist..."); debug("this shouldn't happen as the file doesn't exist...");
assertTrue(false); assertTrue(false);
}); });

16
test/mjsunit/test-http-proxy.js

@ -4,17 +4,17 @@ var PROXY_PORT = 8869;
var BACKEND_PORT = 8870; var BACKEND_PORT = 8870;
var backend = node.http.createServer(function (req, res) { var backend = node.http.createServer(function (req, res) {
// node.debug("backend"); // debug("backend");
res.sendHeader(200, {"content-type": "text/plain"}); res.sendHeader(200, {"content-type": "text/plain"});
res.sendBody("hello world\n"); res.sendBody("hello world\n");
res.finish(); res.finish();
}); });
// node.debug("listen backend") // debug("listen backend")
backend.listen(BACKEND_PORT); backend.listen(BACKEND_PORT);
var proxy_client = node.http.createClient(BACKEND_PORT); var proxy_client = node.http.createClient(BACKEND_PORT);
var proxy = node.http.createServer(function (req, res) { 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); var proxy_req = proxy_client.get(req.uri.path);
proxy_req.finish(function(proxy_res) { proxy_req.finish(function(proxy_res) {
res.sendHeader(proxy_res.statusCode, proxy_res.headers); 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() { proxy_res.addListener("complete", function() {
res.finish(); res.finish();
// node.debug("proxy res"); // debug("proxy res");
}); });
}); });
}); });
// node.debug("listen proxy") // debug("listen proxy")
proxy.listen(PROXY_PORT); proxy.listen(PROXY_PORT);
var body = ""; var body = "";
var client = node.http.createClient(PROXY_PORT); var client = node.http.createClient(PROXY_PORT);
var req = client.get("/test"); var req = client.get("/test");
// node.debug("client req") // debug("client req")
req.finish(function (res) { req.finish(function (res) {
// node.debug("got res"); // debug("got res");
assertEquals(200, res.statusCode); assertEquals(200, res.statusCode);
res.setBodyEncoding("utf8"); res.setBodyEncoding("utf8");
res.addListener("body", function (chunk) { body += chunk; }); res.addListener("body", function (chunk) { body += chunk; });
res.addListener("complete", function () { res.addListener("complete", function () {
proxy.close(); proxy.close();
backend.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; responses_recvd += 1;
res.setBodyEncoding("ascii"); res.setBodyEncoding("ascii");
res.addListener("body", function (chunk) { body0 += chunk; }); res.addListener("body", function (chunk) { body0 += chunk; });
node.debug("Got /hello response"); debug("Got /hello response");
}); });
setTimeout(function () { setTimeout(function () {
@ -52,15 +52,15 @@ setTimeout(function () {
responses_recvd += 1; responses_recvd += 1;
res.setBodyEncoding("utf8"); res.setBodyEncoding("utf8");
res.addListener("body", function (chunk) { body1 += chunk; }); res.addListener("body", function (chunk) { body1 += chunk; });
node.debug("Got /world response"); debug("Got /world response");
}); });
}, 1); }, 1);
process.addListener("exit", function () { process.addListener("exit", function () {
node.debug("responses_recvd: " + responses_recvd); debug("responses_recvd: " + responses_recvd);
assertEquals(2, responses_recvd); assertEquals(2, responses_recvd);
node.debug("responses_sent: " + responses_sent); debug("responses_sent: " + responses_sent);
assertEquals(2, responses_sent); assertEquals(2, responses_sent);
assertEquals("The path was /hello", body0); 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"); include("common.js");
debug("load test-module-loading.js");
var a = require("fixtures/a.js"); var a = require("fixtures/a.js");
var d = require("fixtures/b/d.js"); var d = require("fixtures/b/d.js");
var d2 = 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); server.listen(port);
var cmd = 'curl -H "Expect:" -F "test-field=foobar" -F test-file=@'+__filename+' http://localhost:'+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() { process.addListener('exit', function() {
assertEquals(2, parts_complete); assertEquals(2, parts_complete);
}); });

20
test/mjsunit/test-tcp-binary.js

@ -5,14 +5,14 @@ binaryString = "";
for (var i = 255; i >= 0; i--) { for (var i = 255; i >= 0; i--) {
var s = "'\\" + i.toString(8) + "'"; var s = "'\\" + i.toString(8) + "'";
S = eval(s); S = eval(s);
node.error( s error( s
+ " " + " "
+ JSON.stringify(S) + JSON.stringify(S)
+ " " + " "
+ JSON.stringify(String.fromCharCode(i)) + JSON.stringify(String.fromCharCode(i))
+ " " + " "
+ S.charCodeAt(0) + S.charCodeAt(0)
); );
node.assert(S.charCodeAt(0) == i); node.assert(S.charCodeAt(0) == i);
node.assert(S == String.fromCharCode(i)); node.assert(S == String.fromCharCode(i));
binaryString += S; binaryString += S;
@ -21,7 +21,7 @@ for (var i = 255; i >= 0; i--) {
var echoServer = node.tcp.createServer(function (connection) { var echoServer = node.tcp.createServer(function (connection) {
connection.setEncoding("binary"); connection.setEncoding("binary");
connection.addListener("receive", function (chunk) { connection.addListener("receive", function (chunk) {
node.error("recved: " + JSON.stringify(chunk)); error("recved: " + JSON.stringify(chunk));
connection.send(chunk, "binary"); connection.send(chunk, "binary");
}); });
connection.addListener("eof", function () { connection.addListener("eof", function () {
@ -38,7 +38,7 @@ var c = node.tcp.createConnection(PORT);
c.setEncoding("binary"); c.setEncoding("binary");
c.addListener("receive", function (chunk) { c.addListener("receive", function (chunk) {
if (j < 256) { if (j < 256) {
node.error("send " + j); error("send " + j);
c.send(String.fromCharCode(j), "binary"); c.send(String.fromCharCode(j), "binary");
j++; j++;
} else { } else {

4
test/mjsunit/test-tcp-pingpong-delay.js

@ -24,7 +24,7 @@ function pingPongTest (port, host, on_complete) {
}); });
socket.addListener("timeout", function () { socket.addListener("timeout", function () {
node.debug("server-side timeout!!"); debug("server-side timeout!!");
assertFalse(true); assertFalse(true);
}); });
@ -70,7 +70,7 @@ function pingPongTest (port, host, on_complete) {
}); });
client.addListener("timeout", function () { client.addListener("timeout", function () {
node.debug("client-side timeout!!"); debug("client-side timeout!!");
assertFalse(true); assertFalse(true);
}); });

2
test/mjsunit/test-tcp-throttle.js

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

Loading…
Cancel
Save