Bug 1551045 - add debug log in `vtt.jsm`. r=heycam
authorAlastor Wu <alwu@mozilla.com>
Sun, 12 May 2019 22:56:06 +0000
changeset 532398 5c99c6daa9db60f35fb85956271fd855e7c0cd7b
parent 532388 fa3cfee27619ddc9bcbcf70555bda4eb1e815146
child 532399 c7feffe40029e833241baa952cec89346d649a06
push id11268
push usercsabou@mozilla.com
push dateTue, 14 May 2019 15:24:22 +0000
treeherdermozilla-beta@5fb7fcd568d6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1551045
milestone68.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 1551045 - add debug log in `vtt.jsm`. r=heycam We should add some debug logs, which should be easily enable and disable, in vtt.jsm in order to increase the efficiency of debugging. Differential Revision: https://phabricator.services.mozilla.com/D30798
dom/media/webvtt/vtt.jsm
--- a/dom/media/webvtt/vtt.jsm
+++ b/dom/media/webvtt/vtt.jsm
@@ -29,16 +29,23 @@ var EXPORTED_SYMBOLS = ["WebVTT"];
 
 const {Services} = ChromeUtils.import('resource://gre/modules/Services.jsm');
 const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 XPCOMUtils.defineLazyPreferenceGetter(this, "supportPseudo",
                                       "media.webvtt.pseudo.enabled", false);
 
 (function(global) {
+  var DEBUG_LOG = false;
+
+  function LOG(message) {
+    if (DEBUG_LOG) {
+      dump("[vtt] " + message + "\n");
+    }
+  }
 
   var _objCreate = Object.create || (function() {
     function F() {}
     return function(o) {
       if (arguments.length !== 1) {
         throw new Error('Object.create shim only accepts one parameter.');
       }
       F.prototype = o;
@@ -794,31 +801,41 @@ XPCOMUtils.defineLazyPreferenceGetter(th
     get bottom() {
       return this.top + this.height;
     }
 
     get right() {
       return this.left + this.width;
     }
 
+    // This function is used for debugging, it will return the box's information.
+    getBoxInfoInChars() {
+      return `top=${this.top}, bottom=${this.bottom}, left=${this.left}, ` +
+             `right=${this.right}, width=${this.width}, height=${this.height}`;
+    }
+
     // Move the box along a particular axis. Optionally pass in an amount to move
     // the box. If no amount is passed then the default is the line height of the
     // box.
     move(axis, toMove) {
       switch (axis) {
       case "+x":
+        LOG(`box's left moved from ${this.left} to ${this.left + toMove}`);
         this.left += toMove;
         break;
       case "-x":
+        LOG(`box's left moved from ${this.left} to ${this.left - toMove}`);
         this.left -= toMove;
         break;
       case "+y":
+        LOG(`box's top moved from ${this.top} to ${this.top + toMove}`);
         this.top += toMove;
         break;
       case "-y":
+        LOG(`box's top moved from ${this.top} to ${this.top - toMove}`);
         this.top -= toMove;
         break;
       }
     }
 
     // Check if this box overlaps another box, b2.
     overlaps(b2) {
       return this.left < b2.right &&
@@ -1132,16 +1149,18 @@ XPCOMUtils.defineLazyPreferenceGetter(th
       boxPositions.push(controlBarBox);
     }
 
     // https://w3c.github.io/webvtt/#processing-model 6.1.12.1
     // Create regionNode
     let regionNodeBoxes = {};
     let regionNodeBox;
 
+    LOG(`=== processCues ===`);
+
     for (let i = 0; i < cues.length; i++) {
       cue = cues[i];
       if (cue.region != null) {
        // 6.1.14.1
         styleBox = new RegionCueStyleBox(window, cue);
 
         if (!regionNodeBoxes[cue.region.id]) {
           // create regionNode
@@ -1178,16 +1197,17 @@ XPCOMUtils.defineLazyPreferenceGetter(th
         // result of algorithm doesn't want us to show the cue when we don't
         // have any room for this cue.
         let cueBox = adjustBoxPosition(styleBox, containerBox, controlBarBox, boxPositions);
         if (cueBox) {
           // Remember the computed div so that we don't have to recompute it later
           // if we don't have too.
           cue.displayState = styleBox.div;
           boxPositions.push(cueBox);
+          LOG(`cue ${i}, ` + cueBox.getBoxInfoInChars());
         }
       }
     }
   };
 
   WebVTT.Parser = function(window, decoder) {
     this.window = window;
     this.state = "INITIAL";