Browse Source

Namespace EVERYTHING under process; introduce GLOBAL

http://groups.google.com/group/nodejs/browse_thread/thread/1034fd2ad2cd93e8
v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
ad0a4cefb8
  1. 4
      benchmark/http_simple.js
  2. 6
      benchmark/process_loop.js
  3. 8
      benchmark/run.js
  4. 2
      benchmark/static_http_server.js
  5. 117
      doc/api.txt
  6. 26
      lib/file.js
  7. 30
      lib/http.js
  8. 10
      lib/multipart.js
  9. 34
      lib/posix.js
  10. 6
      lib/repl.js
  11. 12
      lib/sys.js
  12. 4
      lib/tcp.js
  13. 22
      src/events.js
  14. 14
      src/file.js
  15. 77
      src/node.cc
  16. 136
      src/node.js
  17. 22
      src/util.js
  18. 8
      test/mjsunit/common.js
  19. 8
      test/mjsunit/test-buffered-file.js
  20. 2
      test/mjsunit/test-delayed-require.js
  21. 4
      test/mjsunit/test-event-emitter-add-listeners.js
  22. 2
      test/mjsunit/test-exec.js
  23. 4
      test/mjsunit/test-file-cat-noexist.js
  24. 6
      test/mjsunit/test-fs-sendfile.js
  25. 2
      test/mjsunit/test-fs-stat.js
  26. 8
      test/mjsunit/test-fs-write.js
  27. 2
      test/mjsunit/test-http-cat.js
  28. 2
      test/mjsunit/test-http-client-race.js
  29. 2
      test/mjsunit/test-http-client-upload.js
  30. 2
      test/mjsunit/test-http-malformed-request.js
  31. 2
      test/mjsunit/test-http-proxy.js
  32. 2
      test/mjsunit/test-http-server.js
  33. 2
      test/mjsunit/test-http.js
  34. 8
      test/mjsunit/test-mkdir-rmdir.js
  35. 2
      test/mjsunit/test-module-loading.js
  36. 2
      test/mjsunit/test-multipart.js
  37. 4
      test/mjsunit/test-process-buffering.js
  38. 4
      test/mjsunit/test-process-kill.js
  39. 4
      test/mjsunit/test-process-simple.js
  40. 4
      test/mjsunit/test-process-spawn-loop.js
  41. 14
      test/mjsunit/test-promise-timeout.js
  42. 12
      test/mjsunit/test-promise-wait.js
  43. 2
      test/mjsunit/test-readdir.js
  44. 4
      test/mjsunit/test-signal-handler.js
  45. 6
      test/mjsunit/test-tcp-binary.js
  46. 2
      test/mjsunit/test-tcp-many-clients.js
  47. 2
      test/mjsunit/test-tcp-pingpong-delay.js
  48. 2
      test/mjsunit/test-tcp-pingpong.js
  49. 2
      test/mjsunit/test-tcp-reconnect.js
  50. 2
      test/mjsunit/test-tcp-throttle-kernel-buffer.js
  51. 2
      test/mjsunit/test-tcp-throttle.js
  52. 2
      test/mjsunit/test-tcp-timeout.js
  53. 2
      test/mjsunit/test-timers.js
  54. 2
      test/mjsunit/test-utf8-scripts.js
  55. 4
      test/mjsunit/test-wait-ordering.js

4
benchmark/http_simple.js

@ -1,7 +1,7 @@
libDir = node.path.join(node.path.dirname(__filename), "../lib"); libDir = process.path.join(process.path.dirname(__filename), "../lib");
require.paths.unshift(libDir); require.paths.unshift(libDir);
node.mixin(require("/utils.js")); process.mixin(require("/utils.js"));
http = require("/http.js"); http = require("/http.js");
fixed = "" fixed = ""

6
benchmark/process_loop.js

