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. 79
      src/node.cc
  16. 140
      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);
node.mixin(require("/utils.js"));
process.mixin(require("/utils.js"));
http = require("/http.js");
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);
node.mixin(require("/utils.js"));
process.mixin(require("/utils.js"));
function next (i) {
if (i <= 0) return;
var child = node.createChildProcess("echo", ["hello"]);
var child = process.createChildProcess("echo", ["hello"]);
child.addListener("output", function (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);
node.mixin(require("/utils.js"));
process.mixin(require("/utils.js"));
var benchmarks = [ "static_http_server.js"
, "timers.js"
, "process_loop.js"
];
var benchmark_dir = node.path.dirname(__filename);
var benchmark_dir = process.path.dirname(__filename);
function exec (script, callback) {
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) {
var elapsed = new Date() - start;
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);
http = require("/http.js");
var concurrency = 30;

117
doc/api.txt

@ -46,53 +46,35 @@ Unless otherwise noted, functions are all asynchronous and do not block
execution.
=== Helpers
=== Global Objects
These objects are available to all programs.
+GLOBAL+ ::
The global namespace object.
+node.cwd()+::
Returns the current working directory of the process.
+process+ ::
The process object. Most stuff lives in here. See the "process object"
section.
+node.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.
+require(path)+ ::
See the modules section.
+node.compile(source, scriptOrigin)+::
Just like +eval()+ except that you can specify a +scriptOrigin+ for better
error reporting.
+require.paths+ ::
The search path for absolute path arguments to +require()+.
+__filename+ ::
The filename of the script being executed.
+__module+ ::
A reference to the current module (of type +node.Module+). In particular
+__module.exports+ is the same as the +exports+ object. See +src/node.js+ for
A reference to the current module (of type +process.Module+). In particular
+__module.exports+ is the same as the +exports+ object. See +src/process.js+ for
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
+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"]
|=========================================================
@ -111,10 +93,6 @@ the global scope. +process+ is an instance of +node.EventEmitter+.
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+ ::
An array containing the command line arguments.
@ -124,6 +102,35 @@ An object containing the user environment. See environ(7).
+process.pid+ ::
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
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
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:
+"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
complete.
==== +node.EventEmitter+
==== +process.EventEmitter+
All EventEmitters emit the event +"newListener"+ when new listeners are
added.
@ -204,9 +211,9 @@ manipulated, e.g. to remove listeners.
+emitter.emit(event, arg1, arg2, ...)+ ::
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
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.
+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.
+
(+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 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
synchronous.
@ -303,22 +310,22 @@ synchronous.
| +"data"+ | +data+ | Made when stdin has received a chunk of data.
Depending on the encoding that stdin was opened
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.
| +"close"+ | | Made when stdin has been closed.
|=========================================================
+node.stdio.open(encoding="utf8")+::
Open stdin. The program will not exit until +node.stdio.close()+ has been
+process.stdio.open(encoding="utf8")+::
Open stdin. The program will not exit until +process.stdio.close()+ has been
called or the +"close"+ event has been emitted.
+node.stdio.write(data)+::
+process.stdio.write(data)+::
Write data to stdout.
+node.stdio.writeError(data)+::
+process.stdio.writeError(data)+::
Write data to stderr. Synchronous.
+node.stdio.close()+::
+process.stdio.close()+::
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
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));
----------------------------------------
@ -418,10 +425,10 @@ Stops a interval from triggering.
=== Child Processes
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.
==== +node.ChildProcess+
==== +process.ChildProcess+
[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.
|=========================================================
+node.createChildProcess(command, args=[], env=ENV)+::
+process.createChildProcess(command, args=[], env=ENV)+::
Launches a new process with the given +command+, command line arguments, and
environmental variables. For example:
+
----------------------------------------
var ls = node.createChildProcess("ls", ["-lh", "/usr"]);
var ls = process.createChildProcess("ls", ["-lh", "/usr"]);
ls.addListener("output", function (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")+.
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"),
@ -574,7 +581,7 @@ sys.puts("stats: " + JSON.stringify(stats));
+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 error: no parameters.

26
lib/file.js

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

30
lib/http.js

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

10
lib/multipart.js

@ -1,6 +1,6 @@
exports.parse = function(options) {
var stream = new exports.Stream(options);
var promise = new node.Promise();
var promise = new process.Promise();
var parts = {};
stream.addListener('part', function(part) {
@ -24,11 +24,11 @@ exports.parse = function(options) {
};
exports.Stream = function(options) {
node.EventEmitter.call(this);
process.EventEmitter.call(this);
this.init(options);
};
node.inherits(exports.Stream, node.EventEmitter);
process.inherits(exports.Stream, process.EventEmitter);
var proto = exports.Stream.prototype;
@ -96,7 +96,7 @@ proto.write = function(chunk) {
};
function Part(stream) {
node.EventEmitter.call(this);
process.EventEmitter.call(this);
this.headers = {};
this.buffer = '';
@ -109,7 +109,7 @@ function Part(stream) {
this._headersComplete = false;
}
node.inherits(Part, node.EventEmitter);
process.inherits(Part, process.EventEmitter);
Part.prototype.parsedHeaders = function() {
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);
};
node.fs.Stats.prototype.isDirectory = function () {
return this._checkModeProperty(node.S_IFDIR);
process.fs.Stats.prototype.isDirectory = function () {
return this._checkModeProperty(process.S_IFDIR);
};
node.fs.Stats.prototype.isFile = function () {
return this._checkModeProperty(node.S_IFREG);
process.fs.Stats.prototype.isFile = function () {
return this._checkModeProperty(process.S_IFREG);
};
node.fs.Stats.prototype.isBlockDevice = function () {
return this._checkModeProperty(node.S_IFBLK);
process.fs.Stats.prototype.isBlockDevice = function () {
return this._checkModeProperty(process.S_IFBLK);
};
node.fs.Stats.prototype.isCharacterDevice = function () {
return this._checkModeProperty(node.S_IFCHR);
process.fs.Stats.prototype.isCharacterDevice = function () {
return this._checkModeProperty(process.S_IFCHR);
};
node.fs.Stats.prototype.isSymbolicLink = function () {
return this._checkModeProperty(node.S_IFLNK);
process.fs.Stats.prototype.isSymbolicLink = function () {
return this._checkModeProperty(process.S_IFLNK);
};
node.fs.Stats.prototype.isFIFO = function () {
return this._checkModeProperty(node.S_IFIFO);
process.fs.Stats.prototype.isFIFO = function () {
return this._checkModeProperty(process.S_IFIFO);
};
node.fs.Stats.prototype.isSocket = function () {
return this._checkModeProperty(node.S_IFSOCK);
process.fs.Stats.prototype.isSocket = function () {
return this._checkModeProperty(process.S_IFSOCK);
};
for (var key in node.fs) {
if (node.fs.hasOwnProperty(key)) exports[key] = node.fs[key];
for (var key in process.fs) {
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;
}
node.stdio.open();
node.stdio.addListener("data", readline);
process.stdio.open();
process.stdio.addListener("data", readline);
displayPrompt();
}
@ -97,7 +97,7 @@ function parseREPLKeyword (cmd) {
displayPrompt();
return true;
case ".exit":
node.stdio.close();
process.stdio.close();
return true;
case ".help":
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) {
node.stdio.write(x);
process.stdio.write(x);
};
exports.puts = function (x) {
node.stdio.write(x.toString() + "\n");
process.stdio.write(x.toString() + "\n");
};
exports.debug = function (x) {
node.stdio.writeError("DEBUG: " + x.toString() + "\n");
process.stdio.writeError("DEBUG: " + x.toString() + "\n");
};
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) {
var child = node.createChildProcess("/bin/sh", ["-c", command]);
var child = process.createChildProcess("/bin/sh", ["-c", command]);
var stdout = "";
var stderr = "";
var promise = new node.Promise();
var promise = new process.Promise();
child.addListener("output", function (chunk) {
if (chunk) stdout += chunk;

4
lib/tcp.js

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

22
src/events.js

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

14
src/file.js

@ -1,19 +1,19 @@
node.fs.exists = function (path, callback) {
var p = node.fs.stat(path);
process.fs.exists = function (path, callback) {
var p = process.fs.stat(path);
p.addCallback(function () { callback(true); });
p.addErrback(function () { callback(false); });
};
node.fs.cat = function (path, encoding) {
var promise = new node.Promise();
process.fs.cat = function (path, encoding) {
var promise = new process.Promise();
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;
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.constructor === String) {
content += chunk;
@ -25,7 +25,7 @@ node.fs.cat = function (path, encoding) {
readChunk();
} else {
promise.emitSuccess(content);
node.fs.close(fd);
process.fs.close(fd);
}
}).addErrback(function () {
promise.emitError();

79
src/node.cc

@ -31,6 +31,8 @@ extern char **environ;
namespace node {
static Persistent<Object> process;
static int dash_dash_index = 0;
static bool use_debug_agent = false;
@ -267,10 +269,8 @@ v8::Handle<v8::Value> Kill(const v8::Arguments& args) {
sig = args[1]->Int32Value();
} else if (args[1]->IsString()) {
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()) {
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[]) {
HandleScope scope;
// Reference to 'process'
Local<Object> process = Context::GetCurrent()->Global();
Local<FunctionTemplate> process_template = FunctionTemplate::New();
node::EventEmitter::Initialize(process_template);
process = Persistent<Object>::New(process_template->GetFunction()->NewInstance());
Local<Object> node_obj = Object::New(); // Create the 'process.node' object
process->Set(String::NewSymbol("node"), node_obj); // and assign it.
// Assign the process object to its place.
Local<Object> global = Context::GetCurrent()->Global();
global->Set(String::NewSymbol("process"), process);
// node.version
node_obj->Set(String::NewSymbol("version"), String::New(NODE_VERSION));
process->Set(String::NewSymbol("version"), String::New(NODE_VERSION));
// node.installPrefix
node_obj->Set(String::NewSymbol("installPrefix"), String::New(NODE_PREFIX));
process->Set(String::NewSymbol("installPrefix"), String::New(NODE_PREFIX));
// process.ARGV
int i, j;
@ -460,40 +463,40 @@ static Local<Object> Load(int argc, char *argv[]) {
process->Set(String::NewSymbol("pid"), Integer::New(getpid()));
// define various internal methods
NODE_SET_METHOD(node_obj, "compile", Compile);
NODE_SET_METHOD(node_obj, "reallyExit", Exit);
NODE_SET_METHOD(node_obj, "cwd", Cwd);
NODE_SET_METHOD(node_obj, "dlopen", DLOpen);
NODE_SET_METHOD(node_obj, "kill", Kill);
NODE_SET_METHOD(process, "compile", Compile);
NODE_SET_METHOD(process, "reallyExit", Exit);
NODE_SET_METHOD(process, "cwd", Cwd);
NODE_SET_METHOD(process, "dlopen", DLOpen);
NODE_SET_METHOD(process, "kill", Kill);
// Assign the EventEmitter. It was created in main().
node_obj->Set(String::NewSymbol("EventEmitter"),
EventEmitter::constructor_template->GetFunction());
process->Set(String::NewSymbol("EventEmitter"),
EventEmitter::constructor_template->GetFunction());
// Initialize the C++ modules..................filename of module
Promise::Initialize(node_obj); // events.cc
Stdio::Initialize(node_obj); // stdio.cc
Timer::Initialize(node_obj); // timer.cc
SignalHandler::Initialize(node_obj); // signal_handler.cc
ChildProcess::Initialize(node_obj); // child_process.cc
DefineConstants(node_obj); // constants.cc
Promise::Initialize(process); // events.cc
Stdio::Initialize(process); // stdio.cc
Timer::Initialize(process); // timer.cc
SignalHandler::Initialize(process); // signal_handler.cc
ChildProcess::Initialize(process); // child_process.cc
DefineConstants(process); // constants.cc
// Create node.dns
Local<Object> dns = Object::New();
node_obj->Set(String::NewSymbol("dns"), dns);
process->Set(String::NewSymbol("dns"), dns);
DNS::Initialize(dns); // dns.cc
Local<Object> fs = Object::New();
node_obj->Set(String::NewSymbol("fs"), fs);
process->Set(String::NewSymbol("fs"), fs);
File::Initialize(fs); // file.cc
// Create node.tcp. Note this separate from lib/tcp.js which is the public
// frontend.
Local<Object> tcp = Object::New();
node_obj->Set(String::New("tcp"), tcp);
process->Set(String::New("tcp"), tcp);
Server::Initialize(tcp); // tcp.cc
Connection::Initialize(tcp); // tcp.cc
// Create node.http. Note this separate from lib/http.js which is the
// public frontend.
Local<Object> http = Object::New();
node_obj->Set(String::New("http"), http);
process->Set(String::New("http"), http);
HTTPServer::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]
// so your next reading stop should be node.js!
ExecuteNativeJS("node.js", native_node);
return scope.Close(node_obj);
}
static void EmitExitEvent() {
HandleScope scope;
// Get reference to 'process' object.
Local<Object> process = Context::GetCurrent()->Global();
// Get the 'emit' function from it.
// Get the 'emit' function from 'process'
Local<Value> emit_v = process->Get(String::NewSymbol("emit"));
if (!emit_v->IsFunction()) {
// 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");
}
// Create the global 'process' object's FunctionTemplate.
Local<FunctionTemplate> process_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 'GLOBAL' object's FunctionTemplate.
Local<FunctionTemplate> global_template = FunctionTemplate::New();
// Create the one and only Context.
Persistent<Context> context = Context::New(NULL,
process_template->InstanceTemplate());
global_template->InstanceTemplate());
Context::Scope context_scope(context);
// Actually assign the global object to it's place as 'process'
context->Global()->Set(String::NewSymbol("process"), context->Global());
// Actually assign the global object to it's place as 'GLOBAL'
context->Global()->Set(String::NewSymbol("GLOBAL"), context->Global());
// Create all the objects, load modules, do everything.
// 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
// might even have created TCP servers. Now we enter the main event loop.

140
src/node.js

@ -1,13 +1,13 @@
node.tcp.createServer = function () {
throw new Error("node.tcp.createServer() has moved. Use require('/tcp.js') to access it.");
process.tcp.createServer = function () {
throw new Error("process.tcp.createServer() has moved. Use require('/tcp.js') to access it.");
};
node.createProcess = function () {
throw "node.createProcess() has been changed to node.createChildProcess() update your code";
process.createProcess = function () {
throw "process.createProcess() has been changed to process.createChildProcess() update your code";
};
node.createChildProcess = function (file, args, env) {
var child = new node.ChildProcess();
process.createChildProcess = function (file, args, env) {
var child = new process.ChildProcess();
args = args || [];
env = env || process.ENV;
var envPairs = [];
@ -23,24 +23,24 @@ node.createChildProcess = function (file, args, env) {
return child;
};
node.exec = function () {
throw new Error("node.exec() has moved. Use require('/sys.js') to bring it back.");
process.exec = function () {
throw new Error("process.exec() has moved. Use require('/sys.js') to bring it back.");
}
node.http.createServer = function () {
throw new Error("node.http.createServer() has moved. Use require('/http.js') to access it.");
process.http.createServer = function () {
throw new Error("process.http.createServer() has moved. Use require('/http.js') to access it.");
}
node.http.createClient = function () {
throw new Error("node.http.createClient() has moved. Use require('/http.js') to access it.");
process.http.createClient = function () {
throw new Error("process.http.createClient() has moved. Use require('/http.js') to access it.");
}
node.tcp.createConnection = function (port, host) {
throw new Error("node.tcp.createConnection() has moved. Use require('/tcp.js') to access it.");
process.tcp.createConnection = function (port, host) {
throw new Error("process.tcp.createConnection() has moved. Use require('/tcp.js') to access it.");
};
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
@ -48,7 +48,7 @@ include = function () {
* Dual licensed under the MIT and GPL licenses.
* http://docs.jquery.com/License
*/
node.mixin = function() {
process.mixin = function() {
// copy reference to target object
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)
if ( typeof target !== "object" && !node.isFunction(target) )
if ( typeof target !== "object" && !process.isFunction(target) )
target = {};
// mixin process itself if only one argument is passed
if ( length == i ) {
target = process;
target = GLOBAL;
--i;
}
@ -83,7 +83,7 @@ node.mixin = function() {
// Recurse if we're merging object values
if ( deep && copy && typeof copy === "object" && !copy.nodeType )
target[ name ] = node.mixin( deep,
target[ name ] = process.mixin( deep,
// Never move original objects, clone them
src || ( copy.length != null ? [ ] : { } )
, copy );
@ -103,12 +103,12 @@ node.mixin = function() {
(function () { // anonymous namespace
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) {
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 () {
process.emit(event);
});
@ -120,14 +120,14 @@ node.mixin = function() {
// Timers
function setTimeout (callback, after) {
var timer = new node.Timer();
var timer = new process.Timer();
timer.addListener("timeout", callback);
timer.start(after, 0);
return timer;
}
function setInterval (callback, repeat) {
var timer = new node.Timer();
var timer = new process.Timer();
timer.addListener("timeout", callback);
timer.start(repeat, repeat);
return timer;
@ -141,18 +141,18 @@ clearInterval = clearTimeout;
// Module
node.libraryPaths = [ node.path.join(ENV["HOME"], ".node_libraries")
, node.path.join(node.installPrefix, "lib/node/libraries")
, "/"
];
process.libraryPaths = [ process.path.join(process.ENV["HOME"], ".node_libraries")
, process.path.join(process.installPrefix, "lib/node/libraries")
, "/"
];
if (ENV["NODE_LIBRARY_PATHS"]) {
node.libraryPaths =
ENV["NODE_LIBRARY_PATHS"].split(":").concat(node.libraryPaths);
if (process.ENV["NODE_LIBRARY_PATHS"]) {
process.libraryPaths =
process.ENV["NODE_LIBRARY_PATHS"].split(":").concat(process.libraryPaths);
}
node.Module = function (filename, parent) {
node.assert(filename.charAt(0) == "/");
process.Module = function (filename, parent) {
process.assert(filename.charAt(0) == "/");
this.filename = filename;
this.exports = {};
this.parent = parent;
@ -163,26 +163,26 @@ node.Module = function (filename, parent) {
this.children = [];
};
node.Module.cache = {};
process.Module.cache = {};
(function () {
function retrieveFromCache (loadPromise, fullPath, parent) {
var module;
if (fullPath in node.Module.cache) {
module = node.Module.cache[fullPath];
if (fullPath in process.Module.cache) {
module = process.Module.cache[fullPath];
setTimeout(function () {
loadPromise.emitSuccess(module.exports);
}, 0);
} else {
module = new node.Module(fullPath, parent);
node.Module.cache[fullPath] = module;
module = new process.Module(fullPath, parent);
process.Module.cache[fullPath] = module;
module.load(loadPromise);
}
}
function findPath (path, dirs, callback) {
node.assert(path.charAt(0) == "/");
node.assert(dirs.constructor == Array);
process.assert(path.charAt(0) == "/");
process.assert(dirs.constructor == Array);
if (dirs.length == 0) {
callback();
@ -190,8 +190,8 @@ node.Module.cache = {};
var dir = dirs[0];
var rest = dirs.slice(1, dirs.length);
var fullPath = node.path.join(dir, path);
node.fs.exists(fullPath, function (doesExist) {
var fullPath = process.path.join(dir, path);
process.fs.exists(fullPath, function (doesExist) {
if (doesExist) {
callback(fullPath);
} else {
@ -201,8 +201,8 @@ node.Module.cache = {};
}
}
node.loadModule = function (requestedPath, exports, parent) {
var loadPromise = new node.Promise();
process.loadModule = function (requestedPath, exports, parent) {
var loadPromise = new process.Promise();
// On success copy the loaded properties into the exports
loadPromise.addCallback(function (t) {
@ -212,19 +212,19 @@ node.Module.cache = {};
});
loadPromise.addErrback(function (e) {
node.stdio.writeError(e.message + "\n");
process.stdio.writeError(e.message + "\n");
process.exit(1);
});
if (!parent) {
// root module
node.assert(requestedPath.charAt(0) == "/");
process.assert(requestedPath.charAt(0) == "/");
retrieveFromCache(loadPromise, requestedPath);
} else {
if (requestedPath.charAt(0) == "/") {
// Need to find the module in node.libraryPaths
findPath(requestedPath, node.libraryPaths, function (fullPath) {
// Need to find the module in process.libraryPaths
findPath(requestedPath, process.libraryPaths, function (fullPath) {
if (fullPath) {
retrieveFromCache(loadPromise, fullPath, parent);
} else {
@ -234,7 +234,7 @@ node.Module.cache = {};
} else {
// Relative file load
var fullPath = node.path.join(node.path.dirname(parent.filename),
var fullPath = process.path.join(process.path.dirname(parent.filename),
requestedPath);
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) {
loadPromise.emitError(new Error("Module '" + self.filename + "' is already loaded."));
return;
}
node.assert(!node.loadPromise);
process.assert(!process.loadPromise);
this.loadPromise = loadPromise;
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;
// XXX Not yet supporting loading from HTTP. would need to download the
// 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) {
self.loaded = true;
node.dlopen(self.filename, self.exports); // FIXME synchronus
process.dlopen(self.filename, self.exports); // FIXME synchronus
loadPromise.emitSuccess(self.exports);
} else {
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 catPromise = node.cat(self.filename);
var catPromise = process.cat(self.filename);
catPromise.addErrback(function () {
loadPromise.emitError(new Error("Error reading " + self.filename));
@ -294,14 +294,14 @@ node.Module.prototype.loadScript = function (loadPromise) {
return requireAsync(url).wait();
}
require.paths = node.libraryPaths;
require.paths = process.libraryPaths;
require.async = requireAsync;
// create wrapper function
var wrapper = "var __wrap__ = function (__module, __filename, exports, require) { "
+ content
+ "\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]);
@ -312,11 +312,11 @@ node.Module.prototype.loadScript = function (loadPromise) {
});
};
node.Module.prototype.newChild = function (path) {
return node.loadModule(path, {}, this);
process.Module.prototype.newChild = function (path) {
return process.loadModule(path, {}, this);
};
node.Module.prototype.waitChildrenLoad = function (callback) {
process.Module.prototype.waitChildrenLoad = function (callback) {
var nloaded = 0;
var children = this.children;
for (var i = 0; i < children.length; i++) {
@ -336,25 +336,21 @@ node.Module.prototype.waitChildrenLoad = function (callback) {
process.exit = function (code) {
process.emit("exit");
node.reallyExit(code);
};
node.exit = function (code) {
throw new Error("node.exit() has been renamed to process.exit().");
process.reallyExit(code);
};
(function () {
var cwd = node.cwd();
var cwd = process.cwd();
// Make ARGV[0] and ARGV[1] into full paths.
if (ARGV[0].charAt(0) != "/") {
ARGV[0] = node.path.join(cwd, ARGV[0]);
// Make process.ARGV[0] and process.ARGV[1] into full paths.
if (process.ARGV[0].charAt(0) != "/") {
process.ARGV[0] = process.path.join(cwd, process.ARGV[0]);
}
if (ARGV[1].charAt(0) != "/") {
ARGV[1] = node.path.join(cwd, ARGV[1]);
if (process.ARGV[1].charAt(0) != "/") {
process.ARGV[1] = process.path.join(cwd, process.ARGV[1]);
}
// 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
* @param {function} superCtor Constructor function to inherit prototype from
*/
node.inherits = function (ctor, superCtor) {
process.inherits = function (ctor, superCtor) {
var tempCtor = function(){};
tempCtor.prototype = superCtor.prototype;
ctor.super_ = superCtor.prototype;
@ -19,21 +19,21 @@ node.inherits = function (ctor, superCtor) {
ctor.prototype.constructor = ctor;
};
node.assert = function (x, msg) {
process.assert = function (x, msg) {
if (!(x)) throw new Error(msg || "assertion error");
};
node.cat = function(location, encoding) {
process.cat = function(location, encoding) {
var url_re = new RegExp("^http:\/\/");
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 node.fs.cat(location, encoding);
return process.fs.cat(location, encoding);
};
node.path = new function () {
process.path = new function () {
this.join = function () {
var joined = "";
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.");
}
node.debug = function () {
throw new Error("node.debug() has moved. Use require('/sys.js') to bring it back.");
process.debug = function () {
throw new Error("process.debug() has moved. Use require('/sys.js') to bring it back.");
}
node.error = function () {
throw new Error("node.error() has moved. Use require('/sys.js') to bring it back.");
process.error = function () {
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.fixturesDir = node.path.join(exports.testDir, "fixtures");
exports.libDir = node.path.join(exports.testDir, "../../lib");
exports.testDir = process.path.dirname(__filename);
exports.fixturesDir = process.path.join(exports.testDir, "fixtures");
exports.libDir = process.path.join(exports.testDir, "../../lib");
require.paths.unshift(exports.libDir);
var mjsunit = require("/mjsunit.js");
var utils = require("/utils.js");
node.mixin(exports, mjsunit, utils);
process.mixin(exports, mjsunit, utils);
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);
node.mixin(require("/file.js"));
process.mixin(require("/file.js"));
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 () {
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 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;
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 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");
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");
sys = require("/sys.js");
PORT = 23123;
var x = node.path.join(fixturesDir, "x.txt");
var x = process.path.join(fixturesDir, "x.txt");
var expected = "xyz";
var server = tcp.createServer(function (socket) {
@ -19,7 +19,7 @@ server.listen(PORT);
var client = tcp.createConnection(PORT);
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) {
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 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 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.close(file).addCallback(function() {
posix.cat(path, node.UTF8).addCallback(function(contents) {
posix.cat(path, process.UTF8).addCallback(function(contents) {
found = contents;
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");
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");
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");
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");
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");
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");
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");
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 fixtures = node.path.join(dirname, "fixtures");
var d = node.path.join(fixtures, "dir");
var dirname = process.path.dirname(__filename);
var fixtures = process.path.join(dirname, "fixtures");
var d = process.path.join(fixtures, "dir");
var mkdir_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");

2
test/mjsunit/test-multipart.js

@ -1,4 +1,4 @@
node.mixin(require("common.js"));
process.mixin(require("common.js"));
http = require("/http.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;
function pwd (callback) {
var output = "";
var child = node.createChildProcess("pwd");
var child = process.createChildProcess("pwd");
child.addListener("output", function (s) {
puts("stdout: " + JSON.stringify(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 cat = node.createChildProcess("cat");
var cat = process.createChildProcess("cat");
cat.addListener("output", 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 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 finished = false;
function spawn (i) {
var child = node.createChildProcess( 'python'
var child = process.createChildProcess( 'python'
, ['-c', 'print 500 * 1024 * "C"']
);
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 promise = new node.Promise();
var promise = new process.Promise();
promise.timeout(250);
assertEquals(250, promise.timeout());
@ -20,7 +20,7 @@ setTimeout(function() {
promise.emitSuccess('Am I too late?');
}, 500);
var waitPromise = new node.Promise();
var waitPromise = new process.Promise();
try {
waitPromise.timeout(250).wait()
} catch (e) {
@ -29,7 +29,7 @@ try {
timeouts++;
}
var successPromise = new node.Promise();
var successPromise = new process.Promise();
successPromise.timeout(500);
setTimeout(function() {
successPromise.emitSuccess();
@ -39,7 +39,7 @@ successPromise.addErrback(function() {
assertUnreachable('addErrback should not fire if there is no timeout');
});
var errorPromise = new node.Promise();
var errorPromise = new process.Promise();
errorPromise.timeout(500);
setTimeout(function() {
errorPromise.emitError(new Error('intentional'));
@ -50,7 +50,7 @@ errorPromise.addErrback(function(e) {
assertEquals('intentional', e.message);
});
var cancelPromise = new node.Promise();
var cancelPromise = new process.Promise();
cancelPromise.timeout(500);
setTimeout(function() {
cancelPromise.cancel();
@ -68,7 +68,7 @@ cancelPromise.addErrback(function(e) {
assertUnreachable('addErrback should not fire if the promise is canceled');
});
var cancelTimeoutPromise = new node.Promise();
var cancelTimeoutPromise = new process.Promise();
cancelTimeoutPromise.timeout(500);
setTimeout(function() {
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 = new node.Promise();
var p1 = new process.Promise();
p1.addCallback(function () {
assertEquals(1, arguments.length);
assertEquals("single arg", arguments[0]);
@ -9,7 +9,7 @@ p1.addCallback(function () {
});
var p2_done = false;
var p2 = new node.Promise();
var p2 = new process.Promise();
p2.addCallback(function () {
p2_done = true;
setTimeout(function () {
@ -18,7 +18,7 @@ p2.addCallback(function () {
});
var p3_done = false;
var p3 = new node.Promise();
var p3 = new process.Promise();
p3.addCallback(function () {
p3_done = true;
});
@ -26,7 +26,7 @@ p3.addCallback(function () {
var p4_done = false;
var p4 = new node.Promise();
var p4 = new process.Promise();
p4.addCallback(function () {
assertEquals(3, arguments.length);
assertEquals("a", arguments[0]);
@ -36,7 +36,7 @@ p4.addCallback(function () {
});
var p5_done = false;
var p5 = new node.Promise();
var p5 = new process.Promise();
p5.addCallback(function () {
p5_done = true;
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;

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);
@ -23,7 +23,7 @@ setInterval(function () {
puts("running process..." + ++i);
if (i == 5) {
node.kill(process.pid, "SIGUSR1");
process.kill(process.pid, "SIGUSR1");
}
}, 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");
PORT = 23123;
@ -14,8 +14,8 @@ for (var i = 255; i >= 0; i--) {
+ " "
+ S.charCodeAt(0)
);
node.assert(S.charCodeAt(0) == i);
node.assert(S == String.fromCharCode(i));
process.assert(S.charCodeAt(0) == i);
process.assert(S == String.fromCharCode(i));
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");
// settings
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");

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");

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");
var N = 50;
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");
PORT = 20444;
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");
PORT = 20443;
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");
port = 9992;
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?

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) {
var promise = new node.Promise();
var promise = new process.Promise();
setTimeout(function () {
promise.emitSuccess();
}, t);

Loading…
Cancel
Save