Bug 1260711 - Fix error 'IndexSizeError: Index or size is negative or greater than the allowed amount' when using the animation inspector. r=pbro
authorNicolas Chevobbe <chevobbe.nicolas@gmail.com>
Wed, 30 Mar 2016 18:25:00 +0200
changeset 291355 ad16491227f9cdf08fda7a3c1973562497d0f4ef
parent 291354 6d91363a7eac7343ded2da66d19b3ca01b6d0776
child 291356 5ea59d4c9ea5af538b4fddc1c624f72d9098ae82
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspbro
bugs1260711
milestone48.0a1
Bug 1260711 - Fix error 'IndexSizeError: Index or size is negative or greater than the allowed amount' when using the animation inspector. r=pbro Error was raised in drawGraphElementBackground when called with the graphView being `0` This could happen because in animation-timeline.js , there is a resize event handler that could be fired while the animation panel width is 0. We fix this by making sure the animation panel does not have a width of zero in the resize handler. MozReview-Commit-ID: 71izZnZBX7V
devtools/client/animationinspector/components/animation-timeline.js
devtools/client/animationinspector/utils.js
--- a/devtools/client/animationinspector/components/animation-timeline.js
+++ b/devtools/client/animationinspector/components/animation-timeline.js
@@ -164,16 +164,21 @@ AnimationsTimeline.prototype = {
     this.destroySubComponents("details", [{
       event: "frame-selected",
       fn: this.onFrameSelected
     }]);
     this.animationsEl.innerHTML = "";
   },
 
   onWindowResize: function() {
+    // Don't do anything if the root element has a width of 0
+    if (this.rootWrapperEl.offsetWidth === 0) {
+      return;
+    }
+
     if (this.windowResizeTimer) {
       this.win.clearTimeout(this.windowResizeTimer);
     }
 
     this.windowResizeTimer = this.win.setTimeout(() => {
       this.drawHeaderAndBackground();
     }, TIMELINE_BACKGROUND_RESIZE_DEBOUNCE_TIMER);
   },
--- a/devtools/client/animationinspector/utils.js
+++ b/devtools/client/animationinspector/utils.js
@@ -73,16 +73,21 @@ exports.createNode = createNode;
  * @param {String} id The ID for the image-element.
  * @param {Number} graphWidth The width of the graph.
  * @param {Number} intervalWidth The width of one interval
  */
 function drawGraphElementBackground(document, id, graphWidth, intervalWidth) {
   let canvas = document.createElement("canvas");
   let ctx = canvas.getContext("2d");
 
+  // Don't do anything if the graph or the intervals have a width of 0
+  if (graphWidth === 0 || intervalWidth === 0) {
+    return;
+  }
+
   // Set the canvas width (as requested) and height (1px, repeated along the Y
   // axis).
   canvas.width = graphWidth;
   canvas.height = 1;
 
   // Create the image data array which will receive the pixels.
   let imageData = ctx.createImageData(canvas.width, canvas.height);
   let pixelArray = imageData.data;