Bug 1452307: Remove some dead code. r?aswan
MozReview-Commit-ID: DpV0WWW8WKF
--- a/toolkit/components/extensions/Schemas.jsm
+++ b/toolkit/components/extensions/Schemas.jsm
@@ -3009,16 +3009,20 @@ this.Schemas = {
contentSchemaJSON: new Map(),
_rootSchema: null,
get rootSchema() {
if (!this.initialized) {
this.init();
}
+ if (!this._rootSchema) {
+ this._rootSchema = new SchemaRoot(null, this.schemaJSON);
+ this._rootSchema.parseSchemas();
+ }
return this._rootSchema;
},
getNamespace(name) {
return this.rootSchema.getNamespace(name);
},
init() {
@@ -3031,18 +3035,16 @@ this.Schemas = {
let data = Services.cpmm.initialProcessData;
let schemas = data["Extension:Schemas"];
if (schemas) {
this.schemaJSON = schemas;
}
Services.cpmm.addMessageListener("Schema:Add", this);
}
-
- this.flushSchemas();
},
receiveMessage(msg) {
let {data} = msg;
switch (msg.name) {
case "Schema:Add":
// If we're given a Map, the ordering of the initial items
// matters, so swap with our current data to make sure its
@@ -3050,40 +3052,23 @@ this.Schemas = {
if (typeof data.get === "function") {
// Create a new Map so we're sure it's in the same compartment.
[this.schemaJSON, data] = [new Map(data), this.schemaJSON];
}
for (let [url, schema] of data) {
this.schemaJSON.set(url, schema);
}
- this.flushSchemas();
- break;
-
- case "Schema:Delete":
- this.schemaJSON.delete(data.url);
- this.flushSchemas();
+ if (this._rootScheam) {
+ throw new Error("Schema loaded after root schema populated");
+ }
break;
}
},
- _needFlush: true,
- flushSchemas() {
- if (this._needFlush) {
- this._needFlush = false;
- XPCOMUtils.defineLazyGetter(this, "_rootSchema", () => {
- this._needFlush = true;
-
- let rootSchema = new SchemaRoot(null, this.schemaJSON);
- rootSchema.parseSchemas();
- return rootSchema;
- });
- }
- },
-
_loadCachedSchemasPromise: null,
loadCachedSchemas() {
if (!this._loadCachedSchemasPromise) {
this._loadCachedSchemasPromise = StartupCache.schemas.getAll().then(results => {
return results;
});
}
@@ -3099,17 +3084,19 @@ this.Schemas = {
let data = Services.ppmm.initialProcessData;
data["Extension:Schemas"] = this.contentSchemaJSON;
Services.ppmm.broadcastAsyncMessage("Schema:Add", [[url, schema]]);
} else if (this.schemaHook) {
this.schemaHook([[url, schema]]);
}
- this.flushSchemas();
+ if (this._rootScheam) {
+ throw new Error("Schema loaded after root schema populated");
+ }
},
fetch(url) {
return readJSONAndBlobbify(url);
},
processSchema(json) {
return blobbify(json);
@@ -3125,27 +3112,16 @@ this.Schemas = {
let blob = (schemaCache.get(url) ||
await StartupCache.schemas.get(url, readJSONAndBlobbify));
if (!this.schemaJSON.has(url)) {
this.addSchema(url, blob, content);
}
},
- unload(url) {
- this.schemaJSON.delete(url);
-
- let data = Services.ppmm.initialProcessData;
- data["Extension:Schemas"] = this.schemaJSON;
-
- Services.ppmm.broadcastAsyncMessage("Schema:Delete", {url});
-
- this.flushSchemas();
- },
-
/**
* Checks whether a given object has the necessary permissions to
* expose the given namespace.
*
* @param {string} namespace
* The top-level namespace to check permissions for.
* @param {object} wrapperFuncs
* Wrapper functions for the given context.
--- a/toolkit/components/extensions/test/xpcshell/test_ext_schemas.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_schemas.js
@@ -507,16 +507,17 @@ let wrapper = {
getImplementation(namespace, name) {
return new TallyingAPIImplementation(namespace, name);
},
};
add_task(async function() {
let url = "data:," + JSON.stringify(json);
+ Schemas._rootSchema = null;
await Schemas.load(url);
let root = {};
tallied = null;
Schemas.inject(root, wrapper);
Assert.equal(tallied, null);
Assert.equal(root.testing.PROP1, 20, "simple value property");
@@ -1050,16 +1051,17 @@ let deprecatedJson = [
deprecated: "This event does not work",
},
],
},
];
add_task(async function testDeprecation() {
let url = "data:," + JSON.stringify(deprecatedJson);
+ Schemas._rootSchema = null;
await Schemas.load(url);
let root = {};
Schemas.inject(root, wrapper);
talliedErrors.length = 0;
@@ -1206,16 +1208,17 @@ let choicesJson = [
],
},
],
},
];
add_task(async function testChoices() {
let url = "data:," + JSON.stringify(choicesJson);
+ Schemas._rootSchema = null;
await Schemas.load(url);
let root = {};
Schemas.inject(root, wrapper);
talliedErrors.length = 0;
Assert.throws(() => root.choices.meh("frog"),
@@ -1295,16 +1298,17 @@ let permissionsJson = [
parameters: [],
},
],
},
];
add_task(async function testPermissions() {
let url = "data:," + JSON.stringify(permissionsJson);
+ Schemas._rootSchema = null;
await Schemas.load(url);
let root = {};
Schemas.inject(root, wrapper);
equal(typeof root.noPerms, "object", "noPerms namespace should exist");
equal(typeof root.noPerms.noPerms, "function", "noPerms.noPerms method should exist");
@@ -1394,16 +1398,17 @@ let nestedNamespaceJson = [
},
],
},
];
add_task(async function testNestedNamespace() {
let url = "data:," + JSON.stringify(nestedNamespaceJson);
+ Schemas._rootSchema = null;
await Schemas.load(url);
let root = {};
Schemas.inject(root, wrapper);
talliedErrors.length = 0;
ok(root.nested, "The root object contains the first namespace level");
@@ -1483,16 +1488,17 @@ let $importJson = [
enum: ["blue", "orange"],
},
],
},
];
add_task(async function test_$import() {
let url = "data:," + JSON.stringify($importJson);
+ Schemas._rootSchema = null;
await Schemas.load(url);
let root = {};
tallied = null;
Schemas.inject(root, wrapper);
equal(tallied, null);
equal(root.from_the.PROP1, "original value", "imported property");
@@ -1621,16 +1627,17 @@ let defaultsJson = [
},
},
],
},
];
add_task(async function testDefaults() {
let url = "data:," + JSON.stringify(defaultsJson);
+ Schemas._rootSchema = null;
await Schemas.load(url);
let testingApiObj = {
defaultFoo: function(arg) {
if (Object.keys(arg) != "prop1") {
throw new Error(`Received the expected default object, default: ${JSON.stringify(arg)}`);
}
arg.newProp = 1;
@@ -1687,16 +1694,17 @@ let returnsJson = [{
returns: {$ref: "Widget"},
parameters: [],
},
],
}];
add_task(async function testReturns() {
const url = "data:," + JSON.stringify(returnsJson);
+ Schemas._rootSchema = null;
await Schemas.load(url);
const apiObject = {
complete() {
return {size: 3, colour: "orange"};
},
optional() {
return {size: 4};