Skip to content

Commit ad0a4ce

Browse files
committed
Namespace EVERYTHING under process; introduce GLOBAL
http://groups.google.com/group/nodejs/browse_thread/thread/1034fd2ad2cd93e8
1 parent 6959a1d commit ad0a4ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+339
-343
lines changed

benchmark/http_simple.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
libDir = node.path.join(node.path.dirname(__filename), "../lib");
1+
libDir = process.path.join(process.path.dirname(__filename), "../lib");
22
require.paths.unshift(libDir);
33

4-
node.mixin(require("/utils.js"));
4+
process.mixin(require("/utils.js"));
55
http = require("/http.js");
66

77
fixed = ""

benchmark/process_loop.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
libDir = node.path.join(node.path.dirname(__filename), "../lib");
1+
libDir = process.path.join(process.path.dirname(__filename), "../lib");
22
require.paths.unshift(libDir);
3-
node.mixin(require("/utils.js"));
3+
process.mixin(require("/utils.js"));
44
function next (i) {
55
if (i <= 0) return;
66

7-
var child = node.createChildProcess("echo", ["hello"]);
7+
var child = process.createChildProcess("echo", ["hello"]);
88

99
child.addListener("output", function (chunk) {
1010
if (chunk) print(chunk);

benchmark/run.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
libDir = node.path.join(node.path.dirname(__filename), "../lib");
1+
libDir = process.path.join(process.path.dirname(__filename), "../lib");
22
require.paths.unshift(libDir);
3-
node.mixin(require("/utils.js"));
3+
process.mixin(require("/utils.js"));
44
var benchmarks = [ "static_http_server.js"
55
, "timers.js"
66
, "process_loop.js"
77
];
88

9-
var benchmark_dir = node.path.dirname(__filename);
9+
var benchmark_dir = process.path.dirname(__filename);
1010

1111
function exec (script, callback) {
1212
var start = new Date();
13-
var child = node.createChildProcess(ARGV[0], [node.path.join(benchmark_dir, script)]);
13+
var child = process.createChildProcess(process.ARGV[0], [process.path.join(benchmark_dir, script)]);
1414
child.addListener("exit", function (code) {
1515
var elapsed = new Date() - start;
1616
callback(elapsed, code);

benchmark/static_http_server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
libDir = node.path.join(node.path.dirname(__filename), "../lib");
1+
libDir = process.path.join(process.path.dirname(__filename), "../lib");
22
require.paths.unshift(libDir);
33
http = require("/http.js");
44
var concurrency = 30;

doc/api.txt

Lines changed: 62 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -46,53 +46,35 @@ Unless otherwise noted, functions are all asynchronous and do not block
4646
execution.
4747

4848

49-
=== Helpers
49+
=== Global Objects
5050

51-
These objects are available to all programs.
51+
+GLOBAL+ ::
52+
The global namespace object.
5253

53-
+node.cwd()+::
54-
Returns the current working directory of the process.
54+
+process+ ::
55+
The process object. Most stuff lives in here. See the "process object"
56+
section.
5557

56-
+node.kill(pid, signal="SIGTERM")+ ::
57-
Send a signal to a process. +pid+ is the process id and +signal+ is the
58-
signal to send; for example, "SIGINT" or "SIGUSR1". See kill(2) for more
59-
information.
58+
+require(path)+ ::
59+
See the modules section.
6060

61-
+node.compile(source, scriptOrigin)+::
62-
Just like +eval()+ except that you can specify a +scriptOrigin+ for better
63-
error reporting.
61+
+require.paths+ ::
62+
The search path for absolute path arguments to +require()+.
6463

6564
+__filename+ ::
6665
The filename of the script being executed.
6766

6867
+__module+ ::
69-
A reference to the current module (of type +node.Module+). In particular
70-
+__module.exports+ is the same as the +exports+ object. See +src/node.js+ for
68+
A reference to the current module (of type +process.Module+). In particular
69+
+__module.exports+ is the same as the +exports+ object. See +src/process.js+ for
7170
more information.
7271

73-
+require(path)+ ::
74-
See the modules section.
75-
76-
+require.paths+ ::
77-
The search path for absolute path arguments to +require()+.
7872

79-
+node.mixin([deep], target, object1, [objectN])+ ::
80-
Extend one object with one or more others, returning the modified object.
81-
If no target is specified, the +process+ namespace itself is extended.
82-
Keep in mind that the target object will be modified, and will be returned
83-
from +node.mixin()+.
84-
+
85-
If a boolean true is specified as the first argument, Node performs a deep
86-
copy, recursively copying any objects it finds. Otherwise, the copy will
87-
share structure with the original object(s).
88-
+
89-
Undefined properties are not copied. However, properties inherited from the
90-
object's prototype will be copied over.
9173

9274
=== The +process+ Object
9375

9476
+process+ is the equivalent of +window+ in browser-side javascript. It is
95-
the global scope. +process+ is an instance of +node.EventEmitter+.
77+
the global scope. +process+ is an instance of +process.EventEmitter+.
9678

9779
[cols="1,2,10",options="header"]
9880
|=========================================================
@@ -111,10 +93,6 @@ the global scope. +process+ is an instance of +node.EventEmitter+.
11193
signal names such as SIGINT, SIGUSR1, etc.
11294
|=========================================================
11395

114-
+process.exit(code=0)+::
115-
Ends the process with the specified code. By default it exits with the
116-
success code 0.
117-
11896
+process.ARGV+ ::
11997
An array containing the command line arguments.
12098

@@ -124,6 +102,35 @@ An object containing the user environment. See environ(7).
124102
+process.pid+ ::
125103
The PID of the process.
126104

105+
+process.exit(code=0)+::
106+
Ends the process with the specified code. By default it exits with the
107+
success code 0.
108+
109+
+process.cwd()+::
110+
Returns the current working directory of the process.
111+
112+
+process.kill(pid, signal="SIGTERM")+ ::
113+
Send a signal to a process. +pid+ is the process id and +signal+ is the
114+
signal to send; for example, "SIGINT" or "SIGUSR1". See kill(2) for more
115+
information.
116+
117+
+process.compile(source, scriptOrigin)+::
118+
Just like +eval()+ except that you can specify a +scriptOrigin+ for better
119+
error reporting.
120+
121+
+process.mixin([deep], target, object1, [objectN])+ ::
122+
Extend one object with one or more others, returning the modified object.
123+
If no target is specified, the +GLOBAL+ namespace itself is extended.
124+
Keep in mind that the target object will be modified, and will be returned
125+
from +process.mixin()+.
126+
+
127+
If a boolean true is specified as the first argument, Node performs a deep
128+
copy, recursively copying any objects it finds. Otherwise, the copy will
129+
share structure with the original object(s).
130+
+
131+
Undefined properties are not copied. However, properties inherited from the
132+
object's prototype will be copied over.
133+
127134
=== System module
128135

129136
These function are in +"/sys.js"+. Use +require("/sys.js")+ to access them.
@@ -161,7 +168,7 @@ sys.exec("ls /").addCallback(function (stdout, stderr) {
161168

162169
Many objects in Node emit events: a TCP server emits an event each time
163170
there is a connection, a child process emits an event when it exits. All
164-
objects which emit events are are instances of +node.EventEmitter+.
171+
objects which emit events are are instances of +process.EventEmitter+.
165172

166173
Events are represented by a camel-cased string. Here are some examples:
167174
+"connection"+, +"receive"+, +"messageBegin"+.
@@ -173,7 +180,7 @@ Some asynchronous file operations return an +EventEmitter+ called a
173180
_promise_. A promise emits just a single event when the operation is
174181
complete.
175182

176-
==== +node.EventEmitter+
183+
==== +process.EventEmitter+
177184

178185
All EventEmitters emit the event +"newListener"+ when new listeners are
179186
added.
@@ -204,9 +211,9 @@ manipulated, e.g. to remove listeners.
204211
+emitter.emit(event, arg1, arg2, ...)+ ::
205212
Execute each of the listeners in order with the supplied arguments.
206213

207-
==== +node.Promise+
214+
==== +process.Promise+
208215

209-
+node.Promise+ inherits from +node.eventEmitter+. A promise emits one of two
216+
+process.Promise+ inherits from +process.eventEmitter+. A promise emits one of two
210217
events: +"success"+ or +"error"+. After emitting its event, it will not
211218
emit anymore events.
212219

@@ -228,7 +235,7 @@ Adds a listener for the +"error"+ event. Returns the same promise object.
228235
Adds a listener for the +"cancel"+ event. Returns the same promise object.
229236

230237
+promise.emitSuccess(arg1, arg2, ...)+ ::
231-
If you created the promise (by doing +new node.Promise()+) then call
238+
If you created the promise (by doing +new process.Promise()+) then call
232239
+emitSuccess+ to emit the +"success"+ event with the given arguments.
233240
+
234241
(+promise.emit("success", arg1, arg2, ...)+ should also work, but doesn't at
@@ -292,7 +299,7 @@ program setup, not during busy server activity.
292299

293300
=== Standard I/O
294301

295-
Standard I/O is handled through a special object +node.stdio+. stdout and
302+
Standard I/O is handled through a special object +process.stdio+. stdout and
296303
stdin are fully non-blocking (even when piping to files). stderr is
297304
synchronous.
298305

@@ -303,22 +310,22 @@ synchronous.
303310
| +"data"+ | +data+ | Made when stdin has received a chunk of data.
304311
Depending on the encoding that stdin was opened
305312
with, +data+ will be a string. This event will
306-
only be emited after +node.stdio.open()+ has
313+
only be emited after +process.stdio.open()+ has
307314
been called.
308315
| +"close"+ | | Made when stdin has been closed.
309316
|=========================================================
310317

311-
+node.stdio.open(encoding="utf8")+::
312-
Open stdin. The program will not exit until +node.stdio.close()+ has been
318+
+process.stdio.open(encoding="utf8")+::
319+
Open stdin. The program will not exit until +process.stdio.close()+ has been
313320
called or the +"close"+ event has been emitted.
314321

315-
+node.stdio.write(data)+::
322+
+process.stdio.write(data)+::
316323
Write data to stdout.
317324

318-
+node.stdio.writeError(data)+::
325+
+process.stdio.writeError(data)+::
319326
Write data to stderr. Synchronous.
320327

321-
+node.stdio.close()+::
328+
+process.stdio.close()+::
322329
Close stdin.
323330

324331

@@ -361,10 +368,10 @@ The module path is relative to the file calling +require()+. That is,
361368
+circle.js+ must be in the same directory as +foo.js+ for +require()+ to
362369
find it.
363370

364-
Use +node.mixin()+ to include modules into the global namespace.
371+
Use +process.mixin()+ to include modules into the global namespace.
365372

366373
----------------------------------------
367-
node.mixin(process, require("circle.js"), require("/sys.js"));
374+
process.mixin(process, require("circle.js"), require("/sys.js"));
368375
puts("The area of a cirlce of radius 4 is " + area(4));
369376
----------------------------------------
370377

@@ -418,10 +425,10 @@ Stops a interval from triggering.
418425
=== Child Processes
419426

420427
Node provides a tridirectional +popen(3)+ facility through the class
421-
+node.ChildProcess+. It is possible to stream data through the child's +stdin+,
428+
+process.ChildProcess+. It is possible to stream data through the child's +stdin+,
422429
+stdout+, and +stderr+ in a fully non-blocking way.
423430

424-
==== +node.ChildProcess+
431+
==== +process.ChildProcess+
425432

426433
[cols="1,2,10",options="header"]
427434
|=========================================================
@@ -444,12 +451,12 @@ Node provides a tridirectional +popen(3)+ facility through the class
444451
+"error"+ callbacks will no longer be made.
445452
|=========================================================
446453

447-
+node.createChildProcess(command, args=[], env=ENV)+::
454+
+process.createChildProcess(command, args=[], env=ENV)+::
448455
Launches a new process with the given +command+, command line arguments, and
449456
environmental variables. For example:
450457
+
451458
----------------------------------------
452-
var ls = node.createChildProcess("ls", ["-lh", "/usr"]);
459+
var ls = process.createChildProcess("ls", ["-lh", "/usr"]);
453460
ls.addListener("output", function (data) {
454461
puts(data);
455462
});
@@ -485,7 +492,7 @@ File I/O is provided by simple wrappers around standard POSIX functions. To
485492
use this module do +require("/posix.js")+.
486493

487494
All POSIX wrappers have a similar form. They return a promise
488-
(+node.Promise+). Example of deleting a file:
495+
(+process.Promise+). Example of deleting a file:
489496

490497
------------------------------------------------------------------------------
491498
var posix = require("/posix.js"),
@@ -574,7 +581,7 @@ sys.puts("stats: " + JSON.stringify(stats));
574581

575582

576583
+posix.open(path, flags, mode)+::
577-
See open(2). The constants like +O_CREAT+ are defined at +node.O_CREAT+.
584+
See open(2). The constants like +O_CREAT+ are defined at +process.O_CREAT+.
578585
- on success: +fd+ is given as the parameter.
579586
- on error: no parameters.
580587

lib/file.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@ exports.debugLevel = 0; // Increase to get more verbose debug output
66

77
function debugMessage (msg) {
88
if (exports.debugLevel > 0) {
9-
node.error(__filename + ": " + msg.toString());
9+
process.error(__filename + ": " + msg.toString());
1010
}
1111
}
1212

1313
function debugObject (obj) {
1414
if (exports.debugLevel > 0) {
15-
node.error(__filename + ": " + JSON.stringify(obj));
15+
process.error(__filename + ": " + JSON.stringify(obj));
1616
}
1717
}
1818

1919
exports.read = posix.cat;
2020

2121
exports.write = function (filename, data, encoding) {
22-
var promise = new node.Promise();
22+
var promise = new process.Promise();
2323

2424
encoding = encoding || "utf8"; // default to utf8
2525

26-
posix.open(filename, node.O_WRONLY | node.O_TRUNC | node.O_CREAT, 0666)
26+
posix.open(filename, process.O_WRONLY | process.O_TRUNC | process.O_CREAT, 0666)
2727
.addCallback(function (fd) {
2828
function doWrite (_data) {
2929
posix.write(fd, _data, 0, encoding)
@@ -60,27 +60,27 @@ exports.File = function (filename, mode, options) {
6060

6161
switch (mode) {
6262
case "r":
63-
self.flags = node.O_RDONLY;
63+
self.flags = process.O_RDONLY;
6464
break;
6565

6666
case "r+":
67-
self.flags = node.O_RDWR;
67+
self.flags = process.O_RDWR;
6868
break;
6969

7070
case "w":
71-
self.flags = node.O_CREAT | node.O_TRUNC | node.O_WRONLY;
71+
self.flags = process.O_CREAT | process.O_TRUNC | process.O_WRONLY;
7272
break;
7373

7474
case "w+":
75-
self.flags = node.O_CREAT | node.O_TRUNC | node.O_RDWR;
75+
self.flags = process.O_CREAT | process.O_TRUNC | process.O_RDWR;
7676
break;
7777

7878
case "a":
79-
self.flags = node.O_APPEND | node.O_CREAT | node.O_WRONLY;
79+
self.flags = process.O_APPEND | process.O_CREAT | process.O_WRONLY;
8080
break;
8181

8282
case "a+":
83-
self.flags = node.O_APPEND | node.O_CREAT | node.O_RDWR;
83+
self.flags = process.O_APPEND | process.O_CREAT | process.O_RDWR;
8484
break;
8585

8686
default:
@@ -124,21 +124,21 @@ proto._maybeDispatch = function () {
124124
userPromise = self.currentAction.promise;
125125

126126
promise.addCallback(function () {
127-
node.assert(self.currentAction.promise === userPromise);
127+
process.assert(self.currentAction.promise === userPromise);
128128
userPromise.emitSuccess.apply(userPromise, arguments);
129129
self.currentAction = null;
130130
self._maybeDispatch();
131131
}).addErrback(function () {
132132
debugMessage("Error in method " + method);
133-
node.assert(self.currentAction.promise === userPromise);
133+
process.assert(self.currentAction.promise === userPromise);
134134
userPromise.emitError.apply(userPromise, arguments);
135135
self.currentAction = null;
136136
self._maybeDispatch();
137137
});
138138
};
139139

140140
proto._queueAction = function (method, args) {
141-
var userPromise = new node.Promise();
141+
var userPromise = new process.Promise();
142142
this.actionQueue.push({ method: method, args: args, promise: userPromise });
143143
this._maybeDispatch();
144144
return userPromise;

0 commit comments

Comments
 (0)