Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
events, bugfix: crash when off function on new Emitter.
  • Loading branch information
xicilion committed Apr 22, 2020
1 parent c54335d commit 01e3ccd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 6 additions & 4 deletions fibjs/include/EventEmitter.h
Expand Up @@ -302,12 +302,14 @@ class JSTrigger {
{
v8::Local<v8::Array> esa = GetHiddenList(ev);

removeFunction(esa, func, ev);
if (!esa.IsEmpty()) {
removeFunction(esa, func, ev);

int32_t len = esa->Length();
int32_t len = esa->Length();

if (len == 0)
DeletePrivate(ev);
if (len == 0)
DeletePrivate(ev);
}

retVal = o;
return 0;
Expand Down
5 changes: 5 additions & 0 deletions test/trigger_test.js
Expand Up @@ -397,6 +397,11 @@ describe("Trigger/EventEmitter", () => {

evevt_test("events.EventEmitter.call", new MyEmitter2());

it('bugfix: crash when off function on new Emitter', () => {
var ev = new events.EventEmitter();
ev.off('a', () => {});
})

describe("defaultMaxListeners", () => {
it('getter', () => {
assert.equal(events.defaultMaxListeners, 10);
Expand Down

0 comments on commit 01e3ccd

Please sign in to comment.