From 3de7d241381f27f8e1f77d562fe9552e11a23894 Mon Sep 17 00:00:00 2001 From: Dan Mills Date: Mon, 3 Nov 2008 14:40:28 -0800 Subject: [PATCH] Update Observers js module to latest version --- services/sync/modules/Observers.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/services/sync/modules/Observers.js b/services/sync/modules/Observers.js index 947b986ded5..d557576e45e 100644 --- a/services/sync/modules/Observers.js +++ b/services/sync/modules/Observers.js @@ -56,8 +56,10 @@ let Observers = { remove: function(callback, topic) { let observer = Observers._observers[topic][callback]; - Observers._service.removeObserver(observer, topic); - delete this._observers[topic][callback]; + if (observer) { + Observers._service.removeObserver(observer, topic); + delete this._observers[topic][callback]; + } }, notify: function(subject, topic, data) { @@ -67,6 +69,8 @@ let Observers = { _service: Cc["@mozilla.org/observer-service;1"]. getService(Ci.nsIObserverService), + // Observers indexed by callback. This lets us get the observer + // to remove when a caller calls |remove|, passing it a callback. _observers: {} }; @@ -81,10 +85,12 @@ Observer.prototype = { // Pass the wrappedJSObject for subjects that have one. Otherwise pass // the subject itself. This way we support both wrapped subjects created // using this module and those that are real XPCOM components. - if (subject && subject.wrappedJSObject) - this._callback(subject.wrappedJSObject, topic, data); + let unwrappedSubject = subject.wrappedJSObject || subject; + + if (typeof this._callback == "function") + this._callback(unwrappedSubject, topic, data); else - this._callback(subject, topic, data); + this._callback.observe(unwrappedSubject, topic, data); } }