Add docs. Rename exit() to node.exit().
authorRyan <ry@tinyclouds.org>
Mon, 25 May 2009 11:38:36 +0000 (13:38 +0200)
committerRyan <ry@tinyclouds.org>
Mon, 25 May 2009 11:38:36 +0000 (13:38 +0200)
src/node.cc
src/node.js
website/node.html

index ba422a6..f189ea3 100644 (file)
@@ -275,9 +275,9 @@ main (int argc, char *argv[])
   Local<Object> node = Object::New();
   g->Set(String::New("node"), node);
 
-  NODE_SET_METHOD(node, "compile", compile);
+  NODE_SET_METHOD(node, "compile", compile); // internal 
   NODE_SET_METHOD(node, "debug", debug);
-  NODE_SET_METHOD(g, "exit", node_exit);
+  NODE_SET_METHOD(node, "exit", node_exit);
 
   Local<Array> arguments = Array::New(argc);
   for (int i = 0; i < argc; i++) {
index f52c6c7..e3d9d16 100644 (file)
@@ -79,7 +79,7 @@ clearInterval = clearTimeout;
       findScript(base_directory, name, function (filename) {
         if (filename === null) {
           stderr.puts("Cannot find a script matching: " + name);
-          exit(1);
+          node.exit(1);
         }
         loadScript(filename, target, callback);
       });
@@ -137,7 +137,7 @@ clearInterval = clearTimeout;
     node.fs.cat(filename, "utf8", function (status, content) {
       if (status != 0) {
         stderr.puts("Error reading " + filename + ": " + node.fs.strerror(status));
-        exit(1);
+        node.exit(1);
       }
       
       var scaffold = new Scaffold(content, filename, target);
index 213d8d1..e64b593 100644 (file)
@@ -185,6 +185,9 @@ always have a capital first letter.
   <dt><code class="sh_javascript">node.debug(string)</code></dt>
   <dd>A synchronous output function. Will <i>block</i> the process and output the
       string immediately to stdout. Use with care.</dd>
+
+  <dt><code class="sh_javascript">node.exit(code)</code></dt>
+  <dd>Immediately ends the process with the specified code.</dd>
 </dl>
 
 <h3 id="timers">Timers</h3>
@@ -242,6 +245,23 @@ completion callbacks:
   <dt><code class="sh_javascript">new node.fs.File</code></dt>
   <dd>Creates a new file object. </dd>
 
+  <dt><code class="sh_javascript">file.onError</code></dt>
+  <dd>Callback. This is called internally anytime an error occurs with this
+  file. There are three arguments: the method name, the POSIX errno, and a
+  string describing the error.
+
+  <p>Example</p>
+<pre class="sh_javascript">
+var path = "/some/path/that/doesnt/exist";
+var file = new node.fs.File();
+file.onError = function (method, errno, msg) {
+  stderr.puts("An error occurred calling " + method + " on " + path);
+  stderr.puts(msg);
+  exit(1);
+}
+file.open(path, "w+")
+</pre>
+
   <dt><code class="sh_javascript">file.open(path, mode, on_completion)</code></dt>
   <dd>Opens the file at <code>path</code>. 
   <p><code>mode</code> is a string: 
@@ -607,7 +627,7 @@ function fail (expected, found, name_opt) {
 function deepEquals (a, b) {
   // ...
 }
-<span class="highlight">exports</span>.assertEquals = function (expected, found, name_opt) {
+exports.assertEquals = function (expected, found, name_opt) {
   if (!deepEquals(found, expected)) {
     fail(expected, found, name_opt);
   }
@@ -629,8 +649,7 @@ class="sh_javascript">onLoad</code> can be set and will notify the user
 when all the included modules are loaded.  Each file/module can have an <code
 class="sh_javascript">onLoad</code> callback.  
 
-<p> To export an object, add to the special <code
-  class="highlight">exports</code> object.
+<p>To export an object, add to the special <code>exports</code> object.
 
 <p> The functions <code class="sh_javascript">fail</code> and <code class="sh_javascript">deepEquals</code> are not
 exported and remain private to the module.