Backed out changeset 6790d8962ad9 to make ESlint happy. r=backout
authorSebastian Hengst <archaeopteryx@coole-files.de>
Sat, 12 Nov 2016 17:07:10 +0100
changeset 352385 5e2ec37ba69ffa5c78be6651815362d7c196c5f4
parent 352384 7b4af0b1626b70d331c0769a91faa3f72a876dc2
child 352386 0e366a3e90d2f87c8466dd9edf19581029023659
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbackout
milestone52.0a1
backs out6790d8962ad997c31d17c15e78d3a39692ec390a
Backed out changeset 6790d8962ad9 to make ESlint happy. r=backout
toolkit/components/extensions/Extension.jsm
toolkit/components/extensions/ExtensionChild.jsm
toolkit/components/extensions/ExtensionCommon.jsm
toolkit/components/extensions/ExtensionUtils.jsm
toolkit/components/extensions/MessageChannel.jsm
--- a/toolkit/components/extensions/Extension.jsm
+++ b/toolkit/components/extensions/Extension.jsm
@@ -74,17 +74,16 @@ var {
   GlobalManager,
   ParentAPIManager,
   apiManager: Management,
 } = ExtensionParent;
 
 const {
   EventEmitter,
   LocaleData,
-  getUniqueId,
 } = ExtensionUtils;
 
 XPCOMUtils.defineLazyGetter(this, "console", ExtensionUtils.getConsole);
 
 const LOGGER_ID_BASE = "addons.webextension.";
 const UUID_MAP_PREF = "extensions.webextensions.uuids";
 const LEAVE_STORAGE_PREF = "extensions.webextensions.keepStorageOnUninstall";
 const LEAVE_UUID_PREF = "extensions.webextensions.keepUuidOnUninstall";
@@ -560,26 +559,28 @@ this.ExtensionData = class {
       this.localeData.selectedLocale = locale;
       return results[0];
     }.bind(this));
   }
 };
 
 let _browserUpdated = false;
 
