From e5a07dae467f17745ceabd2c5ebe45cba7efe1ae Mon Sep 17 00:00:00 2001 From: Ben Turner Date: Wed, 4 Aug 2010 14:44:28 -0700 Subject: [PATCH] Bug 583923 - 'IndexedDB: Don't fire events if there are no listeners for it'. r=sicking. --- dom/indexedDB/AsyncConnectionHelper.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/dom/indexedDB/AsyncConnectionHelper.cpp b/dom/indexedDB/AsyncConnectionHelper.cpp index a5ffe30dd4b1..c76233c91839 100644 --- a/dom/indexedDB/AsyncConnectionHelper.cpp +++ b/dom/indexedDB/AsyncConnectionHelper.cpp @@ -313,6 +313,17 @@ AsyncConnectionHelper::OnSuccess(nsIDOMEventTarget* aTarget) return result; } + // Check to make sure we have a listener here before actually firing. + nsCOMPtr target(do_QueryInterface(aTarget)); + if (target) { + nsIEventListenerManager* manager = target->GetListenerManager(PR_FALSE); + if (!manager || + !manager->HasListenersFor(NS_LITERAL_STRING(SUCCESS_EVT_STR))) { + // No listeners here, skip creating and dispatching the event. + return OK; + } + } + if (NS_FAILED(variant->SetWritable(PR_FALSE))) { NS_ERROR("Failed to make variant readonly!"); return nsIIDBDatabaseException::UNKNOWN_ERR;