Bug 1378854 - Stop using sdk/core/heritage in DevTools stack utils; r=zer0 draft
authorJan Odvarko <odvarko@gmail.com>
Mon, 10 Jul 2017 11:28:26 +0200
changeset 606080 4aff3c90edaf18040810e79bc8c75dfd05b3d6ab
parent 605863 a418121d46250f91728b86d9eea331029c264c30
child 636670 83cc6b236d122d22872fb44c623dbb496cd1845e
push id67599
push userjodvarko@mozilla.com
push dateMon, 10 Jul 2017 09:29:11 +0000
reviewerszer0
bugs1378854
milestone56.0a1
Bug 1378854 - Stop using sdk/core/heritage in DevTools stack utils; r=zer0 MozReview-Commit-ID: L4FrZ0UBKea
devtools/server/actors/utils/stack.js
--- a/devtools/server/actors/utils/stack.js
+++ b/devtools/server/actors/utils/stack.js
@@ -1,92 +1,90 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
-var {Class} = require("sdk/core/heritage");
-
 /**
  * A helper class that stores stack frame objects.  Each frame is
  * assigned an index, and if a frame is added more than once, the same
  * index is used.  Users of the class can get an array of all frames
  * that have been added.
  */
-var StackFrameCache = Class({
+class StackFrameCache {
   /**
    * Initialize this object.
    */
-  initialize: function () {
+  constructor() {
     this._framesToIndices = null;
     this._framesToForms = null;
     this._lastEventSize = 0;
-  },
+  }
 
   /**
    * Prepare to accept frames.
    */
-  initFrames: function () {
+  initFrames() {
     if (this._framesToIndices) {
       // The maps are already initialized.
       return;
     }
 
     this._framesToIndices = new Map();
     this._framesToForms = new Map();
     this._lastEventSize = 0;
-  },
+  }
 
   /**
    * Forget all stored frames and reset to the initialized state.
    */
-  clearFrames: function () {
+  clearFrames() {
     this._framesToIndices.clear();
     this._framesToIndices = null;
     this._framesToForms.clear();
     this._framesToForms = null;
     this._lastEventSize = 0;
-  },
+  }
 
   /**
    * Add a frame to this stack frame cache, and return the index of
    * the frame.
    */
-  addFrame: function (frame) {
+  addFrame(frame) {
     this._assignFrameIndices(frame);
     this._createFrameForms(frame);
     return this._framesToIndices.get(frame);
-  },
+  }
 
   /**
    * A helper method for the memory actor.  This populates the packet
    * object with "frames" property. Each of these
    * properties will be an array indexed by frame ID.  "frames" will
    * contain frame objects (see makeEvent).
    *
    * @param packet
    *        The packet to update.
    *
    * @returns packet
    */
-  updateFramePacket: function (packet) {
+  updateFramePacket(packet) {
     // Now that we are guaranteed to have a form for every frame, we know the
     // size the "frames" property's array must be. We use that information to
     // create dense arrays even though we populate them out of order.
     const size = this._framesToForms.size;
     packet.frames = Array(size).fill(null);
 
     // Populate the "frames" properties.
     for (let [stack, index] of this._framesToIndices) {
       packet.frames[index] = this._framesToForms.get(stack);
     }
 
     return packet;
-  },
+  }
 
   /**
    * If any new stack frames have been added to this cache since the
    * last call to makeEvent (clearing the cache also resets the "last
    * call"), then return a new array describing the new frames.  If no
    * new frames are available, return null.
    *
    * The frame cache assumes that the user of the cache keeps track of
@@ -108,62 +106,62 @@ var StackFrameCache = Class({
    * }
    *
    * The intent of this approach is to make it simpler to efficiently
    * send frame information over the debugging protocol, by only
    * sending new frames.
    *
    * @returns array or null
    */
-  makeEvent: function () {
+  makeEvent() {
     const size = this._framesToForms.size;
     if (!size || size <= this._lastEventSize) {
       return null;
     }
 
     let packet = Array(size - this._lastEventSize).fill(null);
     for (let [stack, index] of this._framesToIndices) {
       if (index >= this._lastEventSize) {
         packet[index - this._lastEventSize] = this._framesToForms.get(stack);
       }
     }
 
     this._lastEventSize = size;
 
     return packet;
-  },
+  }
 
   /**
    * Assigns an index to the given frame and its parents, if an index is not
    * already assigned.
    *
    * @param SavedFrame frame
    *        A frame to assign an index to.
    */
-  _assignFrameIndices: function (frame) {
+  _assignFrameIndices(frame) {
     if (this._framesToIndices.has(frame)) {
       return;
     }
 
     if (frame) {
       this._assignFrameIndices(frame.parent);
       this._assignFrameIndices(frame.asyncParent);
     }
 
     const index = this._framesToIndices.size;
     this._framesToIndices.set(frame, index);
-  },
+  }
 
   /**
    * Create the form for the given frame, if one doesn't already exist.
    *
    * @param SavedFrame frame
    *        A frame to create a form for.
    */
-  _createFrameForms: function (frame) {
+  _createFrameForms(frame) {
     if (this._framesToForms.has(frame)) {
       return;
     }
 
     let form = null;
     if (frame) {
       form = {
         line: frame.line,
@@ -174,12 +172,12 @@ var StackFrameCache = Class({
         asyncParent: this._framesToIndices.get(frame.asyncParent),
         asyncCause: frame.asyncCause
       };
       this._createFrameForms(frame.parent);
       this._createFrameForms(frame.asyncParent);
     }
 
     this._framesToForms.set(frame, form);
-  },
-});
+  }
+}
 
 exports.StackFrameCache = StackFrameCache;