+let nextId = 0;
+
 const PROXIED_EVENTS = new Set(["test-harness-message"]);
 
 // We create one instance of this class per extension. |addonData|
 // comes directly from bootstrap.js when initializing.
 this.Extension = class extends ExtensionData {
   constructor(addonData, startupReason) {
     super(addonData.resourceURI);
 
     this.uuid = UUIDMap.get(addonData.id);
-    this.instanceId = getUniqueId();
+    this.instanceId = nextId++;
 
     this.MESSAGE_EMIT_EVENT = `Extension:EmitEvent:${this.instanceId}`;
     Services.ppmm.addMessageListener(this.MESSAGE_EMIT_EVENT, this);
 
     if (addonData.cleanupFile) {
       Services.obs.addObserver(this, "xpcom-shutdown", false);
       this.cleanupFile = addonData.cleanupFile || null;
       delete addonData.cleanupFile;
--- a/toolkit/components/extensions/ExtensionChild.jsm
+++ b/toolkit/components/extensions/ExtensionChild.jsm
@@ -44,29 +44,30 @@ Cu.import("resource://gre/modules/Extens
 const {
   EventManager,
   SingletonEventManager,
   SpreadArgs,
   defineLazyGetter,
   findPathInObject,
   getInnerWindowID,
   getMessageManager,
-  getUniqueId,
   injectAPI,
 } = ExtensionUtils;
 
 const {
   BaseContext,
   LocalAPIImplementation,
   SchemaAPIInterface,
   SchemaAPIManager,
 } = ExtensionCommon;
 
 var ExtensionChild;
 
+let gNextPortId = 1;
+
 /**
  * Abstraction for a Port object in the extension API.
  *
  * @param {BaseContext} context The context that owns this port.
  * @param {nsIMessageSender} senderMM The message manager to send messages to.
  * @param {Array<nsIMessageListenerManager>} receiverMMs Message managers to
  *     listen on.
  * @param {string} name Arbitrary port name as defined by the addon.
@@ -100,16 +101,20 @@ class Port {
       receiveMessage: ({data}) => this.disconnectByOtherEnd(data),
     }, this.handlerBase);
 
     MessageChannel.addListener(this.receiverMMs, "Extension:Port:Disconnect", this.disconnectHandler);
 
     this.context.callOnClose(this);
   }
 
+  static getNextID() {
+    return `${gNextPortId++}-${Services.appinfo.uniqueProcessID}`;
+  }
+
   api() {
     let portObj = Cu.createObjectIn(this.context.cloneScope);
 
     let portError = null;
     let publicAPI = {
       name: this.name,
 
       disconnect: () => {
@@ -392,25 +397,25 @@ class Messenger {
       }
       port.disconnectByOtherEnd(error);
     });
 
     return port.api();
   }
 
   connect(messageManager, name, recipient) {
-    let portId = getUniqueId();
+    let portId = Port.getNextID();
 
     let port = new Port(this.context, messageManager, this.messageManagers, name, portId, null, recipient);
 
     return this._connect(messageManager, port, recipient);
   }
 
   connectNative(messageManager, name, recipient) {
-    let portId = getUniqueId();
+    let portId = Port.getNextID();
 
     let port = new NativePort(this.context, messageManager, this.messageManagers, name, portId, null, recipient);
 
     return this._connect(messageManager, port, recipient);
   }
 
   onConnect(name) {
     return new SingletonEventManager(this.context, name, callback => {
@@ -608,17 +613,17 @@ class ChildAPIManagerBase {
    * @param {string} path The full name of the method, e.g. "tabs.create".
    * @param {Array} args The parameters for the function.
    * @param {function(*)} [callback] The callback to be called when the function
    *     completes.
    * @returns {Promise|undefined} Must be void if `callback` is set, and a
    *     promise otherwise. The promise is resolved when the function completes.
    */
   callParentAsyncFunction(path, args, callback) {
-    let callId = getUniqueId();
+    let callId = nextId++;
     let deferred = PromiseUtils.defer();
     this.callPromises.set(callId, deferred);
 
     this.messageManager.sendAsyncMessage("API:Call", {
       childId: this.id,
       callId,
       path,
       args,
--- a/toolkit/components/extensions/ExtensionCommon.jsm
+++ b/toolkit/components/extensions/ExtensionCommon.jsm
@@ -28,31 +28,32 @@ XPCOMUtils.defineLazyModuleGetter(this, 
 Cu.import("resource://gre/modules/ExtensionUtils.jsm");
 
 var {
   EventEmitter,
   ExtensionError,
   SpreadArgs,
   getConsole,
   getInnerWindowID,
-  getUniqueId,
   runSafeSync,
   runSafeSyncWithoutClone,
   instanceOf,
 } = ExtensionUtils;
 
 XPCOMUtils.defineLazyGetter(this, "console", getConsole);
 
+let gContextId = 0;
+
 class BaseContext {
   constructor(envType, extension) {
     this.envType = envType;
     this.onClose = new Set();
     this.checkedLastError = false;
     this._lastError = null;
-    this.contextId = getUniqueId();
+    this.contextId = `${++gContextId}-${Services.appinfo.uniqueProcessID}`;
     this.unloaded = false;
     this.extension = extension;
     this.jsonSandbox = null;
     this.active = true;
     this.incognito = null;
     this.messageManager = null;
     this.docShell = null;
     this.contentWindow = null;
--- a/toolkit/components/extensions/ExtensionUtils.jsm
+++ b/toolkit/components/extensions/ExtensionUtils.jsm
@@ -43,23 +43,16 @@ function getConsole() {
   return new ConsoleAPI({
     maxLogLevelPref: "extensions.webextensions.log.level",
     prefix: "WebExtensions",
   });
 }
 
 XPCOMUtils.defineLazyGetter(this, "console", getConsole);
 
-let nextId = 0;
-const {uniqueProcessID} = Services.appinfo;
-
-function getUniqueId() {
-  return `${nextId++}-${uniqueProcessID}`;
-}
-
 /**
  * An Error subclass for which complete error messages are always passed
  * to extensions, rather than being interpreted as an unknown error.
  */
 class ExtensionError extends Error {}
 
 function filterStack(error) {
   return String(error.stack).replace(/(^.*(Task\.jsm|Promise-backend\.js).*\n)+/gm, "<Promise Chain>\n");
@@ -1178,17 +1171,16 @@ this.ExtensionUtils = {
   defineLazyGetter,
   detectLanguage,
   extend,
   findPathInObject,
   flushJarCache,
   getConsole,
   getInnerWindowID,
   getMessageManager,
-  getUniqueId,
   ignoreEvent,
   injectAPI,
   instanceOf,
   normalizeTime,
   promiseDocumentLoaded,
   promiseDocumentReady,
   promiseEvent,
   promiseObserved,
--- a/toolkit/components/extensions/MessageChannel.jsm
+++ b/toolkit/components/extensions/MessageChannel.jsm
@@ -273,16 +273,18 @@ class FilteringMessageManagerMap extends
 
     return broker;
   }
 }
 
 const MESSAGE_MESSAGE = "MessageChannel:Message";
 const MESSAGE_RESPONSE = "MessageChannel:Response";
 
+let gChannelId = 0;
+
 this.MessageChannel = {
   init() {
     Services.obs.addObserver(this, "message-manager-close", false);
     Services.obs.addObserver(this, "message-manager-disconnect", false);
 
     this.messageManagers = new FilteringMessageManagerMap(
       MESSAGE_MESSAGE, this._handleMessage.bind(this));
 
@@ -507,17 +509,17 @@ this.MessageChannel = {
    *    contents for details.
    * @returns {Promise}
    */
   sendMessage(target, messageName, data, options = {}) {
     let sender = options.sender || {};
     let recipient = options.recipient || {};
     let responseType = options.responseType || this.RESPONSE_SINGLE;
 
-    let channelId = ExtensionUtils.getUniqueId();
+    let channelId = `${gChannelId++}-${Services.appinfo.uniqueProcessID}`;
     let message = {messageName, channelId, sender, recipient, data, responseType};
 
     if (responseType == this.RESPONSE_NONE) {
       try {
         target.sendAsyncMessage(MESSAGE_MESSAGE, message);
       } catch (e) {
         // Caller is not expecting a reply, so dump the error to the console.
         Cu.reportError(e);