@ -1,10 +1,10 @@
libDir = node.path.join(node.path.dirname(__filename), "../lib"); libDir = process.path.join(process.path.dirname(__filename), "../lib");
require.paths.unshift(libDir); require.paths.unshift(libDir);
node.mixin(require("/utils.js")); process.mixin(require("/utils.js"));
function next (i) { function next (i) {
if (i <= 0) return; if (i <= 0) return;
var child = node.createChildProcess("echo", ["hello"]); var child = process.createChildProcess("echo", ["hello"]);
child.addListener("output", function (chunk) { child.addListener("output", function (chunk) {
if (chunk) print(chunk); if (chunk) print(chunk);

8
benchmark/run.js

@ -1,16 +1,16 @@
libDir = node.path.join(node.path.dirname(__filename), "../lib"); libDir = process.path.join(process.path.dirname(__filename), "../lib");
require.paths.unshift(libDir); require.paths.unshift(libDir);
node.mixin(require("/utils.js")); process.mixin(require("/utils.js"));
var benchmarks = [ "static_http_server.js" var benchmarks = [ "static_http_server.js"
, "timers.js" , "timers.js"
, "process_loop.js" , "process_loop.js"
]; ];
var benchmark_dir = node.path.dirname(__filename); var benchmark_dir = process.path.dirname(__filename);
function exec (script, callback) { function exec (script, callback) {
var start = new Date(); var start = new Date();
var child = node.createChildProcess(ARGV[0], [node.path.join(benchmark_dir, script)]); var child = process.createChildProcess(process.ARGV[0], [process.path.join(benchmark_dir, script)]);
child.addListener("exit", function (code) { child.addListener("exit", function (code) {
var elapsed = new Date() - start; var elapsed = new Date() - start;
callback(elapsed, code); callback(elapsed, code);

2
benchmark/static_http_server.js

@ -1,4 +1,4 @@
libDir = node.path.join(node.path.dirname(__filename), "../lib"); libDir = process.path.join(process.path.dirname(__filename), "../lib");
require.paths.unshift(libDir); require.paths.unshift(libDir);
http = require("/http.js"); http = require("/http.js");
var concurrency = 30; var concurrency = 30;

117
doc/api.txt

@ -46,53 +46,35 @@ Unless otherwise noted, functions are all asynchronous and do not block
execution. execution.
=== Helpers === Global Objects
These objects are available to all programs. +GLOBAL+ ::
The global namespace object.
+node.cwd()+:: +process+ ::
Returns the current working directory of the process. The process object. Most stuff lives in here. See the "process object"
section.
+node.kill(pid, signal="SIGTERM")+ :: +require(path)+ ::
Send a signal to a process. +pid+ is the process id and +signal+ is the See the modules section.
signal to send; for example, "SIGINT" or "SIGUSR1". See kill(2) for more
information.
+node.compile(source, scriptOrigin)+:: +require.paths+ ::
Just like +eval()+ except that you can specify a +scriptOrigin+ for better The search path for absolute path arguments to +require()+.
error reporting.
+__filename+ :: +__filename+ ::
The filename of the script being executed. The filename of the script being executed.
+__module+ :: +__module+ ::
A reference to the current module (of type +node.Module+). In particular A reference to the current module (of type +process.Module+). In particular
+__module.exports+ is the same as the +exports+ object. See +src/node.js+ for +__module.exports+ is the same as the +exports+ object. See +src/process.js+ for
more information. more information.
+require(path)+ ::
See the modules section.
+require.paths+ ::
The search path for absolute path arguments to +require()+.
+node.mixin([deep], target, object1, [objectN])+ ::
Extend one object with one or more others, returning the modified object.
If no target is specified, the +process+ namespace itself is extended.
Keep in mind that the target object will be modified, and will be returned
from +node.mixin()+.
+
If a boolean true is specified as the first argument, Node performs a deep
copy, recursively copying any objects it finds. Otherwise, the copy will
share structure with the original object(s).
+
Undefined properties are not copied. However, properties inherited from the
object's prototype will be copied over.
=== The +process+ Object === The +process+ Object
+process+ is the equivalent of +window+ in browser-side javascript. It is +process+ is the equivalent of +window+ in browser-side javascript. It is
the global scope. +process+ is an instance of +node.EventEmitter+. the global scope. +process+ is an instance of +process.EventEmitter+.
[cols="1,2,10",options="header"] [cols="1,2,10",options="header"]
|========================================================= |=========================================================
@ -111,10 +93,6 @@ the global scope. +process+ is an instance of +node.EventEmitter+.
signal names such as SIGINT, SIGUSR1, etc. signal names such as SIGINT, SIGUSR1, etc.
|========================================================= |=========================================================
+process.exit(code=0)+::
Ends the process with the specified code. By default it exits with the
success code 0.
+process.ARGV+ :: +process.ARGV+ ::
An array containing the command line arguments. An array containing the command line arguments.
@ -124,6 +102,35 @@ An object containing the user environment. See environ(7).
+process.pid+ :: +process.pid+ ::
The PID of the process. The PID of the process.
+process.exit(code=0)+::
Ends the process with the specified code. By default it exits with the
success code 0.
+process.cwd()+::
Returns the current working directory of the process.
+process.kill(pid, signal="SIGTERM")+ ::
Send a signal to a process. +pid+ is the process id and +signal+ is the
signal to send; for example, "SIGINT" or "SIGUSR1". See kill(2) for more
information.
+process.compile(source, scriptOrigin)+::
Just like +eval()+ except that you can specify a +scriptOrigin+ for better
error reporting.
+process.mixin([deep], target, object1, [objectN])+ ::
Extend one object with one or more others, returning the modified object.
If no target is specified, the +GLOBAL+ namespace itself is extended.
Keep in mind that the target object will be modified, and will be returned
from +process.mixin()+.
+
If a boolean true is specified as the first argument, Node performs a deep
copy, recursively copying any objects it finds. Otherwise, the copy will
share structure with the original object(s).
+
Undefined properties are not copied. However, properties inherited from the
object's prototype will be copied over.
=== System module === System module
These function are in +"/sys.js"+. Use +require("/sys.js")+ to access them. These function are in +"/sys.js"+. Use +require("/sys.js")+ to access them.
@ -161,7 +168,7 @@ sys.exec("ls /").addCallback(function (stdout, stderr) {
Many objects in Node emit events: a TCP server emits an event each time 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 there is a connection, a child process emits an event when it exits. All
objects which emit events are are instances of +node.EventEmitter+. objects which emit events are are instances of +process.EventEmitter+.
Events are represented by a camel-cased string. Here are some examples: Events are represented by a camel-cased string. Here are some examples:
+"connection"+, +"receive"+, +"messageBegin"+. +"connection"+, +"receive"+, +"messageBegin"+.
@ -173,7 +180,7 @@ Some asynchronous file operations return an +EventEmitter+ called a
_promise_. A promise emits just a single event when the operation is _promise_. A promise emits just a single event when the operation is
complete. complete.
==== +node.EventEmitter+ ==== +process.EventEmitter+
All EventEmitters emit the event +"newListener"+ when new listeners are All EventEmitters emit the event +"newListener"+ when new listeners are
added. added.
@ -204,9 +211,9 @@ manipulated, e.g. to remove listeners.
+emitter.emit(event, arg1, arg2, ...)+ :: +emitter.emit(event, arg1, arg2, ...)+ ::
Execute each of the listeners in order with the supplied arguments. Execute each of the listeners in order with the supplied arguments.
==== +node.Promise+ ==== +process.Promise+
+node.Promise+ inherits from +node.eventEmitter+. A promise emits one of two +process.Promise+ inherits from +process.eventEmitter+. A promise emits one of two
events: +"success"+ or +"error"+. After emitting its event, it will not events: +"success"+ or +"error"+. After emitting its event, it will not
emit anymore events. emit anymore events.
@ -228,7 +235,7 @@ Adds a listener for the +"error"+ event. Returns the same promise object.
Adds a listener for the +"cancel"+ event. Returns the same promise object. Adds a listener for the +"cancel"+ event. Returns the same promise object.
+promise.emitSuccess(arg1, arg2, ...)+ :: +promise.emitSuccess(arg1, arg2, ...)+ ::
If you created the promise (by doing +new node.Promise()+) then call If you created the promise (by doing +new process.Promise()+) then call
+emitSuccess+ to emit the +"success"+ event with the given arguments. +emitSuccess+ to emit the +"success"+ event with the given arguments.
+ +
(+promise.emit("success", arg1, arg2, ...)+ should also work, but doesn't at (+promise.emit("success", arg1, arg2, ...)+ should also work, but doesn't at
@ -292,7 +299,7 @@ program setup, not during busy server activity.
=== Standard I/O === Standard I/O
Standard I/O is handled through a special object +node.stdio+. stdout and Standard I/O is handled through a special object +process.stdio+. stdout and
stdin are fully non-blocking (even when piping to files). stderr is stdin are fully non-blocking (even when piping to files). stderr is
synchronous. synchronous.
@ -303,22 +310,22 @@ synchronous.
| +"data"+ | +data+ | Made when stdin has received a chunk of data. | +"data"+ | +data+ | Made when stdin has received a chunk of data.
Depending on the encoding that stdin was opened Depending on the encoding that stdin was opened
with, +data+ will be a string. This event will with, +data+ will be a string. This event will
only be emited after +node.stdio.open()+ has only be emited after +process.stdio.open()+ has
been called. been called.
| +"close"+ | | Made when stdin has been closed. | +"close"+ | | Made when stdin has been closed.
|========================================================= |=========================================================
+node.stdio.open(encoding="utf8")+:: +process.stdio.open(encoding="utf8")+::
Open stdin. The program will not exit until +node.stdio.close()+ has been Open stdin. The program will not exit until +process.stdio.close()+ has been
called or the +"close"+ event has been emitted. called or the +"close"+ event has been emitted.
+node.stdio.write(data)+:: +process.stdio.write(data)+::
Write data to stdout. Write data to stdout.
+node.stdio.writeError(data)+:: +process.stdio.writeError(data)+::
Write data to stderr. Synchronous. Write data to stderr. Synchronous.
+node.stdio.close()+:: +process.stdio.close()+::
Close stdin. Close stdin.
@ -361,10 +368,10 @@ The module path is relative to the file calling +require()+. That is,
+circle.js+ must be in the same directory as +foo.js+ for +require()+ to +circle.js+ must be in the same directory as +foo.js+ for +require()+ to
find it. find it.
Use +node.mixin()+ to include modules into the global namespace. Use +process.mixin()+ to include modules into the global namespace.
---------------------------------------- ----------------------------------------
node.mixin(process, require("circle.js"), require("/sys.js")); process.mixin(process, require("circle.js"), require("/sys.js"));
puts("The area of a cirlce of radius 4 is " + area(4)); puts("The area of a cirlce of radius 4 is " + area(4));
---------------------------------------- ----------------------------------------
@ -418,10 +425,10 @@ Stops a interval from triggering.
=== Child Processes === Child Processes
Node provides a tridirectional +popen(3)+ facility through the class Node provides a tridirectional +popen(3)+ facility through the class
+node.ChildProcess+. It is possible to stream data through the child's +stdin+, +process.ChildProcess+. It is possible to stream data through the child's +stdin+,
+stdout+, and +stderr+ in a fully non-blocking way. +stdout+, and +stderr+ in a fully non-blocking way.
==== +node.ChildProcess+ ==== +process.ChildProcess+
[cols="1,2,10",options="header"] [cols="1,2,10",options="header"]
|========================================================= |=========================================================
@ -444,12 +451,12 @@ Node provides a tridirectional +popen(3)+ facility through the class
+"error"+ callbacks will no longer be made. +"error"+ callbacks will no longer be made.
|========================================================= |=========================================================
+node.createChildProcess(command, args=[], env=ENV)+:: +process.createChildProcess(command, args=[], env=ENV)+::
Launches a new process with the given +command+, command line arguments, and Launches a new process with the given +command+, command line arguments, and
environmental variables. For example: environmental variables. For example:
+ +
---------------------------------------- ----------------------------------------
var ls = node.createChildProcess("ls", ["-lh", "/usr"]); var ls = process.createChildProcess("ls", ["-lh", "/usr"]);
ls.addListener("output", function (data) { ls.addListener("output", function (data) {
puts(data); puts(data);
}); });
@ -485,7 +492,7 @@ File I/O is provided by simple wrappers around standard POSIX functions. To
use this module do +require("/posix.js")+. use this module do +require("/posix.js")+.
All POSIX wrappers have a similar form. They return a promise All POSIX wrappers have a similar form. They return a promise
(+node.Promise+). Example of deleting a file: (+process.Promise+). Example of deleting a file:
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
var posix = require("/posix.js"), var posix = require("/posix.js"),
@ -574,7 +581,7 @@ sys.puts("stats: " + JSON.stringify(stats));
+posix.open(path, flags, mode)+:: +posix.open(path, flags, mode)+::
See open(2). The constants like +O_CREAT+ are defined at +node.O_CREAT+. See open(2). The constants like +O_CREAT+ are defined at +process.O_CREAT+.
- on success: +fd+ is given as the parameter. - on success: +fd+ is given as the parameter.
- on error: no parameters. - on error: no parameters.

26
lib/file.js

@ -6,24 +6,24 @@ exports.debugLevel = 0; // Increase to get more verbose debug output
function debugMessage (msg) { function debugMessage (msg) {
if (exports.debugLevel > 0) { if (exports.debugLevel > 0) {
node.error(__filename + ": " + msg.toString()); process.error(__filename + ": " + msg.toString());
} }
} }
function debugObject (obj) { function debugObject (obj) {
if (exports.debugLevel > 0) { if (exports.debugLevel > 0) {
node.error(__filename + ": " + JSON.stringify(obj)); process.error(__filename + ": " + JSON.stringify(obj));
} }
} }
exports.read = posix.cat; exports.read = posix.cat;
exports.write = function (filename, data, encoding) { exports.write = function (filename, data, encoding) {
var promise = new node.Promise(); var promise = new process.Promise();
encoding = encoding || "utf8"; // default to utf8 encoding = encoding || "utf8"; // default to utf8
posix.open(filename, node.O_WRONLY | node.O_TRUNC | node.O_CREAT, 0666) posix.open(filename, process.O_WRONLY | process.O_TRUNC | process.O_CREAT, 0666)
.addCallback(function (fd) { .addCallback(function (fd) {
function doWrite (_data) { function doWrite (_data) {
posix.write(fd, _data, 0, encoding) posix.write(fd, _data, 0, encoding)
@ -60,27 +60,27 @@ exports.File = function (filename, mode, options) {
switch (mode) { switch (mode) {
case "r": case "r":
self.flags = node.O_RDONLY; self.flags = process.O_RDONLY;
break; break;
case "r+": case "r+":
self.flags = node.O_RDWR; self.flags = process.O_RDWR;
break; break;
case "w": case "w":
self.flags = node.O_CREAT | node.O_TRUNC | node.O_WRONLY; self.flags = process.O_CREAT | process.O_TRUNC | process.O_WRONLY;
break; break;
case "w+": case "w+":
self.flags = node.O_CREAT | node.O_TRUNC | node.O_RDWR; self.flags = process.O_CREAT | process.O_TRUNC | process.O_RDWR;
break; break;
case "a": case "a":
self.flags = node.O_APPEND | node.O_CREAT | node.O_WRONLY; self.flags = process.O_APPEND | process.O_CREAT | process.O_WRONLY;
break; break;
case "a+": case "a+":
self.flags = node.O_APPEND | node.O_CREAT | node.O_RDWR; self.flags = process.O_APPEND | process.O_CREAT | process.O_RDWR;
break; break;
default: default:
@ -124,13 +124,13 @@ proto._maybeDispatch = function () {
userPromise = self.currentAction.promise; userPromise = self.currentAction.promise;
promise.addCallback(function () { promise.addCallback(function () {
node.assert(self.currentAction.promise === userPromise); process.assert(self.currentAction.promise === userPromise);
userPromise.emitSuccess.apply(userPromise, arguments); userPromise.emitSuccess.apply(userPromise, arguments);
self.currentAction = null; self.currentAction = null;
self._maybeDispatch(); self._maybeDispatch();
}).addErrback(function () { }).addErrback(function () {
debugMessage("Error in method " + method); debugMessage("Error in method " + method);
node.assert(self.currentAction.promise === userPromise); process.assert(self.currentAction.promise === userPromise);
userPromise.emitError.apply(userPromise, arguments); userPromise.emitError.apply(userPromise, arguments);
self.currentAction = null; self.currentAction = null;
self._maybeDispatch(); self._maybeDispatch();
@ -138,7 +138,7 @@ proto._maybeDispatch = function () {
}; };
proto._queueAction = function (method, args) { proto._queueAction = function (method, args) {
var userPromise = new node.Promise(); var userPromise = new process.Promise();
this.actionQueue.push({ method: method, args: args, promise: userPromise }); this.actionQueue.push({ method: method, args: args, promise: userPromise });
this._maybeDispatch(); this._maybeDispatch();
return userPromise; return userPromise;

30
lib/http.js

@ -115,7 +115,7 @@ var chunk_expression = /chunk/i;
/* Abstract base class for ServerRequest and ClientResponse. */ /* Abstract base class for ServerRequest and ClientResponse. */
function IncomingMessage (connection) { function IncomingMessage (connection) {
node.EventEmitter.call(this); process.EventEmitter.call(this);
this.connection = connection; this.connection = connection;
this.httpVersion = null; this.httpVersion = null;
@ -136,7 +136,7 @@ function IncomingMessage (connection) {
this.statusCode = null; this.statusCode = null;
this.client = this.connection; this.client = this.connection;
} }
node.inherits(IncomingMessage, node.EventEmitter); process.inherits(IncomingMessage, process.EventEmitter);
IncomingMessage.prototype._parseQueryString = function () { IncomingMessage.prototype._parseQueryString = function () {
var parts = this.uri.queryString.split('&'); var parts = this.uri.queryString.split('&');
@ -177,7 +177,7 @@ IncomingMessage.prototype._addHeaderLine = function (field, value) {
}; };
function OutgoingMessage () { function OutgoingMessage () {
node.EventEmitter.call(this); process.EventEmitter.call(this);
this.output = []; this.output = [];
this.outputEncodings = []; this.outputEncodings = [];
@ -191,7 +191,7 @@ function OutgoingMessage () {
this.finished = false; this.finished = false;
} }
node.inherits(OutgoingMessage, node.EventEmitter); process.inherits(OutgoingMessage, process.EventEmitter);
OutgoingMessage.prototype.send = function (data, encoding) { OutgoingMessage.prototype.send = function (data, encoding) {
var length = this.output.length; var length = this.output.length;
@ -313,7 +313,7 @@ function ServerResponse () {
this.should_keep_alive = true; this.should_keep_alive = true;
this.use_chunked_encoding_by_default = true; this.use_chunked_encoding_by_default = true;
} }
node.inherits(ServerResponse, OutgoingMessage); process.inherits(ServerResponse, OutgoingMessage);
ServerResponse.prototype.sendHeader = function (statusCode, headers) { ServerResponse.prototype.sendHeader = function (statusCode, headers) {
var reason = STATUS_CODES[statusCode] || "unknown"; var reason = STATUS_CODES[statusCode] || "unknown";
@ -335,7 +335,7 @@ function ClientRequest (method, uri, headers) {
this.sendHeaderLines(method + " " + uri + " HTTP/1.0\r\n", headers); this.sendHeaderLines(method + " " + uri + " HTTP/1.0\r\n", headers);
} }
node.inherits(ClientRequest, OutgoingMessage); process.inherits(ClientRequest, OutgoingMessage);
ClientRequest.prototype.finish = function (responseListener) { ClientRequest.prototype.finish = function (responseListener) {
this.addListener("response", responseListener); this.addListener("response", responseListener);
@ -344,7 +344,7 @@ ClientRequest.prototype.finish = function (responseListener) {
function createIncomingMessageStream (connection, incoming_listener) { function createIncomingMessageStream (connection, incoming_listener) {
var stream = new node.EventEmitter(); var stream = new process.EventEmitter();
stream.addListener("incoming", incoming_listener); stream.addListener("incoming", incoming_listener);
@ -455,7 +455,7 @@ function flushMessageQueue (connection, queue) {
exports.createServer = function (requestListener, options) { exports.createServer = function (requestListener, options) {
var server = new node.http.Server(); var server = new process.http.Server();
//server.setOptions(options); //server.setOptions(options);
server.addListener("request", requestListener); server.addListener("request", requestListener);
server.addListener("connection", connectionListener); server.addListener("connection", connectionListener);
@ -494,7 +494,7 @@ function connectionListener (connection) {
exports.createClient = function (port, host) { exports.createClient = function (port, host) {
var client = new node.http.Client(); var client = new process.http.Client();
var requests = []; var requests = [];
@ -552,31 +552,31 @@ exports.createClient = function (port, host) {
return client; return client;
}; };
node.http.Client.prototype.get = function (uri, headers) { process.http.Client.prototype.get = function (uri, headers) {
var req = new ClientRequest("GET", uri, headers); var req = new ClientRequest("GET", uri, headers);
this._pushRequest(req); this._pushRequest(req);
return req; return req;
}; };
node.http.Client.prototype.head = function (uri, headers) { process.http.Client.prototype.head = function (uri, headers) {
var req = new ClientRequest("HEAD", uri, headers); var req = new ClientRequest("HEAD", uri, headers);
this._pushRequest(req); this._pushRequest(req);
return req; return req;
}; };
node.http.Client.prototype.post = function (uri, headers) { process.http.Client.prototype.post = function (uri, headers) {
var req = new ClientRequest("POST", uri, headers); var req = new ClientRequest("POST", uri, headers);
this._pushRequest(req); this._pushRequest(req);
return req; return req;
}; };
node.http.Client.prototype.del = function (uri, headers) { process.http.Client.prototype.del = function (uri, headers) {
var req = new ClientRequest("DELETE", uri, headers); var req = new ClientRequest("DELETE", uri, headers);
this._pushRequest(req); this._pushRequest(req);
return req; return req;
}; };
node.http.Client.prototype.put = function (uri, headers) { process.http.Client.prototype.put = function (uri, headers) {
var req = new ClientRequest("PUT", uri, headers); var req = new ClientRequest("PUT", uri, headers);
this._pushRequest(req); this._pushRequest(req);
return req; return req;
@ -584,7 +584,7 @@ node.http.Client.prototype.put = function (uri, headers) {
exports.cat = function (url, encoding, headers) { exports.cat = function (url, encoding, headers) {
var promise = new node.Promise(); var promise = new process.Promise();
encoding = encoding || "utf8"; encoding = encoding || "utf8";

10
lib/multipart.js

@ -1,6 +1,6 @@
exports.parse = function(options) { exports.parse = function(options) {
var stream = new exports.Stream(options); var stream = new exports.Stream(options);
var promise = new node.Promise(); var promise = new process.Promise();
var parts = {}; var parts = {};
stream.addListener('part', function(part) { stream.addListener('part', function(part) {
@ -24,11 +24,11 @@ exports.parse = function(options) {
}; };
exports.Stream = function(options) { exports.Stream = function(options) {
node.EventEmitter.call(this); process.EventEmitter.call(this);
this.init(options); this.init(options);
}; };
node.inherits(exports.Stream, node.EventEmitter); process.inherits(exports.Stream, process.EventEmitter);
var proto = exports.Stream.prototype; var proto = exports.Stream.prototype;
@ -96,7 +96,7 @@ proto.write = function(chunk) {
}; };
function Part(stream) { function Part(stream) {
node.EventEmitter.call(this); process.EventEmitter.call(this);
this.headers = {}; this.headers = {};
this.buffer = ''; this.buffer = '';
@ -109,7 +109,7 @@ function Part(stream) {
this._headersComplete = false; this._headersComplete = false;
} }
node.inherits(Part, node.EventEmitter); process.inherits(Part, process.EventEmitter);
Part.prototype.parsedHeaders = function() { Part.prototype.parsedHeaders = function() {
for (var header in this.headers) { for (var header in this.headers) {

34
lib/posix.js

@ -1,35 +1,35 @@
node.fs.Stats.prototype._checkModeProperty = function (property) { process.fs.Stats.prototype._checkModeProperty = function (property) {
return ((this.mode & property) === property); return ((this.mode & property) === property);
}; };
node.fs.Stats.prototype.isDirectory = function () { process.fs.Stats.prototype.isDirectory = function () {
return this._checkModeProperty(node.S_IFDIR); return this._checkModeProperty(process.S_IFDIR);
}; };
node.fs.Stats.prototype.isFile = function () { process.fs.Stats.prototype.isFile = function () {
return this._checkModeProperty(node.S_IFREG); return this._checkModeProperty(process.S_IFREG);
}; };
node.fs.Stats.prototype.isBlockDevice = function () { process.fs.Stats.prototype.isBlockDevice = function () {
return this._checkModeProperty(node.S_IFBLK); return this._checkModeProperty(process.S_IFBLK);
}; };
node.fs.Stats.prototype.isCharacterDevice = function () { process.fs.Stats.prototype.isCharacterDevice = function () {
return this._checkModeProperty(node.S_IFCHR); return this._checkModeProperty(process.S_IFCHR);
}; };
node.fs.Stats.prototype.isSymbolicLink = function () { process.fs.Stats.prototype.isSymbolicLink = function () {
return this._checkModeProperty(node.S_IFLNK); return this._checkModeProperty(process.S_IFLNK);
}; };
node.fs.Stats.prototype.isFIFO = function () { process.fs.Stats.prototype.isFIFO = function () {
return this._checkModeProperty(node.S_IFIFO); return this._checkModeProperty(process.S_IFIFO);
}; };
node.fs.Stats.prototype.isSocket = function () { process.fs.Stats.prototype.isSocket = function () {
return this._checkModeProperty(node.S_IFSOCK); return this._checkModeProperty(process.S_IFSOCK);
}; };
for (var key in node.fs) { for (var key in process.fs) {
if (node.fs.hasOwnProperty(key)) exports[key] = node.fs[key]; if (process.fs.hasOwnProperty(key)) exports[key] = process.fs[key];
} }

6
lib/repl.js

@ -18,8 +18,8 @@ exports.start = function (prompt) {
exports.prompt = prompt; exports.prompt = prompt;
} }
node.stdio.open(); process.stdio.open();
node.stdio.addListener("data", readline); process.stdio.addListener("data", readline);
displayPrompt(); displayPrompt();
} }
@ -97,7 +97,7 @@ function parseREPLKeyword (cmd) {
displayPrompt(); displayPrompt();
return true; return true;
case ".exit": case ".exit":
node.stdio.close(); process.stdio.close();
return true; return true;
case ".help": case ".help":
sys.puts(".break\tSometimes you get stuck in a place you can't get out... This will get you out."); sys.puts(".break\tSometimes you get stuck in a place you can't get out... This will get you out.");

12
lib/sys.js

@ -1,17 +1,17 @@
exports.print = function (x) { exports.print = function (x) {
node.stdio.write(x); process.stdio.write(x);
}; };
exports.puts = function (x) { exports.puts = function (x) {
node.stdio.write(x.toString() + "\n"); process.stdio.write(x.toString() + "\n");
}; };
exports.debug = function (x) { exports.debug = function (x) {
node.stdio.writeError("DEBUG: " + x.toString() + "\n"); process.stdio.writeError("DEBUG: " + x.toString() + "\n");
}; };
exports.error = function (x) { exports.error = function (x) {
node.stdio.writeError(x.toString() + "\n"); process.stdio.writeError(x.toString() + "\n");
}; };
/** /**
@ -44,10 +44,10 @@ exports.p = function (x) {
}; };
exports.exec = function (command) { exports.exec = function (command) {
var child = node.createChildProcess("/bin/sh", ["-c", command]); var child = process.createChildProcess("/bin/sh", ["-c", command]);
var stdout = ""; var stdout = "";
var stderr = ""; var stderr = "";
var promise = new node.Promise(); var promise = new process.Promise();
child.addListener("output", function (chunk) { child.addListener("output", function (chunk) {
if (chunk) stdout += chunk; if (chunk) stdout += chunk;

4
lib/tcp.js

@ -1,12 +1,12 @@
exports.createServer = function (on_connection, options) { exports.createServer = function (on_connection, options) {
var server = new node.tcp.Server(); var server = new process.tcp.Server();
server.addListener("connection", on_connection); server.addListener("connection", on_connection);
//server.setOptions(options); //server.setOptions(options);
return server; return server;
}; };
exports.createConnection = function (port, host) { exports.createConnection = function (port, host) {
var connection = new node.tcp.Connection(); var connection = new process.tcp.Connection();
connection.connect(port, host); connection.connect(port, host);
return connection; return connection;
}; };

22
src/events.js

@ -1,8 +1,8 @@
(function () { (function () {
// node.EventEmitter is defined in src/events.cc // process.EventEmitter is defined in src/events.cc
// node.EventEmitter.prototype.emit() is also defined there. // process.EventEmitter.prototype.emit() is also defined there.
node.EventEmitter.prototype.addListener = function (type, listener) { process.EventEmitter.prototype.addListener = function (type, listener) {
if (listener instanceof Function) { if (listener instanceof Function) {
if (!this._events) this._events = {}; if (!this._events) this._events = {};
if (!this._events.hasOwnProperty(type)) this._events[type] = []; if (!this._events.hasOwnProperty(type)) this._events[type] = [];
@ -14,13 +14,13 @@ node.EventEmitter.prototype.addListener = function (type, listener) {
return this; return this;
}; };
node.EventEmitter.prototype.listeners = function (type) { process.EventEmitter.prototype.listeners = function (type) {
if (!this._events) this._events = {}; if (!this._events) this._events = {};
if (!this._events.hasOwnProperty(type)) this._events[type] = []; if (!this._events.hasOwnProperty(type)) this._events[type] = [];
return this._events[type]; return this._events[type];
}; };
node.Promise.prototype.timeout = function(timeout) { process.Promise.prototype.timeout = function(timeout) {
if (timeout === undefined) { if (timeout === undefined) {
return this._timeoutDuration; return this._timeoutDuration;
} }
@ -52,36 +52,36 @@ node.Promise.prototype.timeout = function(timeout) {
return this; return this;
}; };
node.Promise.prototype.cancel = function() { process.Promise.prototype.cancel = function() {
this._events['success'] = []; this._events['success'] = [];
this._events['error'] = []; this._events['error'] = [];
this.emitCancel(); this.emitCancel();
}; };
node.Promise.prototype.emitCancel = function() { process.Promise.prototype.emitCancel = function() {
var args = Array.prototype.slice.call(arguments); var args = Array.prototype.slice.call(arguments);
args.unshift('cancel'); args.unshift('cancel');
this.emit.apply(this, args); this.emit.apply(this, args);
}; };
node.Promise.prototype.addCallback = function (listener) { process.Promise.prototype.addCallback = function (listener) {
this.addListener("success", listener); this.addListener("success", listener);
return this; return this;
}; };
node.Promise.prototype.addErrback = function (listener) { process.Promise.prototype.addErrback = function (listener) {
this.addListener("error", listener); this.addListener("error", listener);
return this; return this;
}; };
node.Promise.prototype.addCancelback = function (listener) { process.Promise.prototype.addCancelback = function (listener) {
this.addListener("cancel", listener); this.addListener("cancel", listener);
return this; return this;
}; };
node.Promise.prototype.wait = function () { process.Promise.prototype.wait = function () {
var ret; var ret;
var had_error = false; var had_error = false;
this.addCallback(function () { this.addCallback(function () {

14
src/file.js

@ -1,19 +1,19 @@
node.fs.exists = function (path, callback) { process.fs.exists = function (path, callback) {
var p = node.fs.stat(path); var p = process.fs.stat(path);
p.addCallback(function () { callback(true); }); p.addCallback(function () { callback(true); });
p.addErrback(function () { callback(false); }); p.addErrback(function () { callback(false); });
}; };
node.fs.cat = function (path, encoding) { process.fs.cat = function (path, encoding) {
var promise = new node.Promise(); var promise = new process.Promise();
encoding = encoding || "utf8"; // default to utf8 encoding = encoding || "utf8"; // default to utf8
node.fs.open(path, node.O_RDONLY, 0666).addCallback(function (fd) { process.fs.open(path, process.O_RDONLY, 0666).addCallback(function (fd) {
var content = "", pos = 0; var content = "", pos = 0;
function readChunk () { function readChunk () {
node.fs.read(fd, 16*1024, pos, encoding).addCallback(function (chunk, bytes_read) { process.fs.read(fd, 16*1024, pos, encoding).addCallback(function (chunk, bytes_read) {
if (chunk) { if (chunk) {
if (chunk.constructor === String) { if (chunk.constructor === String) {
content += chunk; content += chunk;
@ -25,7 +25,7 @@ node.fs.cat = function (path, encoding) {
readChunk(); readChunk();
} else { } else {
promise.emitSuccess(content); promise.emitSuccess(content);
node.fs.close(fd); process.fs.close(fd);
} }
}).addErrback(function () { }).addErrback(function () {
promise.emitError(); promise.emitError();

77
src/node.cc

@ -31,6 +31,8 @@ extern char **environ;
namespace node { namespace node {
static Persistent<Object> process;
static int dash_dash_index = 0; static int dash_dash_index = 0;
static bool use_debug_agent = false; static bool use_debug_agent = false;
@ -267,10 +269,8 @@ v8::Handle<v8::Value> Kill(const v8::Arguments& args) {
sig = args[1]->Int32Value(); sig = args[1]->Int32Value();
} else if (args[1]->IsString()) { } else if (args[1]->IsString()) {
Local<String> signame = args[1]->ToString(); Local<String> signame = args[1]->ToString();
Local<Object> process = Context::GetCurrent()->Global();
Local<Object> node_obj = process->Get(String::NewSymbol("node"))->ToObject();
Local<Value> sig_v = node_obj->Get(signame); Local<Value> sig_v = process->Get(signame);
if (!sig_v->IsNumber()) { if (!sig_v->IsNumber()) {
return ThrowException(Exception::Error(String::New("Unknown signal"))); return ThrowException(Exception::Error(String::New("Unknown signal")));
} }
@ -419,16 +419,19 @@ static void ExecuteNativeJS(const char *filename, const char *data) {
static Local<Object> Load(int argc, char *argv[]) { static Local<Object> Load(int argc, char *argv[]) {
HandleScope scope; HandleScope scope;
// Reference to 'process' Local<FunctionTemplate> process_template = FunctionTemplate::New();
Local<Object> process = Context::GetCurrent()->Global(); node::EventEmitter::Initialize(process_template);
process = Persistent<Object>::New(process_template->GetFunction()->NewInstance());
Local<Object> node_obj = Object::New(); // Create the 'process.node' object // Assign the process object to its place.
process->Set(String::NewSymbol("node"), node_obj); // and assign it. Local<Object> global = Context::GetCurrent()->Global();
global->Set(String::NewSymbol("process"), process);
// node.version // node.version
node_obj->Set(String::NewSymbol("version"), String::New(NODE_VERSION)); process->Set(String::NewSymbol("version"), String::New(NODE_VERSION));
// node.installPrefix // node.installPrefix
node_obj->Set(String::NewSymbol("installPrefix"), String::New(NODE_PREFIX)); process->Set(String::NewSymbol("installPrefix"), String::New(NODE_PREFIX));
// process.ARGV // process.ARGV
int i, j; int i, j;
@ -460,40 +463,40 @@ static Local<Object> Load(int argc, char *argv[]) {
process->Set(String::NewSymbol("pid"), Integer::New(getpid())); process->Set(String::NewSymbol("pid"), Integer::New(getpid()));
// define various internal methods // define various internal methods
NODE_SET_METHOD(node_obj, "compile", Compile); NODE_SET_METHOD(process, "compile", Compile);
NODE_SET_METHOD(node_obj, "reallyExit", Exit); NODE_SET_METHOD(process, "reallyExit", Exit);
NODE_SET_METHOD(node_obj, "cwd", Cwd); NODE_SET_METHOD(process, "cwd", Cwd);
NODE_SET_METHOD(node_obj, "dlopen", DLOpen); NODE_SET_METHOD(process, "dlopen", DLOpen);
NODE_SET_METHOD(node_obj, "kill", Kill); NODE_SET_METHOD(process, "kill", Kill);
// Assign the EventEmitter. It was created in main(). // Assign the EventEmitter. It was created in main().
node_obj->Set(String::NewSymbol("EventEmitter"), process->Set(String::NewSymbol("EventEmitter"),
EventEmitter::constructor_template->GetFunction()); EventEmitter::constructor_template->GetFunction());
// Initialize the C++ modules..................filename of module // Initialize the C++ modules..................filename of module
Promise::Initialize(node_obj); // events.cc Promise::Initialize(process); // events.cc
Stdio::Initialize(node_obj); // stdio.cc Stdio::Initialize(process); // stdio.cc
Timer::Initialize(node_obj); // timer.cc Timer::Initialize(process); // timer.cc
SignalHandler::Initialize(node_obj); // signal_handler.cc SignalHandler::Initialize(process); // signal_handler.cc
ChildProcess::Initialize(node_obj); // child_process.cc ChildProcess::Initialize(process); // child_process.cc
DefineConstants(node_obj); // constants.cc DefineConstants(process); // constants.cc
// Create node.dns // Create node.dns
Local<Object> dns = Object::New(); Local<Object> dns = Object::New();
node_obj->Set(String::NewSymbol("dns"), dns); process->Set(String::NewSymbol("dns"), dns);
DNS::Initialize(dns); // dns.cc DNS::Initialize(dns); // dns.cc
Local<Object> fs = Object::New(); Local<Object> fs = Object::New();
node_obj->Set(String::NewSymbol("fs"), fs); process->Set(String::NewSymbol("fs"), fs);
File::Initialize(fs); // file.cc File::Initialize(fs); // file.cc
// Create node.tcp. Note this separate from lib/tcp.js which is the public // Create node.tcp. Note this separate from lib/tcp.js which is the public
// frontend. // frontend.
Local<Object> tcp = Object::New(); Local<Object> tcp = Object::New();
node_obj->Set(String::New("tcp"), tcp); process->Set(String::New("tcp"), tcp);
Server::Initialize(tcp); // tcp.cc Server::Initialize(tcp); // tcp.cc
Connection::Initialize(tcp); // tcp.cc Connection::Initialize(tcp); // tcp.cc
// Create node.http. Note this separate from lib/http.js which is the // Create node.http. Note this separate from lib/http.js which is the
// public frontend. // public frontend.
Local<Object> http = Object::New(); Local<Object> http = Object::New();
node_obj->Set(String::New("http"), http); process->Set(String::New("http"), http);
HTTPServer::Initialize(http); // http.cc HTTPServer::Initialize(http); // http.cc
HTTPConnection::Initialize(http); // http.cc HTTPConnection::Initialize(http); // http.cc
@ -505,16 +508,12 @@ static Local<Object> Load(int argc, char *argv[]) {
// In node.js we actually load the file specified in ARGV[1] // In node.js we actually load the file specified in ARGV[1]
// so your next reading stop should be node.js! // so your next reading stop should be node.js!
ExecuteNativeJS("node.js", native_node); ExecuteNativeJS("node.js", native_node);
return scope.Close(node_obj);
} }
static void EmitExitEvent() { static void EmitExitEvent() {
HandleScope scope; HandleScope scope;
// Get reference to 'process' object. // Get the 'emit' function from 'process'
Local<Object> process = Context::GetCurrent()->Global();
// Get the 'emit' function from it.
Local<Value> emit_v = process->Get(String::NewSymbol("emit")); Local<Value> emit_v = process->Get(String::NewSymbol("emit"));
if (!emit_v->IsFunction()) { if (!emit_v->IsFunction()) {
// could not emit exit event so exit // could not emit exit event so exit
@ -643,26 +642,20 @@ int main(int argc, char *argv[]) {
"Use 'd8 --remote_debugger' to access it.\n"); "Use 'd8 --remote_debugger' to access it.\n");
} }
// Create the global 'process' object's FunctionTemplate. // Create the 'GLOBAL' object's FunctionTemplate.
Local<FunctionTemplate> process_template = FunctionTemplate::New(); Local<FunctionTemplate> global_template = FunctionTemplate::New();
// The global object (process) is an instance of EventEmitter. For some
// strange and forgotten reasons we must initialize EventEmitter now
// before creating the Context. EventEmitter will be assigned to it's
// namespace node.EventEmitter in Load() bellow.
node::EventEmitter::Initialize(process_template);
// Create the one and only Context. // Create the one and only Context.
Persistent<Context> context = Context::New(NULL, Persistent<Context> context = Context::New(NULL,
process_template->InstanceTemplate()); global_template->InstanceTemplate());
Context::Scope context_scope(context); Context::Scope context_scope(context);
// Actually assign the global object to it's place as 'process' // Actually assign the global object to it's place as 'GLOBAL'
context->Global()->Set(String::NewSymbol("process"), context->Global()); context->Global()->Set(String::NewSymbol("GLOBAL"), context->Global());
// Create all the objects, load modules, do everything. // Create all the objects, load modules, do everything.
// so your next reading stop should be node::Load()! // so your next reading stop should be node::Load()!
Local<Object> node_obj = node::Load(argc, argv); node::Load(argc, argv);
// All our arguments are loaded. We've evaluated all of the scripts. We // All our arguments are loaded. We've evaluated all of the scripts. We
// might even have created TCP servers. Now we enter the main event loop. // might even have created TCP servers. Now we enter the main event loop.

136
src/node.js

@ -1,13 +1,13 @@
node.tcp.createServer = function () { process.tcp.createServer = function () {
throw new Error("node.tcp.createServer() has moved. Use require('/tcp.js') to access it."); throw new Error("process.tcp.createServer() has moved. Use require('/tcp.js') to access it.");
}; };
node.createProcess = function () { process.createProcess = function () {
throw "node.createProcess() has been changed to node.createChildProcess() update your code"; throw "process.createProcess() has been changed to process.createChildProcess() update your code";
}; };
node.createChildProcess = function (file, args, env) { process.createChildProcess = function (file, args, env) {
var child = new node.ChildProcess(); var child = new process.ChildProcess();
args = args || []; args = args || [];
env = env || process.ENV; env = env || process.ENV;
var envPairs = []; var envPairs = [];
@ -23,24 +23,24 @@ node.createChildProcess = function (file, args, env) {
return child; return child;
}; };
node.exec = function () { process.exec = function () {
throw new Error("node.exec() has moved. Use require('/sys.js') to bring it back."); throw new Error("process.exec() has moved. Use require('/sys.js') to bring it back.");
} }
node.http.createServer = function () { process.http.createServer = function () {
throw new Error("node.http.createServer() has moved. Use require('/http.js') to access it."); throw new Error("process.http.createServer() has moved. Use require('/http.js') to access it.");
} }
node.http.createClient = function () { process.http.createClient = function () {
throw new Error("node.http.createClient() has moved. Use require('/http.js') to access it."); throw new Error("process.http.createClient() has moved. Use require('/http.js') to access it.");
} }
node.tcp.createConnection = function (port, host) { process.tcp.createConnection = function (port, host) {
throw new Error("node.tcp.createConnection() has moved. Use require('/tcp.js') to access it."); throw new Error("process.tcp.createConnection() has moved. Use require('/tcp.js') to access it.");
}; };
include = function () { include = function () {
throw new Error("include() has been removed. Use node.mixin(process, require(file)) to get the same effect."); throw new Error("include() has been removed. Use process.mixin(process, require(file)) to get the same effect.");
} }
/* From jQuery.extend in the jQuery JavaScript Library v1.3.2 /* From jQuery.extend in the jQuery JavaScript Library v1.3.2
@ -48,7 +48,7 @@ include = function () {
* Dual licensed under the MIT and GPL licenses. * Dual licensed under the MIT and GPL licenses.
* http://docs.jquery.com/License * http://docs.jquery.com/License
*/ */
node.mixin = function() { process.mixin = function() {
// copy reference to target object // copy reference to target object
var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options; var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
@ -61,12 +61,12 @@ node.mixin = function() {
} }
// Handle case when target is a string or something (possible in deep copy) // Handle case when target is a string or something (possible in deep copy)
if ( typeof target !== "object" && !node.isFunction(target) ) if ( typeof target !== "object" && !process.isFunction(target) )
target = {}; target = {};
// mixin process itself if only one argument is passed // mixin process itself if only one argument is passed
if ( length == i ) { if ( length == i ) {
target = process; target = GLOBAL;
--i; --i;
} }
@ -83,7 +83,7 @@ node.mixin = function() {
// Recurse if we're merging object values // Recurse if we're merging object values
if ( deep && copy && typeof copy === "object" && !copy.nodeType ) if ( deep && copy && typeof copy === "object" && !copy.nodeType )
target[ name ] = node.mixin( deep, target[ name ] = process.mixin( deep,
// Never move original objects, clone them // Never move original objects, clone them
src || ( copy.length != null ? [ ] : { } ) src || ( copy.length != null ? [ ] : { } )
, copy ); , copy );
@ -103,12 +103,12 @@ node.mixin = function() {
(function () { // anonymous namespace (function () { // anonymous namespace
function isSignal (event) { function isSignal (event) {
return event.slice(0, 3) === 'SIG' && node.hasOwnProperty(event); return event.slice(0, 3) === 'SIG' && process.hasOwnProperty(event);
}; };
process.addListener("newListener", function (event) { process.addListener("newListener", function (event) {
if (isSignal(event) && process.listeners(event).length === 0) { if (isSignal(event) && process.listeners(event).length === 0) {
var handler = new node.SignalHandler(node[event]); var handler = new process.SignalHandler(process[event]);
handler.addListener("signal", function () { handler.addListener("signal", function () {
process.emit(event); process.emit(event);
}); });
@ -120,14 +120,14 @@ node.mixin = function() {
// Timers // Timers
function setTimeout (callback, after) { function setTimeout (callback, after) {
var timer = new node.Timer(); var timer = new process.Timer();
timer.addListener("timeout", callback); timer.addListener("timeout", callback);
timer.start(after, 0); timer.start(after, 0);
return timer; return timer;
} }
function setInterval (callback, repeat) { function setInterval (callback, repeat) {
var timer = new node.Timer(); var timer = new process.Timer();
timer.addListener("timeout", callback); timer.addListener("timeout", callback);
timer.start(repeat, repeat); timer.start(repeat, repeat);
return timer; return timer;
@ -141,18 +141,18 @@ clearInterval = clearTimeout;
// Module // Module
node.libraryPaths = [ node.path.join(ENV["HOME"], ".node_libraries") process.libraryPaths = [ process.path.join(process.ENV["HOME"], ".node_libraries")
, node.path.join(node.installPrefix, "lib/node/libraries") , process.path.join(process.installPrefix, "lib/node/libraries")
, "/" , "/"
]; ];
if (ENV["NODE_LIBRARY_PATHS"]) { if (process.ENV["NODE_LIBRARY_PATHS"]) {
node.libraryPaths = process.libraryPaths =
ENV["NODE_LIBRARY_PATHS"].split(":").concat(node.libraryPaths); process.ENV["NODE_LIBRARY_PATHS"].split(":").concat(process.libraryPaths);
} }
node.Module = function (filename, parent) { process.Module = function (filename, parent) {
node.assert(filename.charAt(0) == "/"); process.assert(filename.charAt(0) == "/");
this.filename = filename; this.filename = filename;
this.exports = {}; this.exports = {};
this.parent = parent; this.parent = parent;
@ -163,26 +163,26 @@ node.Module = function (filename, parent) {
this.children = []; this.children = [];
}; };
node.Module.cache = {}; process.Module.cache = {};
(function () { (function () {
function retrieveFromCache (loadPromise, fullPath, parent) { function retrieveFromCache (loadPromise, fullPath, parent) {
var module; var module;
if (fullPath in node.Module.cache) { if (fullPath in process.Module.cache) {
module = node.Module.cache[fullPath]; module = process.Module.cache[fullPath];
setTimeout(function () { setTimeout(function () {
loadPromise.emitSuccess(module.exports); loadPromise.emitSuccess(module.exports);
}, 0); }, 0);
} else { } else {
module = new node.Module(fullPath, parent); module = new process.Module(fullPath, parent);
node.Module.cache[fullPath] = module; process.Module.cache[fullPath] = module;
module.load(loadPromise); module.load(loadPromise);
} }
} }
function findPath (path, dirs, callback) { function findPath (path, dirs, callback) {
node.assert(path.charAt(0) == "/"); process.assert(path.charAt(0) == "/");
node.assert(dirs.constructor == Array); process.assert(dirs.constructor == Array);
if (dirs.length == 0) { if (dirs.length == 0) {
callback(); callback();
@ -190,8 +190,8 @@ node.Module.cache = {};
var dir = dirs[0]; var dir = dirs[0];
var rest = dirs.slice(1, dirs.length); var rest = dirs.slice(1, dirs.length);
var fullPath = node.path.join(dir, path); var fullPath = process.path.join(dir, path);
node.fs.exists(fullPath, function (doesExist) { process.fs.exists(fullPath, function (doesExist) {
if (doesExist) { if (doesExist) {
callback(fullPath); callback(fullPath);
} else { } else {
@ -201,8 +201,8 @@ node.Module.cache = {};
} }
} }
node.loadModule = function (requestedPath, exports, parent) { process.loadModule = function (requestedPath, exports, parent) {
var loadPromise = new node.Promise(); var loadPromise = new process.Promise();
// On success copy the loaded properties into the exports // On success copy the loaded properties into the exports
loadPromise.addCallback(function (t) { loadPromise.addCallback(function (t) {
@ -212,19 +212,19 @@ node.Module.cache = {};
}); });
loadPromise.addErrback(function (e) { loadPromise.addErrback(function (e) {
node.stdio.writeError(e.message + "\n"); process.stdio.writeError(e.message + "\n");
process.exit(1); process.exit(1);
}); });
if (!parent) { if (!parent) {
// root module // root module
node.assert(requestedPath.charAt(0) == "/"); process.assert(requestedPath.charAt(0) == "/");
retrieveFromCache(loadPromise, requestedPath); retrieveFromCache(loadPromise, requestedPath);
} else { } else {
if (requestedPath.charAt(0) == "/") { if (requestedPath.charAt(0) == "/") {
// Need to find the module in node.libraryPaths // Need to find the module in process.libraryPaths
findPath(requestedPath, node.libraryPaths, function (fullPath) { findPath(requestedPath, process.libraryPaths, function (fullPath) {
if (fullPath) { if (fullPath) {
retrieveFromCache(loadPromise, fullPath, parent); retrieveFromCache(loadPromise, fullPath, parent);
} else { } else {
@ -234,7 +234,7 @@ node.Module.cache = {};
} else { } else {
// Relative file load // Relative file load
var fullPath = node.path.join(node.path.dirname(parent.filename), var fullPath = process.path.join(process.path.dirname(parent.filename),
requestedPath); requestedPath);
retrieveFromCache(loadPromise, fullPath, parent); retrieveFromCache(loadPromise, fullPath, parent);
} }
@ -244,12 +244,12 @@ node.Module.cache = {};
}; };
}()); }());
node.Module.prototype.load = function (loadPromise) { process.Module.prototype.load = function (loadPromise) {
if (this.loaded) { if (this.loaded) {
loadPromise.emitError(new Error("Module '" + self.filename + "' is already loaded.")); loadPromise.emitError(new Error("Module '" + self.filename + "' is already loaded."));
return; return;
} }
node.assert(!node.loadPromise); process.assert(!process.loadPromise);
this.loadPromise = loadPromise; this.loadPromise = loadPromise;
if (this.filename.match(/\.node$/)) { if (this.filename.match(/\.node$/)) {
@ -259,14 +259,14 @@ node.Module.prototype.load = function (loadPromise) {
} }
}; };
node.Module.prototype.loadObject = function (loadPromise) { process.Module.prototype.loadObject = function (loadPromise) {
var self = this; var self = this;
// XXX Not yet supporting loading from HTTP. would need to download the // XXX Not yet supporting loading from HTTP. would need to download the
// file, store it to tmp then run dlopen on it. // file, store it to tmp then run dlopen on it.
node.fs.exists(self.filename, function (does_exist) { process.fs.exists(self.filename, function (does_exist) {
if (does_exist) { if (does_exist) {
self.loaded = true; self.loaded = true;
node.dlopen(self.filename, self.exports); // FIXME synchronus process.dlopen(self.filename, self.exports); // FIXME synchronus
loadPromise.emitSuccess(self.exports); loadPromise.emitSuccess(self.exports);
} else { } else {
loadPromise.emitError(new Error("Error reading " + self.filename)); loadPromise.emitError(new Error("Error reading " + self.filename));
@ -274,9 +274,9 @@ node.Module.prototype.loadObject = function (loadPromise) {
}); });
}; };
node.Module.prototype.loadScript = function (loadPromise) { process.Module.prototype.loadScript = function (loadPromise) {
var self = this; var self = this;
var catPromise = node.cat(self.filename); var catPromise = process.cat(self.filename);
catPromise.addErrback(function () { catPromise.addErrback(function () {
loadPromise.emitError(new Error("Error reading " + self.filename)); loadPromise.emitError(new Error("Error reading " + self.filename));
@ -294,14 +294,14 @@ node.Module.prototype.loadScript = function (loadPromise) {
return requireAsync(url).wait(); return requireAsync(url).wait();
} }
require.paths = node.libraryPaths; require.paths = process.libraryPaths;
require.async = requireAsync; require.async = requireAsync;
// create wrapper function // create wrapper function
var wrapper = "var __wrap__ = function (__module, __filename, exports, require) { " var wrapper = "var __wrap__ = function (__module, __filename, exports, require) { "
+ content + content
+ "\n}; __wrap__;"; + "\n}; __wrap__;";
var compiled_wrapper = node.compile(wrapper, self.filename); var compiled_wrapper = process.compile(wrapper, self.filename);
compiled_wrapper.apply(self.exports, [self, self.filename, self.exports, require]); compiled_wrapper.apply(self.exports, [self, self.filename, self.exports, require]);
@ -312,11 +312,11 @@ node.Module.prototype.loadScript = function (loadPromise) {
}); });
}; };
node.Module.prototype.newChild = function (path) { process.Module.prototype.newChild = function (path) {
return node.loadModule(path, {}, this); return process.loadModule(path, {}, this);
}; };
node.Module.prototype.waitChildrenLoad = function (callback) { process.Module.prototype.waitChildrenLoad = function (callback) {
var nloaded = 0; var nloaded = 0;
var children = this.children; var children = this.children;
for (var i = 0; i < children.length; i++) { for (var i = 0; i < children.length; i++) {
@ -336,25 +336,21 @@ node.Module.prototype.waitChildrenLoad = function (callback) {
process.exit = function (code) { process.exit = function (code) {
process.emit("exit"); process.emit("exit");
node.reallyExit(code); process.reallyExit(code);
};
node.exit = function (code) {
throw new Error("node.exit() has been renamed to process.exit().");
}; };
(function () { (function () {
var cwd = node.cwd(); var cwd = process.cwd();
// Make ARGV[0] and ARGV[1] into full paths. // Make process.ARGV[0] and process.ARGV[1] into full paths.
if (ARGV[0].charAt(0) != "/") { if (process.ARGV[0].charAt(0) != "/") {
ARGV[0] = node.path.join(cwd, ARGV[0]); process.ARGV[0] = process.path.join(cwd, process.ARGV[0]);
} }
if (ARGV[1].charAt(0) != "/") { if (process.ARGV[1].charAt(0) != "/") {
ARGV[1] = node.path.join(cwd, ARGV[1]); process.ARGV[1] = process.path.join(cwd, process.ARGV[1]);
} }
// Load the root module--the command line argument. // Load the root module--the command line argument.
node.loadModule(ARGV[1], process); process.loadModule(process.ARGV[1], process);
}()); }());

22
src/util.js

@ -11,7 +11,7 @@
* prototype * prototype
* @param {function} superCtor Constructor function to inherit prototype from * @param {function} superCtor Constructor function to inherit prototype from
*/ */
node.inherits = function (ctor, superCtor) { process.inherits = function (ctor, superCtor) {
var tempCtor = function(){}; var tempCtor = function(){};
tempCtor.prototype = superCtor.prototype; tempCtor.prototype = superCtor.prototype;
ctor.super_ = superCtor.prototype; ctor.super_ = superCtor.prototype;
@ -19,21 +19,21 @@ node.inherits = function (ctor, superCtor) {
ctor.prototype.constructor = ctor; ctor.prototype.constructor = ctor;
}; };
node.assert = function (x, msg) { process.assert = function (x, msg) {
if (!(x)) throw new Error(msg || "assertion error"); if (!(x)) throw new Error(msg || "assertion error");
}; };
node.cat = function(location, encoding) { process.cat = function(location, encoding) {
var url_re = new RegExp("^http:\/\/"); var url_re = new RegExp("^http:\/\/");
if (url_re.exec(location)) { if (url_re.exec(location)) {
throw new Error("node.cat for http urls is temporarally disabled."); throw new Error("process.cat for http urls is temporarally disabled.");
} }
//var f = url_re.exec(location) ? node.http.cat : node.fs.cat; //var f = url_re.exec(location) ? process.http.cat : process.fs.cat;
//return f(location, encoding); //return f(location, encoding);
return node.fs.cat(location, encoding); return process.fs.cat(location, encoding);
}; };
node.path = new function () { process.path = new function () {
this.join = function () { this.join = function () {
var joined = ""; var joined = "";
for (var i = 0; i < arguments.length; i++) { for (var i = 0; i < arguments.length; i++) {
@ -81,10 +81,10 @@ p = function () {
throw new Error("p() has moved. Use require('/sys.js') to bring it back."); throw new Error("p() has moved. Use require('/sys.js') to bring it back.");
} }
node.debug = function () { process.debug = function () {
throw new Error("node.debug() has moved. Use require('/sys.js') to bring it back."); throw new Error("process.debug() has moved. Use require('/sys.js') to bring it back.");
} }
node.error = function () { process.error = function () {
throw new Error("node.error() has moved. Use require('/sys.js') to bring it back."); throw new Error("process.error() has moved. Use require('/sys.js') to bring it back.");
} }

8
test/mjsunit/common.js

@ -1,11 +1,11 @@
exports.testDir = node.path.dirname(__filename); exports.testDir = process.path.dirname(__filename);
exports.fixturesDir = node.path.join(exports.testDir, "fixtures"); exports.fixturesDir = process.path.join(exports.testDir, "fixtures");
exports.libDir = node.path.join(exports.testDir, "../../lib"); exports.libDir = process.path.join(exports.testDir, "../../lib");
require.paths.unshift(exports.libDir); require.paths.unshift(exports.libDir);
var mjsunit = require("/mjsunit.js"); var mjsunit = require("/mjsunit.js");
var utils = require("/utils.js"); var utils = require("/utils.js");
node.mixin(exports, mjsunit, utils); process.mixin(exports, mjsunit, utils);
exports.posix = require("/posix.js"); exports.posix = require("/posix.js");

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

@ -1,10 +1,10 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
var testTxt = node.path.join(fixturesDir, "test.txt"); var testTxt = process.path.join(fixturesDir, "test.txt");
var libDir = node.path.join(testDir, "../../lib"); var libDir = process.path.join(testDir, "../../lib");
require.paths.unshift(libDir); require.paths.unshift(libDir);
node.mixin(require("/file.js")); process.mixin(require("/file.js"));
var fileUnlinked = false; var fileUnlinked = false;

2
test/mjsunit/test-delayed-require.js

@ -1,4 +1,4 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
setTimeout(function () { setTimeout(function () {
a = require("fixtures/a.js"); a = require("fixtures/a.js");

4
test/mjsunit/test-event-emitter-add-listeners.js

@ -1,6 +1,6 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
var e = new node.EventEmitter(); var e = new process.EventEmitter();
var events_new_listener_emited = []; var events_new_listener_emited = [];
var times_hello_emited = 0; var times_hello_emited = 0;

2
test/mjsunit/test-exec.js

@ -1,4 +1,4 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
success_count = 0; success_count = 0;
error_count = 0; error_count = 0;

4
test/mjsunit/test-file-cat-noexist.js

@ -1,7 +1,7 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
var got_error = false; var got_error = false;
var filename = node.path.join(fixturesDir, "does_not_exist.txt"); var filename = process.path.join(fixturesDir, "does_not_exist.txt");
var promise = posix.cat(filename, "raw"); var promise = posix.cat(filename, "raw");
promise.addCallback(function (content) { promise.addCallback(function (content) {

6
test/mjsunit/test-fs-sendfile.js

@ -1,9 +1,9 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
tcp = require("/tcp.js"); tcp = require("/tcp.js");
sys = require("/sys.js"); sys = require("/sys.js");
PORT = 23123; PORT = 23123;
var x = node.path.join(fixturesDir, "x.txt"); var x = process.path.join(fixturesDir, "x.txt");
var expected = "xyz"; var expected = "xyz";
var server = tcp.createServer(function (socket) { var server = tcp.createServer(function (socket) {
@ -19,7 +19,7 @@ server.listen(PORT);
var client = tcp.createConnection(PORT); var client = tcp.createConnection(PORT);
client.addListener("connect", function () { client.addListener("connect", function () {
posix.open(x,node.O_RDONLY, 0666).addCallback(function (fd) { posix.open(x,process.O_RDONLY, 0666).addCallback(function (fd) {
posix.sendfile(client.fd, fd, 0, expected.length).addCallback(function (size) { posix.sendfile(client.fd, fd, 0, expected.length).addCallback(function (size) {
assertEquals(expected.length, size); assertEquals(expected.length, size);
}); });

2
test/mjsunit/test-fs-stat.js

@ -1,4 +1,4 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
var got_error = false; var got_error = false;
var success_count = 0; var success_count = 0;

8
test/mjsunit/test-fs-write.js

@ -1,13 +1,13 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
var path = node.path.join(fixturesDir, "write.txt"); var path = process.path.join(fixturesDir, "write.txt");
var expected = "hello"; var expected = "hello";
var found; var found;
posix.open(path, node.O_WRONLY | node.O_TRUNC | node.O_CREAT, 0644).addCallback(function (file) { posix.open(path, process.O_WRONLY | process.O_TRUNC | process.O_CREAT, 0644).addCallback(function (file) {
posix.write(file, expected, 0, "utf8").addCallback(function() { posix.write(file, expected, 0, "utf8").addCallback(function() {
posix.close(file).addCallback(function() { posix.close(file).addCallback(function() {
posix.cat(path, node.UTF8).addCallback(function(contents) { posix.cat(path, process.UTF8).addCallback(function(contents) {
found = contents; found = contents;
posix.unlink(path).wait(); posix.unlink(path).wait();
}); });

2
test/mjsunit/test-http-cat.js

@ -1,4 +1,4 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
http = require("/http.js"); http = require("/http.js");
PORT = 8888; PORT = 8888;

2
test/mjsunit/test-http-client-race.js

@ -1,4 +1,4 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
http = require("/http.js"); http = require("/http.js");
PORT = 8888; PORT = 8888;

2
test/mjsunit/test-http-client-upload.js

@ -1,4 +1,4 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
http = require("/http.js"); http = require("/http.js");
var PORT = 18032; var PORT = 18032;

2
test/mjsunit/test-http-malformed-request.js

@ -1,4 +1,4 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
tcp = require("/tcp.js"); tcp = require("/tcp.js");
http = require("/http.js"); http = require("/http.js");

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

@ -1,4 +1,4 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
http = require("/http.js"); http = require("/http.js");
var PROXY_PORT = 8869; var PROXY_PORT = 8869;

2
test/mjsunit/test-http-server.js

@ -1,4 +1,4 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
tcp = require("/tcp.js"); tcp = require("/tcp.js");
http = require("/http.js"); http = require("/http.js");

2
test/mjsunit/test-http.js

@ -1,4 +1,4 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
http = require("/http.js"); http = require("/http.js");
PORT = 8888; PORT = 8888;

8
test/mjsunit/test-mkdir-rmdir.js

@ -1,8 +1,8 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
var dirname = node.path.dirname(__filename); var dirname = process.path.dirname(__filename);
var fixtures = node.path.join(dirname, "fixtures"); var fixtures = process.path.join(dirname, "fixtures");
var d = node.path.join(fixtures, "dir"); var d = process.path.join(fixtures, "dir");
var mkdir_error = false; var mkdir_error = false;
var rmdir_error = false; var rmdir_error = false;

2
test/mjsunit/test-module-loading.js

@ -1,4 +1,4 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
debug("load test-module-loading.js"); debug("load test-module-loading.js");

2
test/mjsunit/test-multipart.js

@ -1,4 +1,4 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
http = require("/http.js"); http = require("/http.js");
var multipart = require('/multipart.js'); var multipart = require('/multipart.js');

4
test/mjsunit/test-process-buffering.js

@ -1,10 +1,10 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
var pwd_called = false; var pwd_called = false;
function pwd (callback) { function pwd (callback) {
var output = ""; var output = "";
var child = node.createChildProcess("pwd"); var child = process.createChildProcess("pwd");
child.addListener("output", function (s) { child.addListener("output", function (s) {
puts("stdout: " + JSON.stringify(s)); puts("stdout: " + JSON.stringify(s));
if (s) output += s; if (s) output += s;

4
test/mjsunit/test-process-kill.js

@ -1,8 +1,8 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
var exit_status = -1; var exit_status = -1;
var cat = node.createChildProcess("cat"); var cat = process.createChildProcess("cat");
cat.addListener("output", function (chunk) { assertEquals(null, chunk); }); cat.addListener("output", function (chunk) { assertEquals(null, chunk); });
cat.addListener("error", function (chunk) { assertEquals(null, chunk); }); cat.addListener("error", function (chunk) { assertEquals(null, chunk); });

4
test/mjsunit/test-process-simple.js

@ -1,6 +1,6 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
var cat = node.createChildProcess("cat"); var cat = process.createChildProcess("cat");
var response = ""; var response = "";
var exit_status = -1; var exit_status = -1;

4
test/mjsunit/test-process-spawn-loop.js

@ -1,10 +1,10 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
var N = 40; var N = 40;
var finished = false; var finished = false;
function spawn (i) { function spawn (i) {
var child = node.createChildProcess( 'python' var child = process.createChildProcess( 'python'
, ['-c', 'print 500 * 1024 * "C"'] , ['-c', 'print 500 * 1024 * "C"']
); );
var output = ""; var output = "";

14
test/mjsunit/test-promise-timeout.js

@ -1,8 +1,8 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
var timeouts = 0; var timeouts = 0;
var promise = new node.Promise(); var promise = new process.Promise();
promise.timeout(250); promise.timeout(250);
assertEquals(250, promise.timeout()); assertEquals(250, promise.timeout());
@ -20,7 +20,7 @@ setTimeout(function() {
promise.emitSuccess('Am I too late?'); promise.emitSuccess('Am I too late?');
}, 500); }, 500);
var waitPromise = new node.Promise(); var waitPromise = new process.Promise();
try { try {
waitPromise.timeout(250).wait() waitPromise.timeout(250).wait()
} catch (e) { } catch (e) {
@ -29,7 +29,7 @@ try {
timeouts++; timeouts++;
} }
var successPromise = new node.Promise(); var successPromise = new process.Promise();
successPromise.timeout(500); successPromise.timeout(500);
setTimeout(function() { setTimeout(function() {
successPromise.emitSuccess(); successPromise.emitSuccess();
@ -39,7 +39,7 @@ successPromise.addErrback(function() {
assertUnreachable('addErrback should not fire if there is no timeout'); assertUnreachable('addErrback should not fire if there is no timeout');
}); });
var errorPromise = new node.Promise(); var errorPromise = new process.Promise();
errorPromise.timeout(500); errorPromise.timeout(500);
setTimeout(function() { setTimeout(function() {
errorPromise.emitError(new Error('intentional')); errorPromise.emitError(new Error('intentional'));
@ -50,7 +50,7 @@ errorPromise.addErrback(function(e) {
assertEquals('intentional', e.message); assertEquals('intentional', e.message);
}); });
var cancelPromise = new node.Promise(); var cancelPromise = new process.Promise();
cancelPromise.timeout(500); cancelPromise.timeout(500);
setTimeout(function() { setTimeout(function() {
cancelPromise.cancel(); cancelPromise.cancel();
@ -68,7 +68,7 @@ cancelPromise.addErrback(function(e) {
assertUnreachable('addErrback should not fire if the promise is canceled'); assertUnreachable('addErrback should not fire if the promise is canceled');
}); });
var cancelTimeoutPromise = new node.Promise(); var cancelTimeoutPromise = new process.Promise();
cancelTimeoutPromise.timeout(500); cancelTimeoutPromise.timeout(500);
setTimeout(function() { setTimeout(function() {
cancelPromise.emitCancel(); cancelPromise.emitCancel();

12
test/mjsunit/test-promise-wait.js

@ -1,7 +1,7 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
var p1_done = false; var p1_done = false;
var p1 = new node.Promise(); var p1 = new process.Promise();
p1.addCallback(function () { p1.addCallback(function () {
assertEquals(1, arguments.length); assertEquals(1, arguments.length);
assertEquals("single arg", arguments[0]); assertEquals("single arg", arguments[0]);
@ -9,7 +9,7 @@ p1.addCallback(function () {
}); });
var p2_done = false; var p2_done = false;
var p2 = new node.Promise(); var p2 = new process.Promise();
p2.addCallback(function () { p2.addCallback(function () {
p2_done = true; p2_done = true;
setTimeout(function () { setTimeout(function () {
@ -18,7 +18,7 @@ p2.addCallback(function () {
}); });
var p3_done = false; var p3_done = false;
var p3 = new node.Promise(); var p3 = new process.Promise();
p3.addCallback(function () { p3.addCallback(function () {
p3_done = true; p3_done = true;
}); });
@ -26,7 +26,7 @@ p3.addCallback(function () {
var p4_done = false; var p4_done = false;
var p4 = new node.Promise(); var p4 = new process.Promise();
p4.addCallback(function () { p4.addCallback(function () {
assertEquals(3, arguments.length); assertEquals(3, arguments.length);
assertEquals("a", arguments[0]); assertEquals("a", arguments[0]);
@ -36,7 +36,7 @@ p4.addCallback(function () {
}); });
var p5_done = false; var p5_done = false;
var p5 = new node.Promise(); var p5 = new process.Promise();
p5.addCallback(function () { p5.addCallback(function () {
p5_done = true; p5_done = true;
setTimeout(function () { setTimeout(function () {

2
test/mjsunit/test-readdir.js

@ -1,4 +1,4 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
var got_error = false; var got_error = false;

4
test/mjsunit/test-signal-handler.js

@ -1,4 +1,4 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
puts("process.pid: " + process.pid); puts("process.pid: " + process.pid);
@ -23,7 +23,7 @@ setInterval(function () {
puts("running process..." + ++i); puts("running process..." + ++i);
if (i == 5) { if (i == 5) {
node.kill(process.pid, "SIGUSR1"); process.kill(process.pid, "SIGUSR1");
} }
}, 1); }, 1);

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

@ -1,4 +1,4 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
tcp = require("/tcp.js"); tcp = require("/tcp.js");
PORT = 23123; PORT = 23123;
@ -14,8 +14,8 @@ for (var i = 255; i >= 0; i--) {
+ " " + " "
+ S.charCodeAt(0) + S.charCodeAt(0)
); );
node.assert(S.charCodeAt(0) == i); process.assert(S.charCodeAt(0) == i);
node.assert(S == String.fromCharCode(i)); process.assert(S == String.fromCharCode(i));
binaryString += S; binaryString += S;
} }

2
test/mjsunit/test-tcp-many-clients.js

@ -1,4 +1,4 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
tcp = require("/tcp.js"); tcp = require("/tcp.js");
// settings // settings
var port = 20743; var port = 20743;

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

@ -1,4 +1,4 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
tcp = require("/tcp.js"); tcp = require("/tcp.js");

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

@ -1,4 +1,4 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
tcp = require("/tcp.js"); tcp = require("/tcp.js");

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

@ -1,4 +1,4 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
tcp = require("/tcp.js"); tcp = require("/tcp.js");
var N = 50; var N = 50;
var port = 8921; var port = 8921;

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

@ -1,4 +1,4 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
tcp = require("/tcp.js"); tcp = require("/tcp.js");
PORT = 20444; PORT = 20444;
N = 30*1024; // 500kb N = 30*1024; // 500kb

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

@ -1,4 +1,4 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
tcp = require("/tcp.js"); tcp = require("/tcp.js");
PORT = 20443; PORT = 20443;
N = 200; N = 200;

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

@ -1,4 +1,4 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
tcp = require("/tcp.js"); tcp = require("/tcp.js");
port = 9992; port = 9992;
exchanges = 0; exchanges = 0;

2
test/mjsunit/test-timers.js

@ -1,4 +1,4 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
var WINDOW = 200; // why is does this need to be so big? var WINDOW = 200; // why is does this need to be so big?

2
test/mjsunit/test-utf8-scripts.js

@ -1,4 +1,4 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
// üäö // üäö

4
test/mjsunit/test-wait-ordering.js

@ -1,7 +1,7 @@
node.mixin(require("common.js")); process.mixin(require("common.js"));
function timer (t) { function timer (t) {
var promise = new node.Promise(); var promise = new process.Promise();
setTimeout(function () { setTimeout(function () {
promise.emitSuccess(); promise.emitSuccess();
}, t); }, t);

Loading…
Cancel
Save