Bug 1297202 - Support cross-namespace submodule references in schemas r?aswan
MozReview-Commit-ID: 5JfOI3i3xbW
--- 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",