(function (process) {
process.global.process = process;
process.global.global = process.global;
global.GLOBAL = global;
/** deprecation errors ************************************************/
function removed (reason) {
return function () {
throw new Error(reason)
}
}
GLOBAL.__module = removed("'__module' has been renamed to 'module'");
GLOBAL.include = removed("include(module) has been removed. Use require(module)");
GLOBAL.puts = removed("puts() has moved. Use require('sys') to bring it back.");
GLOBAL.print = removed("print() has moved. Use require('sys') to bring it back.");
GLOBAL.p = removed("p() has moved. Use require('sys') to bring it back.");
process.debug = removed("process.debug() has moved. Use require('sys') to bring it back.");
process.error = removed("process.error() has moved. Use require('sys') to bring it back.");
process.watchFile = removed("process.watchFile() has moved to fs.watchFile()");
process.unwatchFile = removed("process.unwatchFile() has moved to fs.unwatchFile()");
process.mixin = removed('process.mixin() has been removed.');
GLOBAL.node = {};
node.createProcess = removed("node.createProcess() has been changed to process.createChildProcess() update your code");
process.createChildProcess = removed("childProcess API has changed. See doc/api.txt.");
node.exec = removed("process.exec() has moved. Use require('sys') to bring it back.");
node.inherits = removed("node.inherits() has moved. Use require('sys') to access it.");
process.inherits = removed("process.inherits() has moved to sys.inherits.");
node.http = {};
node.http.createServer = removed("node.http.createServer() has moved. Use require('http') to access it.");
node.http.createClient = removed("node.http.createClient() has moved. Use require('http') to access it.");
node.tcp = {};
node.tcp.createServer = removed("node.tcp.createServer() has moved. Use require('tcp') to access it.");
node.tcp.createConnection = removed("node.tcp.createConnection() has moved. Use require('tcp') to access it.");
node.dns = {};
node.dns.createConnection = removed("node.dns.createConnection() has moved. Use require('dns') to access it.");
/**********************************************************************/
// Module
var internalModuleCache = {};
var extensionCache = {};
function Module (id, parent) {
this.id = id;
this.exports = {};
this.parent = parent;
if (parent) {
this.moduleCache = parent.moduleCache;
} else {
this.moduleCache = {};
}
this.moduleCache[this.id] = this;
this.filename = null;
this.loaded = false;
this.exited = false;
this.children = [];
};
function createInternalModule (id, constructor) {
var m = new Module(id);
constructor(m.exports);
m.loaded = true;
internalModuleCache[id] = m;
return m;
};
// This contains the source code for the files in lib/
// Like, natives.fs is the contents of lib/fs.js
var natives = process.binding('natives');
function loadNative (id) {
var m = new Module(id);
internalModuleCache[id] = m;
var e = m._compile(natives[id], id);
if (e) throw e;
m.loaded = true;
return m;
}
function requireNative (id) {
if (internalModuleCache[id]) return internalModuleCache[id].exports;
if (!natives[id]) throw new Error('No such native module ' + id);
return loadNative(id).exports;
}
process.assert = function (x, msg) {
if (!(x)) throw new Error(msg || "assertion error");
};
// Event
var eventsModule = createInternalModule('events', function (exports) {
exports.EventEmitter = process.EventEmitter;
// process.EventEmitter is defined in src/node_events.cc
// process.EventEmitter.prototype.emit() is also defined there.
process.EventEmitter.prototype.addListener = function (type, listener) {
if (!(listener instanceof Function)) {
throw new Error('addListener only takes instances of Function');
}
if (!this._events) this._events = {};
// To avoid recursion in the case that type == "newListeners"! Before
// adding it to the listeners, first emit "newListeners".
this.emit("newListener", type, listener);
if (!this._events[type]) {
// Optimize the case of one listener. Don't need the extra array object.
this._events[type] = listener;
} else if (this._events[type] instanceof Array) {
// If we've already got an array, just append.
this._events[type].push(listener);
} else {
// Adding the second element, need to change to array.
this._events[type] = [this._events[type], listener];
}
return this;
};
process.EventEmitter.prototype.removeListener = function (type, listener) {
if (!(listener instanceof Function)) {
throw new Error('removeListener only takes instances of Function');
}
// does not use listeners(), so no side effect of creating _events[type]
if (!this._events || !this._events[type]) return this;
var list = this._events[type];
if (list instanceof Array) {
var i = list.indexOf(listener);
if (i < 0) return this;
list.splice(i, 1);
} else {
this._events[type] = null;
}
return this;
};
process.EventEmitter.prototype.removeAllListeners = function (type) {
// does not use listeners(), so no side effect of creating _events[type]
if (!type || !this._events || !this._events[type]) return this;
this._events[type] = null;
};
process.EventEmitter.prototype.listeners = function (type) {
if (!this._events) this._events = {};
if (!this._events[type]) this._events[type] = [];
if (!(this._events[type] instanceof Array)) {
this._events[type] = [this._events[type]];
}
return this._events[type];
};
exports.Promise = removed('Promise has been removed. See http://groups.google.com/group/nodejs/msg/0c483b891c56fea2 for more information.');
process.Promise = exports.Promise;
});
var events = eventsModule.exports;
// nextTick()
var nextTickQueue = [];
process._tickCallback = function () {
var l = nextTickQueue.length;
while (l--) {
var cb = nextTickQueue.shift();
cb();
}
};
process.nextTick = function (callback) {
nextTickQueue.push(callback);
process._needTickCallback();
};
// Signal Handlers
function isSignal (event) {
return event.slice(0, 3) === 'SIG' && process.hasOwnProperty(event);
};
process.addListener("newListener", function (event) {
if (isSignal(event) && process.listeners(event).length === 0) {
var b = process.binding('signal_watcher');
var w = new b.SignalWatcher(process[event]);
w.addListener("signal", function () {
process.emit(event);
});
}
});
// Timers
function addTimerListener (callback) {
var timer = this;
// Special case the no param case to avoid the extra object creation.
if (arguments.length > 2) {
var args = Array.prototype.slice.call(arguments, 2);
timer.callback = function () { callback.apply(timer, args); };
} else {
timer.callback = callback;
}
}
global.setTimeout = function (callback, after) {
var timer = new process.Timer();
addTimerListener.apply(timer, arguments);
timer.start(after, 0);
return timer;
};
global.setInterval = function (callback, repeat) {
var timer = new process.Timer();
addTimerListener.apply(timer, arguments);
timer.start(repeat, repeat);
return timer;
};
global.clearTimeout = function (timer) {
if (timer instanceof process.Timer) {
timer.stop();
}
};
global.clearInterval = global.clearTimeout;
// Modules
var debugLevel = parseInt(process.env["NODE_DEBUG"]);
function debug (x) {
if (debugLevel > 0) {
process.binding('stdio').writeError(x + "\n");
}
}
var pathModule = createInternalModule("path", function (exports) {
exports.join = function () {
return exports.normalize(Array.prototype.join.call(arguments, "/"));
};
exports.normalizeArray = function (parts, keepBlanks) {
var directories = [], prev;
for (var i = 0, l = parts.length - 1; i