Bug 1260711 - Fix error 'IndexSizeError: Index or size is negative or greater than the allowed amount' when using the animation inspector. r=pbro draft
authorNicolas Chevobbe <chevobbe.nicolas@gmail.com>
Wed, 30 Mar 2016 18:25:00 +0200
changeset 346248 5471788a60527969b6cedd51c02c0b722df308e6
parent 345748 e1c798332d3be8aed7b934d2e6b3982d5de7d902
child 517382 898818881cdda303ee0babaf15540fde33f53db1
push id14306
push userchevobbe.nicolas@gmail.com
push dateThu, 31 Mar 2016 15:15:29 +0000
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;