Bug 1374237 - Part 1: Uniquify the name of the convert functions in ext-cookies.js and ext-bookmarks.js, r=mixedpuppy

Also declare all top-level functions in those files via const.

MozReview-Commit-ID: FsIEHVeotX8

--HG--
extra : rebase_source : 8257fac9824fddb78bf79c6d45eb16f6c0797603
This commit is contained in:
Bob Silverberg 2017-06-21 14:19:39 -04:00
Родитель c6b128dddf
Коммит bb1231853d
2 изменённых файлов: 25 добавлений и 25 удалений

Просмотреть файл

@ -10,7 +10,7 @@ XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
let listenerCount = 0;
function getTree(rootGuid, onlyChildren) {
const getTree = (rootGuid, onlyChildren) => {
function convert(node, parent) {
let treenode = {
id: node.guid,
@ -57,9 +57,9 @@ function getTree(rootGuid, onlyChildren) {
// It seems like the array always just contains the root node.
return [treenode];
}).catch(e => Promise.reject({message: e.message}));
}
};
function convert(result) {
const convertBookmarks = result => {
let node = {
id: result.guid,
title: result.title || "",
@ -78,7 +78,7 @@ function convert(result) {
}
return node;
}
};
let observer = {
skipTags: true,
@ -163,19 +163,19 @@ let observer = {
};
EventEmitter.decorate(observer);
function decrementListeners() {
const decrementListeners = () => {
listenerCount -= 1;
if (!listenerCount) {
PlacesUtils.bookmarks.removeObserver(observer);
}
}
};
function incrementListeners() {
const incrementListeners = () => {
listenerCount++;
if (listenerCount == 1) {
PlacesUtils.bookmarks.addObserver(observer);
}
}
};
this.bookmarks = class extends ExtensionAPI {
getAPI(context) {
@ -191,7 +191,7 @@ this.bookmarks = class extends ExtensionAPI {
if (!bookmark) {
throw new Error("Bookmark not found");
}
bookmarks.push(convert(bookmark));
bookmarks.push(convertBookmarks(bookmark));
}
return bookmarks;
} catch (error) {
@ -213,11 +213,11 @@ this.bookmarks = class extends ExtensionAPI {
},
search: function(query) {
return PlacesUtils.bookmarks.search(query).then(result => result.map(convert));
return PlacesUtils.bookmarks.search(query).then(result => result.map(convertBookmarks));
},
getRecent: function(numberOfItems) {
return PlacesUtils.bookmarks.getRecent(numberOfItems).then(result => result.map(convert));
return PlacesUtils.bookmarks.getRecent(numberOfItems).then(result => result.map(convertBookmarks));
},
create: function(bookmark) {
@ -244,7 +244,7 @@ this.bookmarks = class extends ExtensionAPI {
}
try {
return PlacesUtils.bookmarks.insert(info).then(convert)
return PlacesUtils.bookmarks.insert(info).then(convertBookmarks)
.catch(error => Promise.reject({message: error.message}));
} catch (e) {
return Promise.reject({message: `Invalid bookmark: ${JSON.stringify(info)}`});
@ -263,7 +263,7 @@ this.bookmarks = class extends ExtensionAPI {
PlacesUtils.bookmarks.DEFAULT_INDEX : destination.index;
try {
return PlacesUtils.bookmarks.update(info).then(convert)
return PlacesUtils.bookmarks.update(info).then(convertBookmarks)
.catch(error => Promise.reject({message: error.message}));
} catch (e) {
return Promise.reject({message: `Invalid bookmark: ${JSON.stringify(info)}`});
@ -283,7 +283,7 @@ this.bookmarks = class extends ExtensionAPI {
}
try {
return PlacesUtils.bookmarks.update(info).then(convert)
return PlacesUtils.bookmarks.update(info).then(convertBookmarks)
.catch(error => Promise.reject({message: error.message}));
} catch (e) {
return Promise.reject({message: `Invalid bookmark: ${JSON.stringify(info)}`});

Просмотреть файл

@ -10,7 +10,7 @@ XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
/* globals DEFAULT_STORE, PRIVATE_STORE */
function convert({cookie, isPrivate}) {
const convertCookie = ({cookie, isPrivate}) => {
let result = {
name: cookie.name,
value: cookie.value,
@ -35,15 +35,15 @@ function convert({cookie, isPrivate}) {
}
return result;
}
};
function isSubdomain(otherDomain, baseDomain) {
const isSubdomain = (otherDomain, baseDomain) => {
return otherDomain == baseDomain || otherDomain.endsWith("." + baseDomain);
}
};
// Checks that the given extension has permission to set the given cookie for
// the given URI.
function checkSetCookiePermissions(extension, uri, cookie) {
const checkSetCookiePermissions = (extension, uri, cookie) => {
// Permission checks:
//
// - If the extension does not have permissions for the specified
@ -129,9 +129,9 @@ function checkSetCookiePermissions(extension, uri, cookie) {
// same origin policy enforcement, but no-one implements this.
return true;
}
};
function* query(detailsIn, props, context) {
const query = function* (detailsIn, props, context) {
// Different callers want to filter on different properties. |props|
// tells us which ones they're interested in.
let details = {};
@ -268,7 +268,7 @@ function* query(detailsIn, props, context) {
yield {cookie, isPrivate, storeId};
}
}
}
};
this.cookies = class extends ExtensionAPI {
getAPI(context) {
@ -278,7 +278,7 @@ this.cookies = class extends ExtensionAPI {
get: function(details) {
// FIXME: We don't sort by length of path and creation time.
for (let cookie of query(details, ["url", "name", "storeId"], context)) {
return Promise.resolve(convert(cookie));
return Promise.resolve(convertCookie(cookie));
}
// Found no match.
@ -287,7 +287,7 @@ this.cookies = class extends ExtensionAPI {
getAll: function(details) {
let allowed = ["url", "name", "domain", "path", "secure", "session", "storeId"];
let result = Array.from(query(details, allowed, context), convert);
let result = Array.from(query(details, allowed, context), convertCookie);
return Promise.resolve(result);
},
@ -384,7 +384,7 @@ this.cookies = class extends ExtensionAPI {
cookie.QueryInterface(Ci.nsICookie2);
if (extension.whiteListedHosts.matchesCookie(cookie)) {
fire.async({removed, cookie: convert({cookie, isPrivate: topic == "private-cookie-changed"}), cause});
fire.async({removed, cookie: convertCookie({cookie, isPrivate: topic == "private-cookie-changed"}), cause});
}
};