diff --git a/README.md b/README.md index 9da06a5..855d01f 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ This is a set of helpers for simplification and standardization of addons and dependency packages. +* EventEmitter C++ implementation. * Contains helpers of following types: GYP, C++, JS, BAT (Windows). * Platforms: win x32/x64, linux x32/x64, mac x64. * Useful links: [V8 Ref](https://v8docs.nodesource.com/node-0.8/d2/dc3/namespacev8.html), diff --git a/include/event-emitter.hpp b/include/event-emitter.hpp index c84d468..d920fcf 100644 --- a/include/event-emitter.hpp +++ b/include/event-emitter.hpp @@ -292,6 +292,26 @@ protected: emitter->_wrappedIds[nextId] = cb; emitter->_rawIds[nextId] = raw; + int count = emitter->_raw[name].size(); + + if (emitter->_maxListeners > 0 && count > emitter->_maxListeners) { + + std::cout << "EventEmitter Warning: too many listeners ("; + std::cout << count << " > " << emitter->_maxListeners << ") on '"; + std::cout << name << "' event, possible memory leak." << std::endl; + + // Some JS magic to retrieve the call stack + v8::Local code = JS_STR( + "(new Error()).stack.split('\\n').slice(1).join('\\n')" + ); + v8::Local stack = v8::Local::Cast( + v8::Script::Compile(code)->Run() + ); + Nan::Utf8String stackStr(stack); + std::cout << *stackStr << std::endl; + + } + }