(function () { // annonymous namespace
-// deprecation errors
+/** deprecation errors ************************************************/
GLOBAL.__module = function () {
throw new Error("'__module' has been renamed to 'module'");
throw new Error("node.inherits() has moved. Use require('sys') to access it.");
};
+/**********************************************************************/
+
+// Module
+
+function Module (id, parent) {
+ this.id = id;
+ this.exports = {};
+ this.parent = parent;
+
+ this.filename = null;
+ this.loaded = false;
+ this.loadPromise = null;
+ this.exited = false;
+ this.children = [];
+};
+
+var moduleCache = {};
+
+function createModule (id, parent) {
+ if (id in moduleCache) {
+ debug("found " + JSON.stringify(id) + " in cache");
+ return moduleCache[id];
+ }
+ debug("didn't found " + JSON.stringify(id) + " in cache. creating new module");
+ var m = new Module(id, parent);
+ moduleCache[id] = m;
+ return m;
+};
+
+function createInternalModule (id, constructor) {
+ var m = createModule(id);
+ constructor(m.exports);
+ m.loaded = true;
+ return m;
+};
+
+
+process.inherits = function (ctor, superCtor) {
+ var tempCtor = function(){};
+ tempCtor.prototype = superCtor.prototype;
+ ctor.super_ = superCtor;
+ ctor.prototype = new tempCtor();
+ ctor.prototype.constructor = ctor;
+};
+
process.createChildProcess = function (file, args, env) {
var child = new process.ChildProcess();
return target;
};
-
// Event
-// 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] = [];
- // To avoid recursion in the case that type == "newListeners"! Before
- // adding it to the listeners, first emit "newListeners".
- this.emit("newListener", type, listener);
- this._events[type].push(listener);
- }
- return this;
-};
-
-process.EventEmitter.prototype.removeListener = function (type, listener) {
- if (listener instanceof Function) {
- // does not use listeners(), so no side effect of creating _events[type]
- if (!this._events || !this._events.hasOwnProperty(type)) return;
- var list = this._events[type];
- if (list.indexOf(listener) < 0) return;
- list.splice(list.indexOf(listener), 1);
- }
- return this;
-};
-
-process.EventEmitter.prototype.listeners = function (type) {
- if (!this._events) this._events = {};
- if (!this._events.hasOwnProperty(type)) this._events[type] = [];
- return this._events[type];
-};
-
-process.inherits = function (ctor, superCtor) {
- var tempCtor = function(){};
- tempCtor.prototype = superCtor.prototype;
- ctor.super_ = superCtor;
- ctor.prototype = new tempCtor();
- ctor.prototype.constructor = ctor;
-};
+var eventsModule = createInternalModule('events', function (exports) {
+ exports.EventEmitter = process.EventEmitter;
+
+ // 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] = [];
+ // To avoid recursion in the case that type == "newListeners"! Before
+ // adding it to the listeners, first emit "newListeners".
+ this.emit("newListener", type, listener);
+ this._events[type].push(listener);
+ }
+ return this;
+ };
+ process.EventEmitter.prototype.removeListener = function (type, listener) {
+ if (listener instanceof Function) {
+ // does not use listeners(), so no side effect of creating _events[type]
+ if (!this._events || !this._events.hasOwnProperty(type)) return;
+ var list = this._events[type];
+ if (list.indexOf(listener) < 0) return;
+ list.splice(list.indexOf(listener), 1);
+ }
+ return this;
+ };
-// Promise
+ process.EventEmitter.prototype.listeners = function (type) {
+ if (!this._events) this._events = {};
+ if (!this._events.hasOwnProperty(type)) this._events[type] = [];
+ return this._events[type];
+ };
-process.Promise = function () {
- process.EventEmitter.call();
- this._blocking = false;
- this._hasFired = false;
-};
-process.inherits(process.Promise, process.EventEmitter);
+ exports.Promise = function () {
+ exports.EventEmitter.call();
+ this._blocking = false;
+ this._hasFired = false;
+ };
+ process.inherits(exports.Promise, exports.EventEmitter);
-process.Promise.prototype.timeout = function(timeout) {
- if (timeout === undefined) {
- return this._timeoutDuration;
- }
+ process.Promise = exports.Promise;
- this._timeoutDuration = timeout;
- if (this._timer) {
- clearTimeout(this._timer);
- this._timer = null;
- }
+ exports.Promise.prototype.timeout = function(timeout) {
+ if (timeout === undefined) {
+ return this._timeoutDuration;
+ }
- var promiseComplete = false;
- var onComplete = function() {
- promiseComplete = true;
+ this._timeoutDuration = timeout;
if (this._timer) {
clearTimeout(this._timer);
this._timer = null;
}
- };
- this
- .addCallback(onComplete)
- .addCancelback(onComplete)
- .addErrback(onComplete);
+ var promiseComplete = false;
+ var onComplete = function() {
+ promiseComplete = true;
+ if (this._timer) {
+ clearTimeout(this._timer);
+ this._timer = null;
+ }
+ };
- var self = this;
- this._timer = setTimeout(function() {
- self._timer = null;
- if (promiseComplete) {
- return;
- }
+ this
+ .addCallback(onComplete)
+ .addCancelback(onComplete)
+ .addErrback(onComplete);
- self.emitError(new Error('timeout'));
- }, this._timeoutDuration);
+ var self = this;
+ this._timer = setTimeout(function() {
+ self._timer = null;
+ if (promiseComplete) {
+ return;
+ }
- return this;
-};
+ self.emitError(new Error('timeout'));
+ }, this._timeoutDuration);
-process.Promise.prototype.cancel = function() {
- if(this._cancelled) return;
- this._cancelled = true;
+ return this;
+ };
- this._events['success'] = [];
- this._events['error'] = [];
+ exports.Promise.prototype.cancel = function() {
+ if(this._cancelled) return;
+ this._cancelled = true;
- this.emitCancel();
-};
+ this._events['success'] = [];
+ this._events['error'] = [];
-process.Promise.prototype.emitCancel = function() {
- Array.prototype.unshift.call(arguments, 'cancel')
- this.emit.apply(this, arguments);
-};
+ this.emitCancel();
+ };
-process.Promise.prototype.emitSuccess = function() {
- if (this.hasFired) return;
- this.hasFired = true;
- Array.prototype.unshift.call(arguments, 'success')
- this.emit.apply(this, arguments);
-};
+ exports.Promise.prototype.emitCancel = function() {
+ Array.prototype.unshift.call(arguments, 'cancel')
+ this.emit.apply(this, arguments);
+ };
-process.Promise.prototype.emitError = function() {
- if (this.hasFired) return;
- this.hasFired = true;
- Array.prototype.unshift.call(arguments, 'error')
- this.emit.apply(this, arguments);
-};
+ exports.Promise.prototype.emitSuccess = function() {
+ if (this.hasFired) return;
+ this.hasFired = true;
+ Array.prototype.unshift.call(arguments, 'success')
+ this.emit.apply(this, arguments);
+ };
-process.Promise.prototype.addCallback = function (listener) {
- this.addListener("success", listener);
- return this;
-};
+ exports.Promise.prototype.emitError = function() {
+ if (this.hasFired) return;
+ this.hasFired = true;
+ Array.prototype.unshift.call(arguments, 'error')
+ this.emit.apply(this, arguments);
+ };
-process.Promise.prototype.addErrback = function (listener) {
- this.addListener("error", listener);
- return this;
-};
+ exports.Promise.prototype.addCallback = function (listener) {
+ this.addListener("success", listener);
+ return this;
+ };
-process.Promise.prototype.addCancelback = function (listener) {
- this.addListener("cancel", listener);
- return this;
-};
+ exports.Promise.prototype.addErrback = function (listener) {
+ this.addListener("error", listener);
+ return this;
+ };
-/* Poor Man's coroutines */
-var coroutineStack = [];
+ exports.Promise.prototype.addCancelback = function (listener) {
+ this.addListener("cancel", listener);
+ return this;
+ };
-process.Promise.prototype._destack = function () {
- this._blocking = false;
+ /* Poor Man's coroutines */
+ var coroutineStack = [];
- while (coroutineStack.length > 0 &&
- !coroutineStack[coroutineStack.length-1]._blocking)
- {
- coroutineStack.pop();
- process.unloop("one");
- }
-};
+ exports.Promise.prototype._destack = function () {
+ this._blocking = false;
-process.Promise.prototype.wait = function () {
- var self = this;
- var ret;
- var hadError = false;
-
- self.addCallback(function () {
- if (arguments.length == 1) {
- ret = arguments[0];
- } else if (arguments.length > 1) {
- ret = Array.prototype.slice.call(arguments);
+ while (coroutineStack.length > 0 &&
+ !coroutineStack[coroutineStack.length-1]._blocking)
+ {
+ coroutineStack.pop();
+ process.unloop("one");
}
- self._destack();
- });
+ };
- self.addErrback(function (arg) {
- hadError = true;
- ret = arg;
- self._destack();
- });
+ exports.Promise.prototype.wait = function () {
+ var self = this;
+ var ret;
+ var hadError = false;
- coroutineStack.push(self);
- if (coroutineStack.length > 10) {
- process.stdio.writeError("WARNING: promise.wait() is being called too often.\n");
- }
- self._blocking = true;
+ self.addCallback(function () {
+ if (arguments.length == 1) {
+ ret = arguments[0];
+ } else if (arguments.length > 1) {
+ ret = Array.prototype.slice.call(arguments);
+ }
+ self._destack();
+ });
- process.loop();
+ self.addErrback(function (arg) {
+ hadError = true;
+ ret = arg;
+ self._destack();
+ });
- process.assert(self._blocking == false);
+ coroutineStack.push(self);
+ if (coroutineStack.length > 10) {
+ process.stdio.writeError("WARNING: promise.wait() is being called too often.\n");
+ }
+ self._blocking = true;
- if (hadError) {
- if (ret) {
- throw ret;
- } else {
- throw new Error("Promise completed with error (No arguments given.)");
+ process.loop();
+
+ process.assert(self._blocking == false);
+
+ if (hadError) {
+ if (ret) {
+ throw ret;
+ } else {
+ throw new Error("Promise completed with error (No arguments given.)");
+ }
}
- }
- return ret;
-};
+ return ret;
+ };
+});
+var events = eventsModule.exports;
// Signal Handlers
}
-// private constructor
-function Module (id, parent) {
- this.id = id;
- this.exports = {};
- this.parent = parent;
-
- this.filename = null;
- this.loaded = false;
- this.loadPromise = null;
- this.exited = false;
- this.children = [];
-};
-
-var moduleCache = {};
-
-function createModule (id, parent) {
- if (id in moduleCache) {
- debug("found " + JSON.stringify(id) + " in cache");
- return moduleCache[id];
- }
- debug("didn't found " + JSON.stringify(id) + " in cache. creating new module");
- var m = new Module(id, parent);
- moduleCache[id] = m;
- return m;
-};
-
-function createInternalModule (id, constructor) {
- var m = createModule(id);
- constructor(m.exports);
- m.loaded = true;
- return m;
-};
var posixModule = createInternalModule("posix", function (exports) {
exports.Stats = process.Stats;
// list to make the arguments clear.
exports.close = function (fd) {
- var promise = new process.Promise();
+ var promise = new events.Promise();
process.fs.close(fd, callback(promise));
return promise;
};
};
exports.open = function (path, flags, mode) {
- var promise = new process.Promise();
+ var promise = new events.Promise();
process.fs.open(path, flags, mode, callback(promise));
return promise;
};
};
exports.read = function (fd, length, position, encoding) {
- var promise = new process.Promise();
+ var promise = new events.Promise();
encoding = encoding || "binary";
process.fs.read(fd, length, position, encoding, callback(promise));
return promise;
};
exports.write = function (fd, data, position, encoding) {
- var promise = new process.Promise();
+ var promise = new events.Promise();
encoding = encoding || "binary";
process.fs.write(fd, data, position, encoding, callback(promise));
return promise;
};
exports.rename = function (oldPath, newPath) {
- var promise = new process.Promise();
+ var promise = new events.Promise();
process.fs.rename(oldPath, newPath, callback(promise));
return promise;
};
};
exports.rmdir = function (path) {
- var promise = new process.Promise();
+ var promise = new events.Promise();
process.fs.rmdir(path, callback(promise));
return promise;
};
};
exports.mkdir = function (path, mode) {
- var promise = new process.Promise();
+ var promise = new events.Promise();
process.fs.mkdir(path, mode, callback(promise));
return promise;
};
};
exports.sendfile = function (outFd, inFd, inOffset, length) {
- var promise = new process.Promise();
+ var promise = new events.Promise();
process.fs.sendfile(outFd, inFd, inOffset, length, callback(promise));
return promise;
};
};
exports.readdir = function (path) {
- var promise = new process.Promise();
+ var promise = new events.Promise();
process.fs.readdir(path, callback(promise));
return promise;
};
};
exports.stat = function (path) {
- var promise = new process.Promise();
+ var promise = new events.Promise();
process.fs.stat(path, callback(promise));
return promise;
};
};
exports.unlink = function (path) {
- var promise = new process.Promise();
+ var promise = new events.Promise();
process.fs.unlink(path, callback(promise));
return promise;
};
exports.cat = function (path, encoding) {
- var promise = new process.Promise();
+ var promise = new events.Promise();
encoding = encoding || "utf8"; // default to utf8
function loadModule (request, parent) {
// This is the promise which is actually returned from require.async()
- var loadPromise = new process.Promise();
+ var loadPromise = new events.Promise();
// debug("loadModule REQUEST " + (request) + " parent: " + JSON.stringify(parent));
debug(id);
if (id.match(/^http:\/\//)) {
- promise = new process.Promise();
+ promise = new events.Promise();
loadModule('http', process.mainModule)
.addCallback(function(http) {
http.cat(id)
// Load the main module--the command line argument.
process.mainModule = createModule(".");
-var loadPromise = new process.Promise();
+var loadPromise = new events.Promise();
process.mainModule.load(process.ARGV[1], loadPromise);
loadPromise.addErrback(function(e) {