Bug 1287010 - Extension.jsm optimization: Use pathObj draft
authorRob Wu <rob@robwu.nl>
Sat, 20 Aug 2016 15:37:43 -0700
changeset 405210 7db31fa1699417c116f005e0f813c84deec2244c
parent 405209 42486069a23aa518c25cd557e28826ef11ce515b
child 405211 e4c7f6ec6c8e0461d3e60b4d11f4da76b03c6ecf
push id27432
push userbmo:rob@robwu.nl
push dateThu, 25 Aug 2016 02:36:24 +0000
bugs1287010
milestone51.0a1
Bug 1287010 - Extension.jsm optimization: Use pathObj The API implementation is already available upfront when the schema API is generated, so `pathObj` has the implementation and can be used instead of looking up the implementation over and over again with `findPathInObject`. MozReview-Commit-ID: FnCIyoaxgA4
toolkit/components/extensions/Extension.jsm
--- a/toolkit/components/extensions/Extension.jsm
+++ b/toolkit/components/extensions/Extension.jsm
@@ -581,66 +581,66 @@ GlobalManager = {
         return context.cloneScope;
       },
 
       hasPermission(permission) {
         return context.extension.hasPermission(permission);
       },
 
       callFunction(pathObj, path, name, args) {
-        return findPathInObject(apis, path)[name](...args);
+        return pathObj[name](...args);
       },
 
       callFunctionNoReturn(pathObj, path, name, args) {
-        findPathInObject(apis, path)[name](...args);
+        pathObj[name](...args);
       },
 
       callAsyncFunction(pathObj, path, name, args, callback) {
         // We pass an empty stub function as a default callback for
         // the `chrome` API, so promise objects are not returned,
         // and lastError values are reported immediately.
         if (callback === null) {
           callback = defaultCallback;
         }
 
         let promise;
         try {
-          promise = findPathInObject(apis, path)[name](...args);
+          promise = pathObj[name](...args) || Promise.resolve();
         } catch (e) {
           promise = Promise.reject(e);
         }
 
-        return context.wrapPromise(promise || Promise.resolve(), callback);
+        return context.wrapPromise(promise, callback);
       },
 
       shouldInject(namespace, name, restrictions) {
         // Do not generate content script APIs, unless explicitly allowed.
         if (context.envType === "content_parent" &&
             (!restrictions || !restrictions.includes("content"))) {
           return false;
         }
-        return findPathInObject(apis, [namespace]) != null;
+        return findPathInObject(apis, [namespace]);
       },
 
       getProperty(pathObj, path, name) {
-        return findPathInObject(apis, path)[name];
+        return pathObj[name];
       },
 
       setProperty(pathObj, path, name, value) {
-        findPathInObject(apis, path)[name] = value;
+        pathObj[name] = value;
       },
 
       addListener(pathObj, path, name, listener, args) {
-        findPathInObject(apis, path)[name].addListener.call(null, listener, ...args);
+        pathObj[name].addListener.call(null, listener, ...args);
       },
       removeListener(pathObj, path, name, listener) {
-        findPathInObject(apis, path)[name].removeListener.call(null, listener);
+        pathObj[name].removeListener.call(null, listener);
       },
       hasListener(pathObj, path, name, listener) {
-        return findPathInObject(apis, path)[name].hasListener.call(null, listener);
+        return pathObj[name].hasListener.call(null, listener);
       },
     };
     Schemas.inject(dest, schemaWrapper);
   },
 
   observe(document, topic, data) {
     let contentWindow = document.defaultView;
     if (!contentWindow) {