Closed Bug 583923 Opened 14 years ago Closed 14 years ago

IndexedDB: Don't fire events if there are no listeners for it

Categories

(Core :: Storage: IndexedDB, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: bent.mozilla, Assigned: bent.mozilla)

Details

Attachments

(1 file)

Attached patch PatchSplinter Review
We're wasting time firing events if no listener is attached. See patch.
Attachment #462270 - Flags: review?(jonas)
Comment on attachment 462270 [details] [diff] [review]
Patch

>diff --git a/dom/indexedDB/AsyncConnectionHelper.cpp b/dom/indexedDB/AsyncConnectionHelper.cpp
>--- a/dom/indexedDB/AsyncConnectionHelper.cpp
>+++ b/dom/indexedDB/AsyncConnectionHelper.cpp
>@@ -308,16 +308,27 @@ AsyncConnectionHelper::OnSuccess(nsIDOME
>     return nsIIDBDatabaseException::UNKNOWN_ERR;
>   }
> 
>   PRUint16 result = GetSuccessResult(variant);
>   if (result != OK) {
>     return result;
>   }
> 
>+  // Check to make sure we have a listener here before actually firing.
>+  nsCOMPtr<nsPIDOMEventTarget> target(do_QueryInterface(aTarget));
>+  if (target) {
>+    nsIEventListenerManager* manager = target->GetListenerManager(PR_FALSE);
>+    if (manager &&
>+        !manager->HasListenersFor(NS_LITERAL_STRING(SUCCESS_EVT_STR))) {
This should be 
if (!manager || !manager->HasListenersFor(NS_LITERAL_STRING(SUCCESS_EVT_STR)) {
  ...
}

Because if you don't have any listeners, you may not have the manager at all.
Ah! Very nice. I'll change to that, thanks.
http://hg.mozilla.org/mozilla-central/rev/08084a1de4a1
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
Component: DOM → DOM: IndexedDB
Version: Trunk → unspecified
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: