Bug 1382913 - throw an error when a non existing observer is removed from observers.js. r=kitcambridge
authorMark Hammond <mhammond@skippinet.com.au>
Tue, 25 Jul 2017 13:59:44 +1000
changeset 419506 1c8ae3d9f7c2973a8a1c132a55b46cbb96f2db97
parent 419505 67aad6b837d40ddbb785916fe2c69b59aa7103b3
child 419507 44260a3e2218dc95c04eda70e9fb3c2e60a034b9
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskitcambridge
bugs1382913
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1382913 - throw an error when a non existing observer is removed from observers.js. r=kitcambridge MozReview-Commit-ID: AR2IPDH0Rpw
services/common/observers.js
services/sync/tests/unit/test_score_triggers.js
--- a/services/common/observers.js
+++ b/services/common/observers.js
@@ -59,16 +59,18 @@ this.Observers = {
     // or thisObject, as far as I know, since the keys to JavaScript hashes
     // (a.k.a. objects) can apparently only be primitive values.
     let [observer] = this._cache.filter(v => v.topic == topic &&
                                              v.callback == callback &&
                                              v.thisObject == thisObject);
     if (observer) {
       this._service.removeObserver(observer, topic);
       this._cache.splice(this._cache.indexOf(observer), 1);
+    } else {
+      throw new Error("Attempt to remove non-existing observer");
     }
   },
 
   /**
    * Notify observers about something.
    *
    * @param topic   {String}
    *        the topic to notify observers about
--- a/services/sync/tests/unit/test_score_triggers.js
+++ b/services/sync/tests/unit/test_score_triggers.js
@@ -56,17 +56,17 @@ add_task(async function test_tracker_sco
   let { engine, tracker } = await registerRotaryEngine();
 
   let scoreUpdated = 0;
 
   function onScoreUpdated() {
     scoreUpdated++;
   }
 
-  Svc.Obs.add("weave:engine:score:updated", onScoreUpdated());
+  Svc.Obs.add("weave:engine:score:updated", onScoreUpdated);
 
   try {
     do_check_eq(engine.score, 0);
 
     tracker.score += SCORE_INCREMENT_SMALL;
     do_check_eq(engine.score, SCORE_INCREMENT_SMALL);
 
     do_check_eq(scoreUpdated, 1);