Bug 1302898 - Make the schema restrictions array non-nullable. r=kmag

MozReview-Commit-ID: Lk8TGsqC4WC

--HG--
extra : rebase_source : c09973950aa64f3c24a29dd5a43bc967735704e2
This commit is contained in:
Matthew Wein 2016-09-14 17:02:06 -07:00
parent 80826a7490
commit d513d2bcb7
3 changed files with 13 additions and 16 deletions

View File

@ -700,8 +700,7 @@ GlobalManager = {
shouldInject(namespace, name, restrictions) {
// Do not generate content script APIs, unless explicitly allowed.
if (context.envType === "content_parent" &&
(!restrictions || !restrictions.includes("content"))) {
if (context.envType === "content_parent" && !restrictions.includes("content")) {
return false;
}
return findPathInObject(apis, namespace) !== null;

View File

@ -1763,11 +1763,7 @@ class ChildAPIManager {
shouldInject(namespace, name, restrictions) {
// Do not generate content script APIs, unless explicitly allowed.
if (this.context.envType === "content_child" &&
(!restrictions || !restrictions.includes("content"))) {
return false;
}
return true;
return this.context.envType !== "content_child" || restrictions.includes("content");
}
getImplementation(namespace, name) {

View File

@ -470,11 +470,11 @@ class Entry {
this.preprocessor = schema.preprocess || null;
/**
* @property {Array<string>} [restrictions]
* A list of restrictions to consider before generating the API.
* @property {Array<string>} restrictions A list of restrictions to
* consider before generating the API.
* These are not parsed by the schema, but passed to `shouldInject`.
*/
this.restrictions = schema.restrictions || null;
this.restrictions = schema.restrictions || [];
}
/**
@ -1425,7 +1425,8 @@ class SubModuleProperty extends Entry {
for (let fun of functions) {
let subpath = path.concat(name);
let namespace = subpath.join(".");
if (context.shouldInject(namespace, fun.name, fun.restrictions || ns.defaultRestrictions)) {
let restrictions = fun.restrictions.length ? fun.restrictions : ns.defaultRestrictions;
if (context.shouldInject(namespace, fun.name, restrictions)) {
let apiImpl = context.getImplementation(namespace, fun.name);
fun.inject(apiImpl, subpath, fun.name, obj, context);
}
@ -1655,8 +1656,8 @@ this.Schemas = {
if (!ns) {
ns = new Map();
ns.permissions = null;
ns.restrictions = null;
ns.defeaultRestrictions = null;
ns.restrictions = [];
ns.defeaultRestrictions = [];
this.namespaces.set(namespaceName, ns);
}
ns.set(symbol, value);
@ -1850,8 +1851,8 @@ this.Schemas = {
let ns = this.namespaces.get(name);
ns.permissions = namespace.permissions || null;
ns.restrictions = namespace.restrictions || null;
ns.defaultRestrictions = namespace.defaultRestrictions || null;
ns.restrictions = namespace.restrictions || [];
ns.defaultRestrictions = namespace.defaultRestrictions || [];
}
},
@ -1925,7 +1926,8 @@ this.Schemas = {
let obj = Cu.createObjectIn(dest, {defineAs: namespace});
for (let [name, entry] of ns) {
if (context.shouldInject(namespace, name, entry.restrictions || ns.defaultRestrictions)) {
let restrictions = entry.restrictions.length ? entry.restrictions : ns.defaultRestrictions;
if (context.shouldInject(namespace, name, restrictions)) {
let apiImpl = context.getImplementation(namespace, name);
entry.inject(apiImpl, [namespace], name, obj, context);
}