Bug 979161 part 1 - Wrap up paint_listener.js so it doesn't leak globals; r=roc
authorBrian Birtles <birtles@gmail.com>
Mon, 10 Mar 2014 13:47:12 +0900
changeset 190919 6c793fa8b589416a2458fc4c49674933f9f3f90c
parent 190918 ef2e0154fc2e978899018b0f86ad373a600b430b
child 190920 bb870818480e484b3c74f1660488ed969609a713
push id474
push userasasaki@mozilla.com
push dateMon, 02 Jun 2014 21:01:02 +0000
treeherdermozilla-release@967f4cf1b31c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs979161
milestone30.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 979161 part 1 - Wrap up paint_listener.js so it doesn't leak globals; r=roc
testing/mochitest/tests/SimpleTest/paint_listener.js
--- a/testing/mochitest/tests/SimpleTest/paint_listener.js
+++ b/testing/mochitest/tests/SimpleTest/paint_listener.js
@@ -1,50 +1,53 @@
-var accumulatedRect = null;
-var onpaint = function() {};
-var debug = false;
+(function() {
+  var accumulatedRect = null;
+  var onpaint = function() {};
+  var debug = false;
 
-function paintListener(event) {
-  if (event.target != window)
-    return;
-  if (debug) {
-    dump("got MozAfterPaint: " + event.boundingClientRect.left + "," + event.boundingClientRect.top + "," +
-         event.boundingClientRect.right + "," + event.boundingClientRect.bottom + "\n");
+  function paintListener(event) {
+    if (event.target != window)
+      return;
+    if (debug) {
+      dump("got MozAfterPaint: " + event.boundingClientRect.left + "," + event.boundingClientRect.top + "," +
+           event.boundingClientRect.right + "," + event.boundingClientRect.bottom + "\n");
+    }
+    if (accumulatedRect) {
+      accumulatedRect[0] = Math.min(accumulatedRect[0], event.boundingClientRect.left);
+      accumulatedRect[1] = Math.min(accumulatedRect[1], event.boundingClientRect.top);
+      accumulatedRect[2] = Math.max(accumulatedRect[2], event.boundingClientRect.right);
+      accumulatedRect[3] = Math.max(accumulatedRect[3], event.boundingClientRect.bottom);
+    } else {
+      accumulatedRect = [event.boundingClientRect.left, event.boundingClientRect.top,
+                         event.boundingClientRect.right, event.boundingClientRect.bottom];
+    }
+    onpaint();
   }
-  if (accumulatedRect) {
-    accumulatedRect[0] = Math.min(accumulatedRect[0], event.boundingClientRect.left);
-    accumulatedRect[1] = Math.min(accumulatedRect[1], event.boundingClientRect.top);
-    accumulatedRect[2] = Math.max(accumulatedRect[2], event.boundingClientRect.right);
-    accumulatedRect[3] = Math.max(accumulatedRect[3], event.boundingClientRect.bottom);
-  } else {
-    accumulatedRect = [event.boundingClientRect.left, event.boundingClientRect.top,
-                       event.boundingClientRect.right, event.boundingClientRect.bottom];
-  }
-  onpaint();
-}
-window.addEventListener("MozAfterPaint", paintListener, false);
+  window.addEventListener("MozAfterPaint", paintListener, false);
 
-function waitForAllPaintsFlushed(callback, subdoc) {
-  document.documentElement.getBoundingClientRect();
-  if (subdoc) {
-    subdoc.documentElement.getBoundingClientRect();
-  }
-  var CI = Components.interfaces;
-  var utils = window.QueryInterface(CI.nsIInterfaceRequestor)
-              .getInterface(CI.nsIDOMWindowUtils);
-  if (!utils.isMozAfterPaintPending) {
-    if (debug) {
-      dump("done...\n");
+  function waitForAllPaintsFlushed(callback, subdoc) {
+    document.documentElement.getBoundingClientRect();
+    if (subdoc) {
+      subdoc.documentElement.getBoundingClientRect();
     }
-    var result = accumulatedRect;
-    accumulatedRect = null;
-    onpaint = function() {};
-    if (!result) {
-      result = [0,0,0,0];
+    var CI = Components.interfaces;
+    var utils = window.QueryInterface(CI.nsIInterfaceRequestor)
+                .getInterface(CI.nsIDOMWindowUtils);
+    if (!utils.isMozAfterPaintPending) {
+      if (debug) {
+        dump("done...\n");
+      }
+      var result = accumulatedRect;
+      accumulatedRect = null;
+      onpaint = function() {};
+      if (!result) {
+        result = [0,0,0,0];
+      }
+      callback(result[0], result[1], result[2], result[3]);
+      return;
     }
-    callback(result[0], result[1], result[2], result[3]);
-    return;
+    if (debug) {
+      dump("waiting for paint...\n");
+    }
+    onpaint = function() { waitForAllPaintsFlushed(callback, subdoc); };
   }
-  if (debug) {
-    dump("waiting for paint...\n");
-  }
-  onpaint = function() { waitForAllPaintsFlushed(callback, subdoc); };
-}
+  window.waitForAllPaintsFlushed = waitForAllPaintsFlushed;
+})();