Bug 1297202 - Support cross-namespace submodule references in schemas r?aswan draft
authorRob Wu <rob@robwu.nl>
Mon, 22 Aug 2016 15:11:47 -0700
changeset 404091 dcdcbde8e30b5ff1ddfe6b95df9218d46f4e43a1
parent 404026 63988dbb25327ff93dd6e0c7e07b2b819795a9eb
child 529096 9e59d3cb687fc17dfe15a7a1490cfa02c8e3bb0b
push id27112
push userbmo:rob@robwu.nl
push dateMon, 22 Aug 2016 22:13:08 +0000
reviewersaswan
bugs1297202
milestone51.0a1
Bug 1297202 - Support cross-namespace submodule references in schemas r?aswan MozReview-Commit-ID: 5JfOI3i3xbW
toolkit/components/extensions/Schemas.jsm
toolkit/components/extensions/test/xpcshell/test_ext_schemas.js
--- a/toolkit/components/extensions/Schemas.jsm
+++ b/toolkit/components/extensions/Schemas.jsm
@@ -1198,16 +1198,21 @@ class SubModuleProperty extends Entry {
     this.properties = properties;
   }
 
   inject(path, name, dest, context) {
     let obj = Cu.createObjectIn(dest, {defineAs: name});
 
     let ns = Schemas.namespaces.get(this.namespaceName);
     let type = ns.get(this.reference);
+    if (!type && this.reference.includes(".")) {
+      let [namespaceName, ref] = this.reference.split(".");
+      ns = Schemas.namespaces.get(namespaceName);
+      type = ns.get(ref);
+    }
     if (!type || !(type instanceof SubModuleType)) {
       throw new Error(`Internal error: ${this.namespaceName}.${this.reference} is not a sub-module`);
     }
 
     let functions = type.functions;
     for (let fun of functions) {
       fun.inject(path.concat(name), fun.name, obj, context);
     }
--- a/toolkit/components/extensions/test/xpcshell/test_ext_schemas.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_schemas.js
@@ -337,16 +337,22 @@ let json = [
        extraParameters: [{
          name: "filter",
          type: "integer",
        }],
      },
    ],
   },
   {
+    namespace: "foreign",
+    properties: {
+      foreignRef: {$ref: "testing.submodule"},
+    },
+  },
+  {
     namespace: "inject",
     properties: {
       PROP1: {value: "should inject"},
     },
   },
   {
     namespace: "do-not-inject",
     properties: {
@@ -776,16 +782,20 @@ add_task(function* () {
 
   root.testing.prop3.sub_foo();
   verify("call", "testing.prop3", "sub_foo", []);
   tallied = null;
 
   Assert.throws(() => root.testing.prop4.sub_foo(),
                 /root.testing.prop4 is undefined/,
                 "should throw for unsupported submodule");
+
+  root.foreign.foreignRef.sub_foo();
+  verify("call", "foreign.foreignRef", "sub_foo", []);
+  tallied = null;
 });
 
 let deprecatedJson = [
   {namespace: "deprecated",
 
    properties: {
      accessor: {
        type: "string",