Bug 1378849 - Stop using add-on SDK APIs in the webaudio editor; r=sole
authorPatrick Brosset <pbrosset@mozilla.com>
Tue, 22 Aug 2017 17:58:15 +0200
changeset 376632 12fecb86b6374a6098431eaea0b806679cb36343
parent 376631 6fb1b3230adf5de00a0131fab47ca9a20844cb64
child 376633 f20a0f19b75be6b6c488f2eebfdbf95c6d4dc962
push id94144
push userryanvm@gmail.com
push dateFri, 25 Aug 2017 00:21:50 +0000
treeherdermozilla-inbound@942d868646cf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssole
bugs1378849
milestone57.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 1378849 - Stop using add-on SDK APIs in the webaudio editor; r=sole MozReview-Commit-ID: AXMub2xwA8Q
devtools/client/webaudioeditor/includes.js
devtools/client/webaudioeditor/models.js
--- a/devtools/client/webaudioeditor/includes.js
+++ b/devtools/client/webaudioeditor/includes.js
@@ -3,17 +3,16 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 "use strict";
 
 var { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
 
 const { loader, require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
 const { XPCOMUtils } = require("resource://gre/modules/XPCOMUtils.jsm");
 const { Task } = require("devtools/shared/task");
-const { Class } = require("sdk/core/heritage");
 const OldEventEmitter = require("devtools/shared/old-event-emitter");
 const EventEmitter = require("devtools/shared/event-emitter");
 const DevToolsUtils = require("devtools/shared/DevToolsUtils");
 const Services = require("Services");
 const { gDevTools } = require("devtools/client/framework/devtools");
 const { LocalizationHelper } = require("devtools/shared/l10n");
 const { ViewHelpers } = require("devtools/client/shared/widgets/view-helpers");
 
--- a/devtools/client/webaudioeditor/models.js
+++ b/devtools/client/webaudioeditor/models.js
@@ -6,279 +6,282 @@
 /**
  * Representational wrapper around AudioNodeActors. Adding and destroying
  * AudioNodes should be performed through the AudioNodes collection.
  *
  * Events:
  * - `connect`: node, destinationNode, parameter
  * - `disconnect`: node
  */
-const AudioNodeModel = Class({
-  extends: EventEmitter,
+class AudioNodeModel extends EventEmitter {
+  constructor(actor) {
+    super();
 
-  // Will be added via AudioNodes `add`
-  collection: null,
+    // Will be added via AudioNodes `add`
+    this.collection = null;
 
-  initialize: function (actor) {
     this.actor = actor;
     this.id = actor.actorID;
     this.type = actor.type;
     this.bypassable = actor.bypassable;
     this._bypassed = false;
     this.connections = [];
-  },
+  }
 
   /**
    * Stores connection data inside this instance of this audio node connecting
    * to another node (destination). If connecting to another node's AudioParam,
    * the second argument (param) must be populated with a string.
    *
    * Connecting nodes is idempotent. Upon new connection, emits "connect" event.
    *
    * @param AudioNodeModel destination
    * @param String param
    */
-  connect: function (destination, param) {
+  connect(destination, param) {
     let edge = findWhere(this.connections, { destination: destination.id, param: param });
 
     if (!edge) {
       this.connections.push({ source: this.id, destination: destination.id, param: param });
       EventEmitter.emit(this, "connect", this, destination, param);
     }
-  },
+  }
 
   /**
    * Clears out all internal connection data. Emits "disconnect" event.
    */
-  disconnect: function () {
+  disconnect() {
     this.connections.length = 0;
     EventEmitter.emit(this, "disconnect", this);
-  },
+  }
 
   /**
    * Gets the bypass status of the audio node.
    *
    * @return Boolean
    */
-  isBypassed: function () {
+  isBypassed() {
     return this._bypassed;
-  },
+  }
 
   /**
    * Sets the bypass value of an AudioNode.
    *
    * @param Boolean enable
    * @return Promise
    */
-  bypass: function (enable) {
+  bypass(enable) {
     this._bypassed = enable;
     return this.actor.bypass(enable).then(() => EventEmitter.emit(this, "bypass", this, enable));
-  },
+  }
 
   /**
    * Returns a promise that resolves to an array of objects containing
    * both a `param` name property and a `value` property.
    *
    * @return Promise->Object
    */
-  getParams: function () {
+  getParams() {
     return this.actor.getParams();
-  },
+  }
 
   /**
    * Returns a promise that resolves to an object containing an
    * array of event information and an array of automation data.
    *
    * @param String paramName
    * @return Promise->Array
    */
-  getAutomationData: function (paramName) {
+  getAutomationData(paramName) {
     return this.actor.getAutomationData(paramName);
-  },
+  }
 
   /**
    * Takes a `dagreD3.Digraph` object and adds this node to
    * the graph to be rendered.
    *
    * @param dagreD3.Digraph
    */
-  addToGraph: function (graph) {
+  addToGraph(graph) {
     graph.addNode(this.id, {
       type: this.type,
       label: this.type.replace(/Node$/, ""),
       id: this.id,
       bypassed: this._bypassed
     });
-  },
+  }
 
   /**
    * Takes a `dagreD3.Digraph` object and adds edges to
    * the graph to be rendered. Separate from `addToGraph`,
    * as while we depend on D3/Dagre's constraints, we cannot
    * add edges for nodes that have not yet been added to the graph.
    *
    * @param dagreD3.Digraph
    */
-  addEdgesToGraph: function (graph) {
+  addEdgesToGraph(graph) {
     for (let edge of this.connections) {
       let options = {
         source: this.id,
         target: edge.destination
       };
 
       // Only add `label` if `param` specified, as this is an AudioParam
       // connection then. `label` adds the magic to render with dagre-d3,
       // and `param` is just more explicitly the param, ignoring
       // implementation details.
       if (edge.param) {
         options.label = options.param = edge.param;
       }
 
       graph.addEdge(null, this.id, edge.destination, options);
     }
-  },
+  }
 
-  toString: () => "[object AudioNodeModel]",
-});
+  toString() {
+    return "[object AudioNodeModel]";
+  }
+}
 
 
 /**
  * Constructor for a Collection of `AudioNodeModel` models.
  *
  * Events:
  * - `add`: node
  * - `remove`: node
  * - `connect`: node, destinationNode, parameter
  * - `disconnect`: node
  */
-const AudioNodesCollection = Class({
-  extends: EventEmitter,
+class AudioNodesCollection extends EventEmitter {
+  constructor() {
+    super();
 
-  model: AudioNodeModel,
-
-  initialize: function () {
+    this.model = AudioNodeModel;
     this.models = new Set();
     this._onModelEvent = this._onModelEvent.bind(this);
-  },
+  }
 
   /**
    * Iterates over all models within the collection, calling `fn` with the
    * model as the first argument.
    *
    * @param Function fn
    */
-  forEach: function (fn) {
+  forEach(fn) {
     this.models.forEach(fn);
-  },
+  }
 
   /**
    * Creates a new AudioNodeModel, passing through arguments into the AudioNodeModel
    * constructor, and adds the model to the internal collection store of this
    * instance.
    *
    * Emits "add" event on instance when completed.
    *
    * @param Object obj
    * @return AudioNodeModel
    */
-  add: function (obj) {
+  add(obj) {
     let node = new this.model(obj);
     node.collection = this;
 
     this.models.add(node);
 
     node.on("*", this._onModelEvent);
     EventEmitter.emit(this, "add", node);
     return node;
-  },
+  }
 
   /**
    * Removes an AudioNodeModel from the internal collection. Calls `delete` method
    * on the model, and emits "remove" on this instance.
    *
    * @param AudioNodeModel node
    */
-  remove: function (node) {
+  remove(node) {
     this.models.delete(node);
     EventEmitter.emit(this, "remove", node);
-  },
+  }
 
   /**
    * Empties out the internal collection of all AudioNodeModels.
    */
-  reset: function () {
+  reset() {
     this.models.clear();
-  },
+  }
 
   /**
    * Takes an `id` from an AudioNodeModel and returns the corresponding
    * AudioNodeModel within the collection that matches that id. Returns `null`
    * if not found.
    *
    * @param Number id
    * @return AudioNodeModel|null
    */
-  get: function (id) {
+  get(id) {
     return findWhere(this.models, { id: id });
-  },
+  }
 
   /**
    * Returns the count for how many models are a part of this collection.
    *
    * @return Number
    */
   get length() {
     return this.models.size;
-  },
+  }
 
   /**
    * Returns detailed information about the collection. used during tests
    * to query state. Returns an object with information on node count,
    * how many edges are within the data graph, as well as how many of those edges
    * are for AudioParams.
    *
    * @return Object
    */
-  getInfo: function () {
+  getInfo() {
     let info = {
       nodes: this.length,
       edges: 0,
       paramEdges: 0
     };
 
     this.models.forEach(node => {
       let paramEdgeCount = node.connections.filter(edge => edge.param).length;
       info.edges += node.connections.length - paramEdgeCount;
       info.paramEdges += paramEdgeCount;
     });
     return info;
-  },
+  }
 
   /**
    * Adds all nodes within the collection to the passed in graph,
    * as well as their corresponding edges.
    *
    * @param dagreD3.Digraph
    */
-  populateGraph: function (graph) {
+  populateGraph(graph) {
     this.models.forEach(node => node.addToGraph(graph));
     this.models.forEach(node => node.addEdgesToGraph(graph));
-  },
+  }
 
   /**
    * Called when a stored model emits any event. Used to manage
    * event propagation, or listening to model events to react, like
    * removing a model from the collection when it's destroyed.
    */
-  _onModelEvent: function (eventName, node, ...args) {
+  _onModelEvent(eventName, node, ...args) {
     if (eventName === "remove") {
       // If a `remove` event from the model, remove it
       // from the collection, and let the method handle the emitting on
       // the collection
       this.remove(node);
     } else {
       // Pipe the event to the collection
       EventEmitter.emit(this, eventName, node, ...args);
     }
-  },
+  }
 
-  toString: () => "[object AudioNodeCollection]",
-});
+  toString() {
+    return "[object AudioNodeCollection]";
+  }
+}