Commit 9541eb10 9541eb10d18e001373d9f5247c41273e4c6d4849 by mickaelandrieu

[WIP] Added ADD/PREPEND Tags for Events

1 parent 416f226d
......@@ -129,6 +129,51 @@ EventEmitter.prototype.addListener = function addListener(type, listener) {
} else if (isArray(this._events[type])) {
// If we've already got an array, just append.
this._events[type].push(listener);
// Check for listener leak
if (!this._events[type].warned) {
var m;
if (this._maxListeners !== undefined) {
m = this._maxListeners;
} else {
m = defaultMaxListeners;
}
if (m && m > 0 && this._events[type].length > m) {
this._events[type].warned = true;
console.error('(node) warning: possible EventEmitter memory ' +
'leak detected. %d listeners added. ' +
'Use emitter.setMaxListeners() to increase limit.',
this._events[type].length);
console.trace();
}
}
} else {
// Adding the second element, need to change to array.
this._events[type] = [this._events[type], listener];
}
return this;
};
EventEmitter.prototype.prependListener = function prependListener(type, listener) {
if ('function' !== typeof listener) {
throw new CasperError('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 (isArray(this._events[type])) {
// If we've already got an array, just append.
this._events[type].unshift(listener);
// Check for listener leak
......@@ -157,7 +202,20 @@ EventEmitter.prototype.addListener = function addListener(type, listener) {
return this;
};
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
EventEmitter.prototype.on = function on(type, listener, tag) {
switch(tag) {
case "ADD":
return this.addListener(type, listener);
break;
case "PREPEND":
return this.prependListener;
break;
default:
return this.addListener(type, listener);
}
};
EventEmitter.prototype.once = function once(type, listener) {
if ('function' !== typeof listener) {
......
......@@ -1532,7 +1532,7 @@ Tester.prototype.renderResults = function renderResults(exit, status, save) {
};
/**
* Runs al suites contained in the paths passed as arguments.
* Runs all suites contained in the paths passed as arguments.
*
*/
Tester.prototype.runSuites = function runSuites() {
......