From 3eb4819db1e3cc1d41c369e7f4e96771ef6f6ed3 Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 25 May 2009 13:38:36 +0200 Subject: [PATCH] Add docs. Rename exit() to node.exit(). --- src/node.cc | 4 ++-- src/node.js | 4 ++-- website/node.html | 25 ++++++++++++++++++++++--- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/node.cc b/src/node.cc index ba422a6..f189ea3 100644 --- a/src/node.cc +++ b/src/node.cc @@ -275,9 +275,9 @@ main (int argc, char *argv[]) Local 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 arguments = Array::New(argc); for (int i = 0; i < argc; i++) { diff --git a/src/node.js b/src/node.js index f52c6c7..e3d9d16 100644 --- a/src/node.js +++ b/src/node.js @@ -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); diff --git a/website/node.html b/website/node.html index 213d8d1..e64b593 100644 --- a/website/node.html +++ b/website/node.html @@ -185,6 +185,9 @@ always have a capital first letter.
node.debug(string)
A synchronous output function. Will block the process and output the string immediately to stdout. Use with care.
+ +
node.exit(code)
+
Immediately ends the process with the specified code.

Timers

@@ -242,6 +245,23 @@ completion callbacks:
new node.fs.File
Creates a new file object.
+
file.onError
+
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. + +

Example

+
+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+")
+
+
file.open(path, mode, on_completion)
Opens the file at path.

mode is a string: @@ -607,7 +627,7 @@ function fail (expected, found, name_opt) { function deepEquals (a, b) { // ... } -exports.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 can be set and will notify the user when all the included modules are loaded. Each file/module can have an onLoad callback. -

To export an object, add to the special exports object. +

To export an object, add to the special exports object.

The functions fail and deepEquals are not exported and remain private to the module. -- 2.7.4