Bug 887889 - Limit scope of executeTransaction closure r=mak

MozReview-Commit-ID: 9d2xh4Qxs3q

--HG--
extra : rebase_source : 07be98bce61af38cbb0932c51bf3e622365f6329
This commit is contained in:
Doug Thayer 2018-03-27 10:30:37 -07:00
Родитель 6196d94bec
Коммит b14f6090bc
1 изменённых файлов: 34 добавлений и 23 удалений

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

@ -49,6 +49,18 @@ cache.set = function CPS_cache_set(group, name, val) {
const privModeStorage = new ContentPrefStore(); const privModeStorage = new ContentPrefStore();
function executeStatementsInTransaction(conn, stmts) {
return conn.executeTransaction(async () => {
let rows = [];
for (let {sql, params, cachable} of stmts) {
let execute = cachable ? conn.executeCached : conn.execute;
let stmtRows = await execute.call(conn, sql, params);
rows = rows.concat(stmtRows);
}
return rows;
});
}
ContentPrefService2.prototype = { ContentPrefService2.prototype = {
// XPCOM Plumbing // XPCOM Plumbing
@ -770,38 +782,37 @@ ContentPrefService2.prototype = {
*/ */
_execStmts: async function CPS2__execStmts(stmts, callbacks) { _execStmts: async function CPS2__execStmts(stmts, callbacks) {
let conn = await this.conn; let conn = await this.conn;
let rows;
let ok = true; let ok = true;
let gotRow = false; try {
let { onRow, onError } = callbacks; rows = await executeStatementsInTransaction(conn, stmts);
await conn.executeTransaction(async () => { } catch (e) {
for (let {sql, params, cachable} of stmts) { ok = false;
if (callbacks.onError) {
try { try {
let execute = cachable ? conn.executeCached : conn.execute; callbacks.onError(e);
await execute.call(conn, sql, params, row => {
gotRow = true;
if (onRow) {
try {
onRow(row);
} catch (e) {
Cu.reportError(e);
}
}
});
} catch (e) { } catch (e) {
try { Cu.reportError(e);
onError(Cr.NS_ERROR_FAILURE); }
} catch (err) { } else {
ok = false; Cu.reportError(e);
Cu.reportError(e); }
} }
if (rows && callbacks.onRow) {
for (let row of rows) {
try {
callbacks.onRow(row);
} catch (e) {
Cu.reportError(e);
} }
} }
}); }
try { try {
callbacks.onDone(ok ? Ci.nsIContentPrefCallback2.COMPLETE_OK : callbacks.onDone(ok ? Ci.nsIContentPrefCallback2.COMPLETE_OK :
Ci.nsIContentPrefCallback2.COMPLETE_ERROR, Ci.nsIContentPrefCallback2.COMPLETE_ERROR,
ok, gotRow); ok, rows && rows.length > 0);
} catch (e) { } catch (e) {
Cu.reportError(e); Cu.reportError(e);
} }