diff --git a/shared/V8ResourceImpl.h b/shared/V8ResourceImpl.h index 30e9b3db..f1da1beb 100644 --- a/shared/V8ResourceImpl.h +++ b/shared/V8ResourceImpl.h @@ -11,6 +11,7 @@ #include "V8Timer.h" #include "IRuntimeEventHandler.h" +#include "V8Helpers.h" class V8ResourceImpl : public alt::IResource::Impl { @@ -69,14 +70,28 @@ class V8ResourceImpl : public alt::IResource::Impl remoteGenericHandlers.push_back(V8Helpers::EventCallback{ isolate, cb, std::move(location), once }); } - void UnsubscribeLocal(const std::string& ev, v8::Local cb) + void UnsubscribeLocal(const std::string& ev, v8::Local cb, V8Helpers::SourceLocation&& location) { auto range = localHandlers.equal_range(ev); + bool anyHandlerRemoved = false; for(auto it = range.first; it != range.second; ++it) { - if(it->second.fn.Get(isolate)->StrictEquals(cb)) it->second.removed = true; + if(it->second.fn.Get(isolate)->StrictEquals(cb)) + { + it->second.removed = true; + anyHandlerRemoved = true; + } } + + if(!anyHandlerRemoved) + { + Log::Warning << + location.ToString() << " alt.off was called for event \"" << ev << + "\" with function reference that was not subscribed" << Log::Endl; + return; + } + alt::CEvent::Type type = V8Helpers::EventHandler::GetTypeForEventName(ev); if(type != alt::CEvent::Type::NONE) IRuntimeEventHandler::Instance().EventHandlerRemoved(type); } diff --git a/shared/bindings/Main.cpp b/shared/bindings/Main.cpp index 60ad4a8e..569bc802 100644 --- a/shared/bindings/Main.cpp +++ b/shared/bindings/Main.cpp @@ -70,7 +70,7 @@ static void Off(const v8::FunctionCallbackInfo& info) V8_ARG_TO_STRING(1, evName); V8_ARG_TO_FUNCTION(2, callback); - resource->UnsubscribeLocal(evName, callback); + resource->UnsubscribeLocal(evName, callback, V8Helpers::SourceLocation::GetCurrent(isolate, resource)); } }