Skip to content
This repository has been archived by the owner on Feb 26, 2022. It is now read-only.

Commit

Permalink
Bug 726967: Fix infinite loop when error event listener throws.
Browse files Browse the repository at this point in the history
  • Loading branch information
ochameau committed Feb 15, 2012
1 parent fe07b21 commit 34a9d6b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/api-utils/lib/events.js
Expand Up @@ -148,7 +148,12 @@ const eventEmitter = {
try {
listener.apply(targetObj, params);
} catch(e) {
this._emit('error', e);
// Bug 726967: Ignore exceptions being throws while notifying the error
// in order to avoid infinite loops.
if (type !== ERROR_TYPE)
this._emit(ERROR_TYPE, e);
else
console.exception("Exception in error event listener " + e);
}
}
return true;
Expand Down
17 changes: 17 additions & 0 deletions packages/api-utils/tests/test-events.js
Expand Up @@ -248,3 +248,20 @@ exports["test:removing once"] = function(test) {
e.once("error", function() { test.fail("error event was emitted"); });
e._emit("foo", "bug-656684");
};

// Bug 726967: Ensure that `emit` doesn't do an infinite loop when `error`
// listener throws an exception
exports['test:emitLoop'] = function(test) {
let e = new EventEmitter();

e.on("foo", function() {
throw new Error("foo");
});

e.on("error", function() {
throw new Error("error");
});
e.emit("foo");

test.pass("emit didn't looped");
};

0 comments on commit 34a9d6b

Please sign in to comment.