diff --git a/benchmark/http_simple.js b/benchmark/http_simple.js index 43435ad5bc7..ab4955bafa2 100644 --- a/benchmark/http_simple.js +++ b/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 = "" diff --git a/benchmark/process_loop.js b/benchmark/process_loop.js index 494074a9cf9..962ad93a78b 100644 --- a/benchmark/process_loop.js +++ b/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); diff --git a/benchmark/run.js b/benchmark/run.js index 965022b3f9d..820c4e35802 100644 --- a/benchmark/run.js +++ b/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); diff --git a/benchmark/static_http_server.js b/benchmark/static_http_server.js index 18660511060..47e92689c19 100644 --- a/benchmark/static_http_server.js +++ b/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; diff --git a/doc/api.txt b/doc/api.txt index 8f2ce20035a..ea6500a5411 100644 --- a/doc/api.txt +++ b/doc/api.txt @@ -46,29 +46,14 @@ 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. - -+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. - -+node.compile(source, scriptOrigin)+:: -Just like +eval()+ except that you can specify a +scriptOrigin+ for better -error reporting. - -+__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 -more information. ++process+ :: +The process object. Most stuff lives in here. See the "process object" +section. +require(path)+ :: See the modules section. @@ -76,23 +61,20 @@ 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. ++__filename+ :: +The filename of the script being executed. + ++__module+ :: +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. + + === 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. diff --git a/lib/file.js b/lib/file.js index 68758377f77..5565fd17702 100644 --- a/lib/file.js +++ b/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; diff --git a/lib/http.js b/lib/http.js index 0e66c67e628..ff00b2cd187 100644 --- a/lib/http.js +++ b/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"; diff --git a/lib/multipart.js b/lib/multipart.js index e5e125a50d6..851007157f3 100644 --- a/lib/multipart.js +++ b/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) { diff --git a/lib/posix.js b/lib/posix.js index 8dd2b39fcf0..01d09f05c16 100644 --- a/lib/posix.js +++ b/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]; } diff --git a/lib/repl.js b/lib/repl.js index bb76d8c04de..5ca84ecac10 100644 --- a/lib/repl.js +++ b/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."); diff --git a/lib/sys.js b/lib/sys.js index f85bb15fdb2..de98a3b51fa 100644 --- a/lib/sys.js +++ b/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; diff --git a/lib/tcp.js b/lib/tcp.js index f3b8aeaa533..88afad15595 100644 --- a/lib/tcp.js +++ b/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; }; diff --git a/src/events.js b/src/events.js index e26d6de0e6c..58c3538798a 100644 --- a/src/events.js +++ b/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 () { diff --git a/src/file.js b/src/file.js index acd4f13705a..307eee392fc 100644 --- a/src/file.js +++ b/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(); diff --git a/src/node.cc b/src/node.cc index 5daafa8a576..c4731297bf3 100644 --- a/src/node.cc +++ b/src/node.cc @@ -31,6 +31,8 @@ extern char **environ; namespace node { +static Persistent process; + static int dash_dash_index = 0; static bool use_debug_agent = false; @@ -267,10 +269,8 @@ v8::Handle Kill(const v8::Arguments& args) { sig = args[1]->Int32Value(); } else if (args[1]->IsString()) { Local signame = args[1]->ToString(); - Local process = Context::GetCurrent()->Global(); - Local node_obj = process->Get(String::NewSymbol("node"))->ToObject(); - Local sig_v = node_obj->Get(signame); + Local 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 Load(int argc, char *argv[]) { HandleScope scope; - // Reference to 'process' - Local process = Context::GetCurrent()->Global(); + Local process_template = FunctionTemplate::New(); + node::EventEmitter::Initialize(process_template); - Local node_obj = Object::New(); // Create the 'process.node' object - process->Set(String::NewSymbol("node"), node_obj); // and assign it. + process = Persistent::New(process_template->GetFunction()->NewInstance()); + + // Assign the process object to its place. + Local 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 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 dns = Object::New(); - node_obj->Set(String::NewSymbol("dns"), dns); + process->Set(String::NewSymbol("dns"), dns); DNS::Initialize(dns); // dns.cc Local 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 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 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 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 process = Context::GetCurrent()->Global(); - // Get the 'emit' function from it. + // Get the 'emit' function from 'process' Local 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 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 global_template = FunctionTemplate::New(); // Create the one and only Context. Persistent 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 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. diff --git a/src/node.js b/src/node.js index dc55624ba96..50e37c426e9 100644 --- a/src/node.js +++ b/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); }()); diff --git a/src/util.js b/src/util.js index cac5d0ea007..794fe3f374f 100644 --- a/src/util.js +++ b/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."); } diff --git a/test/mjsunit/common.js b/test/mjsunit/common.js index f7d0a955d2d..6f4de7b7ebc 100644 --- a/test/mjsunit/common.js +++ b/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"); diff --git a/test/mjsunit/test-buffered-file.js b/test/mjsunit/test-buffered-file.js index 5d1385abe94..ae02e90cf71 100644 --- a/test/mjsunit/test-buffered-file.js +++ b/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; diff --git a/test/mjsunit/test-delayed-require.js b/test/mjsunit/test-delayed-require.js index 3501bed6f9d..c9f242be84c 100644 --- a/test/mjsunit/test-delayed-require.js +++ b/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"); diff --git a/test/mjsunit/test-event-emitter-add-listeners.js b/test/mjsunit/test-event-emitter-add-listeners.js index 6d42ff7289e..8d323899a27 100644 --- a/test/mjsunit/test-event-emitter-add-listeners.js +++ b/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; diff --git a/test/mjsunit/test-exec.js b/test/mjsunit/test-exec.js index 65702cff103..1f24c4b31bb 100644 --- a/test/mjsunit/test-exec.js +++ b/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; diff --git a/test/mjsunit/test-file-cat-noexist.js b/test/mjsunit/test-file-cat-noexist.js index a34da80b882..30c1e2b5e7e 100644 --- a/test/mjsunit/test-file-cat-noexist.js +++ b/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) { diff --git a/test/mjsunit/test-fs-sendfile.js b/test/mjsunit/test-fs-sendfile.js index 59b48b7fd9d..3a9a1bfbe30 100644 --- a/test/mjsunit/test-fs-sendfile.js +++ b/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); }); diff --git a/test/mjsunit/test-fs-stat.js b/test/mjsunit/test-fs-stat.js index 8b87f439e5c..376d69203cd 100644 --- a/test/mjsunit/test-fs-stat.js +++ b/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; diff --git a/test/mjsunit/test-fs-write.js b/test/mjsunit/test-fs-write.js index e4dbcb9ccc0..6b5906ab705 100644 --- a/test/mjsunit/test-fs-write.js +++ b/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(); }); diff --git a/test/mjsunit/test-http-cat.js b/test/mjsunit/test-http-cat.js index 625d2876742..13deab399b1 100644 --- a/test/mjsunit/test-http-cat.js +++ b/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; diff --git a/test/mjsunit/test-http-client-race.js b/test/mjsunit/test-http-client-race.js index 1fbeff2b924..796c74d86bf 100644 --- a/test/mjsunit/test-http-client-race.js +++ b/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; diff --git a/test/mjsunit/test-http-client-upload.js b/test/mjsunit/test-http-client-upload.js index f24acea9d43..071e00178a1 100644 --- a/test/mjsunit/test-http-client-upload.js +++ b/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; diff --git a/test/mjsunit/test-http-malformed-request.js b/test/mjsunit/test-http-malformed-request.js index ec8bd8846fa..48c3e998c63 100644 --- a/test/mjsunit/test-http-malformed-request.js +++ b/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"); diff --git a/test/mjsunit/test-http-proxy.js b/test/mjsunit/test-http-proxy.js index c1024b1e0a0..508d2030780 100644 --- a/test/mjsunit/test-http-proxy.js +++ b/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; diff --git a/test/mjsunit/test-http-server.js b/test/mjsunit/test-http-server.js index 62a72fb9a7a..d28b3d924a7 100644 --- a/test/mjsunit/test-http-server.js +++ b/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"); diff --git a/test/mjsunit/test-http.js b/test/mjsunit/test-http.js index 4cc7753ccd4..1546507f77f 100644 --- a/test/mjsunit/test-http.js +++ b/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; diff --git a/test/mjsunit/test-mkdir-rmdir.js b/test/mjsunit/test-mkdir-rmdir.js index 369cf3a144d..5defedb959b 100644 --- a/test/mjsunit/test-mkdir-rmdir.js +++ b/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; diff --git a/test/mjsunit/test-module-loading.js b/test/mjsunit/test-module-loading.js index cfa3bda3115..58b3715714d 100644 --- a/test/mjsunit/test-module-loading.js +++ b/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"); diff --git a/test/mjsunit/test-multipart.js b/test/mjsunit/test-multipart.js index 5d7ad3072f9..21fa7fdf55e 100644 --- a/test/mjsunit/test-multipart.js +++ b/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'); diff --git a/test/mjsunit/test-process-buffering.js b/test/mjsunit/test-process-buffering.js index a5c09d8858e..b0d795275ed 100644 --- a/test/mjsunit/test-process-buffering.js +++ b/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; diff --git a/test/mjsunit/test-process-kill.js b/test/mjsunit/test-process-kill.js index 6851e0b2f67..59cc5361dff 100644 --- a/test/mjsunit/test-process-kill.js +++ b/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); }); diff --git a/test/mjsunit/test-process-simple.js b/test/mjsunit/test-process-simple.js index 2fb19766257..4a38ca552be 100644 --- a/test/mjsunit/test-process-simple.js +++ b/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; diff --git a/test/mjsunit/test-process-spawn-loop.js b/test/mjsunit/test-process-spawn-loop.js index b17452dc884..ebeb5e5b550 100644 --- a/test/mjsunit/test-process-spawn-loop.js +++ b/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 = ""; diff --git a/test/mjsunit/test-promise-timeout.js b/test/mjsunit/test-promise-timeout.js index 9bf5e195336..5f31a165d61 100644 --- a/test/mjsunit/test-promise-timeout.js +++ b/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(); diff --git a/test/mjsunit/test-promise-wait.js b/test/mjsunit/test-promise-wait.js index aa7b04383ac..2b662ccec9a 100644 --- a/test/mjsunit/test-promise-wait.js +++ b/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 () { diff --git a/test/mjsunit/test-readdir.js b/test/mjsunit/test-readdir.js index 4463ae92182..8a37079fbfc 100644 --- a/test/mjsunit/test-readdir.js +++ b/test/mjsunit/test-readdir.js @@ -1,4 +1,4 @@ -node.mixin(require("common.js")); +process.mixin(require("common.js")); var got_error = false; diff --git a/test/mjsunit/test-signal-handler.js b/test/mjsunit/test-signal-handler.js index 4fd8cd0b2b8..12ad20e0759 100644 --- a/test/mjsunit/test-signal-handler.js +++ b/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); diff --git a/test/mjsunit/test-tcp-binary.js b/test/mjsunit/test-tcp-binary.js index 881a9bed930..988e79160fc 100644 --- a/test/mjsunit/test-tcp-binary.js +++ b/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; } diff --git a/test/mjsunit/test-tcp-many-clients.js b/test/mjsunit/test-tcp-many-clients.js index 5cc3ad24cae..b501a5f4a79 100644 --- a/test/mjsunit/test-tcp-many-clients.js +++ b/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; diff --git a/test/mjsunit/test-tcp-pingpong-delay.js b/test/mjsunit/test-tcp-pingpong-delay.js index 687c8d731cb..a2140f13b4c 100644 --- a/test/mjsunit/test-tcp-pingpong-delay.js +++ b/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"); diff --git a/test/mjsunit/test-tcp-pingpong.js b/test/mjsunit/test-tcp-pingpong.js index a974bf92409..f6ed15b684b 100644 --- a/test/mjsunit/test-tcp-pingpong.js +++ b/test/mjsunit/test-tcp-pingpong.js @@ -1,4 +1,4 @@ -node.mixin(require("common.js")); +process.mixin(require("common.js")); tcp = require("/tcp.js"); diff --git a/test/mjsunit/test-tcp-reconnect.js b/test/mjsunit/test-tcp-reconnect.js index d1d6e531d2b..baa0fea19f3 100644 --- a/test/mjsunit/test-tcp-reconnect.js +++ b/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; diff --git a/test/mjsunit/test-tcp-throttle-kernel-buffer.js b/test/mjsunit/test-tcp-throttle-kernel-buffer.js index d5144b6ddfc..a4ad64de97a 100644 --- a/test/mjsunit/test-tcp-throttle-kernel-buffer.js +++ b/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 diff --git a/test/mjsunit/test-tcp-throttle.js b/test/mjsunit/test-tcp-throttle.js index cf3b028c544..7223425f481 100644 --- a/test/mjsunit/test-tcp-throttle.js +++ b/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; diff --git a/test/mjsunit/test-tcp-timeout.js b/test/mjsunit/test-tcp-timeout.js index dacb1e1211b..a559ba23e35 100644 --- a/test/mjsunit/test-tcp-timeout.js +++ b/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; diff --git a/test/mjsunit/test-timers.js b/test/mjsunit/test-timers.js index 53c4b9dcdfa..361da3152a4 100644 --- a/test/mjsunit/test-timers.js +++ b/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? diff --git a/test/mjsunit/test-utf8-scripts.js b/test/mjsunit/test-utf8-scripts.js index cb820bcac3c..b679e3d544e 100644 --- a/test/mjsunit/test-utf8-scripts.js +++ b/test/mjsunit/test-utf8-scripts.js @@ -1,4 +1,4 @@ -node.mixin(require("common.js")); +process.mixin(require("common.js")); // üäö diff --git a/test/mjsunit/test-wait-ordering.js b/test/mjsunit/test-wait-ordering.js index 40e99dfc3a0..f8503b032b1 100644 --- a/test/mjsunit/test-wait-ordering.js +++ b/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);