Bug 1323845: Part 3 - Auto-create intermediate API namespace objects when necessary. r=aswan
authorKris Maglione <maglione.k@gmail.com>
Tue, 09 Jan 2018 16:02:38 -0800
changeset 453471 77442f18cc027a5cd4bef9a3ac5cdc3d615e3805
parent 453470 43f9533906cfada71309e73d977326b69ef9c7de
child 453472 e8b83e2001740feec71bf29ec88a00825f3c4c79
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1323845
milestone59.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 1323845: Part 3 - Auto-create intermediate API namespace objects when necessary. r=aswan MozReview-Commit-ID: HA8WpynPOqp
toolkit/components/extensions/ExtensionCommon.jsm
--- a/toolkit/components/extensions/ExtensionCommon.jsm
+++ b/toolkit/components/extensions/ExtensionCommon.jsm
@@ -838,28 +838,32 @@ class CanOfAPIs {
   findAPIPath(path) {
     if (this.apiPaths.has(path)) {
       return this.apiPaths.get(path);
     }
 
     let obj = this.root;
     let modules = this.apiManager.modulePaths;
 
-    for (let key of path.split(".")) {
+    let parts = path.split(".");
+    for (let [i, key] of parts.entries()) {
       if (!obj) {
         return;
       }
       modules = getChild(modules, key);
 
       for (let name of modules.modules) {
         if (!this.apis.has(name)) {
           this.loadAPI(name);
         }
       }
 
+      if (!(key in obj) && i < parts.length - 1) {
+        obj[key] = {};
+      }
       obj = obj[key];
     }
 
     this.apiPaths.set(path, obj);
     return obj;
   }
 
   /**
@@ -874,28 +878,33 @@ class CanOfAPIs {
   async asyncFindAPIPath(path) {
     if (this.apiPaths.has(path)) {
       return this.apiPaths.get(path);
     }
 
     let obj = this.root;
     let modules = this.apiManager.modulePaths;
 
-    for (let key of path.split(".")) {
+    let parts = path.split(".");
+    for (let [i, key] of parts.entries()) {
       if (!obj) {
         return;
       }
       modules = getChild(modules, key);
 
       for (let name of modules.modules) {
         if (!this.apis.has(name)) {
           await this.asyncLoadAPI(name);
         }
       }
 
+      if (!(key in obj) && i < parts.length - 1) {
+        obj[key] = {};
+      }
+
       if (typeof obj[key] === "function") {
         obj = obj[key].bind(obj);
       } else {
         obj = obj[key];
       }
     }
 
     this.apiPaths.set(path, obj);