From 143fdd5f2bf50b2aced57a2fe203d1d4ac02cab9 Mon Sep 17 00:00:00 2001 From: Sylvester Keil Date: Mon, 30 Jul 2018 10:18:11 +0200 Subject: [PATCH] Revert "Remove legacy iterator protocol use in Zotero.DB" Reverting this until we can use Fx60 for testing. This reverts commit dfe412d4488426a8d8d2bcacf8c37f20ae5d863e. --- chrome/content/zotero/xpcom/db.js | 22 +++++++++++++--------- test/tests/dbTest.js | 6 +++--- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/chrome/content/zotero/xpcom/db.js b/chrome/content/zotero/xpcom/db.js index dd819f17c2..3c0c22dc7f 100644 --- a/chrome/content/zotero/xpcom/db.js +++ b/chrome/content/zotero/xpcom/db.js @@ -584,18 +584,22 @@ Zotero.DBConnection.prototype.queryAsync = Zotero.Promise.coroutine(function* (s } var failed = false; if (options && options.onRow) { - // Wrap onRow to cancel iteration by default and reject the promise - // on any error, which Sqlite.jsm does not do. - onRow = function (row, cancel) { + // Errors in onRow don't stop the query unless StopIteration is thrown + onRow = function (row) { try { - options.onRow(row, () => { - Zotero.debug("Query cancelled", 3); - cancel(); - }); + options.onRow(row); } catch (e) { - failed = e; - cancel(); + // If the onRow throws a StopIteration, stop gracefully + if (e instanceof StopIteration) { + Zotero.debug("Query cancelled", 3); + } + // Otherwise, mark the promise as rejected, which Sqlite.jsm doesn't do + // on a StopIteration by default + else { + failed = e; + } + throw StopIteration; } } } diff --git a/test/tests/dbTest.js b/test/tests/dbTest.js index 1da155ce29..a83c89afb0 100644 --- a/test/tests/dbTest.js +++ b/test/tests/dbTest.js @@ -151,16 +151,16 @@ describe("Zotero.DB", function() { assert.equal(e.message, "Failed"); }); - it("should stop gracefully if onRow is cancelled", function* () { + it("should stop gracefully if onRow throws a StopIteration", function* () { var i = 0; var rows = []; yield Zotero.DB.queryAsync( "SELECT * FROM " + tmpTable, false, { - onRow: function (row, cancel) { + onRow: function (row) { if (i > 0) { - return cancel(); + throw StopIteration; } rows.push(row.getResultByIndex(0)); i++;