[AllAM] De-duplicate ChromeManifestParser.jsm and DeferedSave.jsm

This commit is contained in:
NTD 2018-06-26 14:43:25 -04:00 committed by Roy Tam
commit f8662e9c1f
5 changed files with 34 additions and 467 deletions

View file

@ -45,7 +45,7 @@ this.ChromeManifestParser = {
* @return Array of objects describing each manifest instruction, in the form:
* { type: instruction-type, baseURI: string-uri, args: [arguments] }
**/
parseSync: function CMP_parseSync(aURI) {
parseSync: function(aURI) {
function parseLine(aLine) {
let line = aLine.trim();
if (line.length == 0 || line.charAt(0) == '#')
@ -80,14 +80,14 @@ this.ChromeManifestParser = {
lines.forEach(parseLine.bind(this));
return data;
},
_readFromJar: function CMP_readFromJar(aURI) {
_readFromJar: function(aURI) {
let data = "";
let entries = [];
let readers = [];
try {
// Deconstrict URI, which can be nested jar: URIs.
// Deconstrict URI, which can be nested jar: URIs.
let uri = aURI.clone();
while (uri instanceof Ci.nsIJARURI) {
entries.push(uri.JAREntry);
@ -99,7 +99,7 @@ this.ChromeManifestParser = {
createInstance(Ci.nsIZipReader);
reader.open(uri.QueryInterface(Ci.nsIFileURL).file);
readers.push(reader);
// Open the nested jars.
for (let i = entries.length - 1; i > 0; i--) {
let innerReader = Cc["@mozilla.org/libjar/zip-reader;1"].
@ -108,7 +108,7 @@ this.ChromeManifestParser = {
readers.push(innerReader);
reader = innerReader;
}
// First entry is the actual file we want to read.
let zis = reader.getInputStream(entries[0]);
data = NetUtil.readInputStreamToString(zis, zis.available());
@ -120,15 +120,15 @@ this.ChromeManifestParser = {
flushJarCache(readers[i].file);
}
}
return data;
},
_readFromFile: function CMP_readFromFile(aURI) {
_readFromFile: function(aURI) {
let file = aURI.QueryInterface(Ci.nsIFileURL).file;
if (!file.exists() || !file.isFile())
return "";
let data = "";
let fis = Cc["@mozilla.org/network/file-input-stream;1"].
createInstance(Ci.nsIFileInputStream);
@ -151,9 +151,7 @@ this.ChromeManifestParser = {
* Instruction type to filter by.
* @return True if any matching instructions were found in the manifest.
*/
hasType: function CMP_hasType(aManifest, aType) {
return aManifest.some(function hasType_matchEntryType(aEntry) {
return aEntry.type == aType;
});
hasType: function(aManifest, aType) {
return aManifest.some(entry => entry.type == aType);
}
};