From 05d19fc6aa468cdc27e28ee94856ea616fdae3ff Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Mon, 30 Jun 2025 12:59:33 -0400 Subject: [PATCH] Replace Bluebird with async in xpcom/ --- chrome/content/zotero/xpcom/api.js | 10 +- chrome/content/zotero/xpcom/attachments.js | 134 +++---- .../content/zotero/xpcom/browserDownload.js | 4 +- chrome/content/zotero/xpcom/cite.js | 8 +- .../content/zotero/xpcom/collectionTreeRow.js | 51 ++- chrome/content/zotero/xpcom/cookieSandbox.js | 20 +- .../content/zotero/xpcom/data/cachedTypes.js | 46 +-- .../content/zotero/xpcom/data/collection.js | 124 +++--- .../content/zotero/xpcom/data/collections.js | 14 +- chrome/content/zotero/xpcom/data/creators.js | 34 +- .../content/zotero/xpcom/data/dataObject.js | 130 +++--- .../content/zotero/xpcom/data/dataObjects.js | 124 +++--- chrome/content/zotero/xpcom/data/feed.js | 132 +++--- chrome/content/zotero/xpcom/data/feedItem.js | 64 +-- chrome/content/zotero/xpcom/data/feedItems.js | 52 +-- chrome/content/zotero/xpcom/data/feeds.js | 55 +-- chrome/content/zotero/xpcom/data/group.js | 60 +-- chrome/content/zotero/xpcom/data/groups.js | 8 +- chrome/content/zotero/xpcom/data/item.js | 364 ++++++++--------- .../content/zotero/xpcom/data/itemFields.js | 42 +- chrome/content/zotero/xpcom/data/items.js | 108 ++--- chrome/content/zotero/xpcom/data/libraries.js | 44 +- chrome/content/zotero/xpcom/data/library.js | 148 +++---- chrome/content/zotero/xpcom/data/notes.js | 12 +- chrome/content/zotero/xpcom/data/relations.js | 36 +- chrome/content/zotero/xpcom/data/search.js | 152 +++---- .../zotero/xpcom/data/searchConditions.js | 10 +- chrome/content/zotero/xpcom/data/searches.js | 22 +- chrome/content/zotero/xpcom/data/tags.js | 88 ++-- chrome/content/zotero/xpcom/dataDirectory.js | 134 +++---- chrome/content/zotero/xpcom/db.js | 30 +- chrome/content/zotero/xpcom/debug.js | 6 +- chrome/content/zotero/xpcom/dictionaries.js | 2 +- chrome/content/zotero/xpcom/duplicates.js | 16 +- chrome/content/zotero/xpcom/editorInstance.js | 10 +- chrome/content/zotero/xpcom/feedReader.js | 8 +- chrome/content/zotero/xpcom/file.js | 82 ++-- chrome/content/zotero/xpcom/fileHandlers.js | 4 +- chrome/content/zotero/xpcom/fulltext.js | 244 ++++++------ chrome/content/zotero/xpcom/history.js | 2 +- chrome/content/zotero/xpcom/http.js | 46 ++- .../zotero/xpcom/httpIntegrationClient.js | 46 +-- chrome/content/zotero/xpcom/id.js | 6 +- chrome/content/zotero/xpcom/integration.js | 317 ++++++++------- chrome/content/zotero/xpcom/ipc.js | 24 +- chrome/content/zotero/xpcom/locateManager.js | 30 +- chrome/content/zotero/xpcom/mime.js | 10 +- .../content/zotero/xpcom/mimeTypeHandler.js | 10 +- chrome/content/zotero/xpcom/notifier.js | 16 +- .../content/zotero/xpcom/pdfWorker/manager.js | 10 +- .../content/zotero/xpcom/preferencePanes.js | 6 +- chrome/content/zotero/xpcom/prefs.js | 16 +- chrome/content/zotero/xpcom/profile.js | 43 +- chrome/content/zotero/xpcom/progressQueue.js | 8 +- chrome/content/zotero/xpcom/progressWindow.js | 30 +- chrome/content/zotero/xpcom/proxy.js | 76 ++-- chrome/content/zotero/xpcom/quickCopy.js | 57 ++- chrome/content/zotero/xpcom/reader.js | 8 +- .../content/zotero/xpcom/recognizeDocument.js | 4 +- chrome/content/zotero/xpcom/retractions.js | 4 +- chrome/content/zotero/xpcom/schema.js | 40 +- chrome/content/zotero/xpcom/server/server.js | 6 +- .../zotero/xpcom/server/server_connector.js | 60 +-- chrome/content/zotero/xpcom/standalone.js | 16 +- .../zotero/xpcom/storage/storageEngine.js | 46 +-- .../zotero/xpcom/storage/storageLocal.js | 106 ++--- .../zotero/xpcom/storage/storageRequest.js | 6 +- .../zotero/xpcom/storage/storageUtilities.js | 4 +- chrome/content/zotero/xpcom/storage/webdav.js | 146 +++---- chrome/content/zotero/xpcom/storage/zfs.js | 122 +++--- chrome/content/zotero/xpcom/style.js | 86 ++-- chrome/content/zotero/xpcom/sync.js | 4 +- .../zotero/xpcom/sync/syncAPIClient.js | 108 ++--- .../content/zotero/xpcom/sync/syncEngine.js | 377 +++++++++--------- .../zotero/xpcom/sync/syncEventListeners.js | 4 +- .../zotero/xpcom/sync/syncFullTextEngine.js | 63 ++- chrome/content/zotero/xpcom/sync/syncLocal.js | 239 +++++------ .../content/zotero/xpcom/sync/syncRunner.js | 140 +++---- .../zotero/xpcom/sync/syncUtilities.js | 6 +- chrome/content/zotero/xpcom/syncedSettings.js | 40 +- .../xpcom/translation/translate_firefox.js | 68 ++-- .../xpcom/translation/translate_item.js | 70 ++-- .../zotero/xpcom/translation/translators.js | 74 ++-- chrome/content/zotero/xpcom/uiProperties.js | 4 +- chrome/content/zotero/xpcom/uri.js | 34 +- chrome/content/zotero/xpcom/users.js | 14 +- .../zotero/xpcom/utilities_internal.js | 28 +- chrome/content/zotero/xpcom/zotero.js | 166 ++++---- 88 files changed, 2736 insertions(+), 2742 deletions(-) diff --git a/chrome/content/zotero/xpcom/api.js b/chrome/content/zotero/xpcom/api.js index c8d5ec246e..200e8e9b15 100644 --- a/chrome/content/zotero/xpcom/api.js +++ b/chrome/content/zotero/xpcom/api.js @@ -38,7 +38,7 @@ Zotero.API = { /** * @return {(Zotero.Collection|Zotero.Search|Zotero.Item)[]} */ - getResultsFromParams: Zotero.Promise.coroutine(function* (params) { + getResultsFromParams: async function (params) { if (!params.objectType) { throw new Error("objectType not specified"); } @@ -93,7 +93,7 @@ Zotero.API = { var s2 = new Zotero.Search(); s2.setScope(s); - var ids = yield s2.search(); + var ids = await s2.search(); if (params.objectKey) { let id = Zotero.Items.getIDFromLibraryAndKey(s.libraryID, params.objectKey); ids = ids.includes(id) ? [id] : []; @@ -128,7 +128,7 @@ Zotero.API = { s.addCondition('noChildren', 'true'); }*/ - var ids = yield s.search(); + var ids = await s.search(); } let itemKeys = new Set(params.itemKey || []); @@ -146,7 +146,7 @@ Zotero.API = { return itemKeys.has(key); }); } - results = yield Zotero.Items.getAsync(ids); + results = await Zotero.Items.getAsync(ids); } } else { @@ -154,7 +154,7 @@ Zotero.API = { } return results; - }), + }, getLibraryPrefix: function (libraryID) { diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index 0ebfbc7fa1..3998ce6e36 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -56,7 +56,7 @@ Zotero.Attachments = new function () { * @param {Object} [options.saveOptions] - Options to pass to Zotero.Item::save() * @return {Promise} */ - this.importFromFile = Zotero.Promise.coroutine(function* (options) { + this.importFromFile = async function (options) { Zotero.debug('Importing attachment from file'); var libraryID = options.libraryID; @@ -88,7 +88,7 @@ Zotero.Attachments = new function () { var attachmentItem, newFile, destDir; try { - yield Zotero.DB.executeTransaction(async function () { + await Zotero.DB.executeTransaction(async function () { // Create a new attachment attachmentItem = new Zotero.Item('attachment'); if (parentItemID) { @@ -143,7 +143,7 @@ Zotero.Attachments = new function () { await attachmentItem.save(saveOptions); }.bind(this)); try { - yield _postProcessFile(attachmentItem); + await _postProcessFile(attachmentItem); } catch (e) { Zotero.logError(e); @@ -155,8 +155,8 @@ Zotero.Attachments = new function () { // Clean up try { - if (destDir && (yield OS.File.exists(destDir))) { - yield OS.File.removeDir(destDir); + if (destDir && ((await OS.File.exists(destDir)))) { + await OS.File.removeDir(destDir); } } catch (e) { @@ -167,7 +167,7 @@ Zotero.Attachments = new function () { } return attachmentItem; - }); + }; /** @@ -180,14 +180,14 @@ Zotero.Attachments = new function () { * @param {Object} [options.saveOptions] - Options to pass to Zotero.Item::save() * @return {Promise} */ - this.linkFromFile = Zotero.Promise.coroutine(function* (options) { + this.linkFromFile = async function (options) { Zotero.debug('Linking attachment from file'); var file = Zotero.File.pathToFile(options.file); var parentItemID = options.parentItemID; var title = options.title; var collections = options.collections; - var contentType = options.contentType || (yield Zotero.MIME.getMIMETypeFromFile(file)); + var contentType = options.contentType || ((await Zotero.MIME.getMIMETypeFromFile(file))); var charset = options.charset; var saveOptions = options.saveOptions; @@ -195,7 +195,7 @@ Zotero.Attachments = new function () { throw new Error("parentItemID and collections cannot both be provided"); } - var item = yield _addToDB({ + var item = await _addToDB({ file, title, linkMode: this.LINK_MODE_LINKED_FILE, @@ -206,13 +206,13 @@ Zotero.Attachments = new function () { saveOptions }); try { - yield _postProcessFile(item); + await _postProcessFile(item); } catch (e) { Zotero.logError(e); } return item; - }); + }; /** @@ -268,7 +268,7 @@ Zotero.Attachments = new function () { // If the file is found (which requires a base directory being set and the file existing), // index it var file = this.resolveRelativePath(path); - if (file && await OS.File.exists(file)) { + if (file && (await OS.File.exists(file))) { try { await _postProcessFile(item); } @@ -286,7 +286,7 @@ Zotero.Attachments = new function () { * @param {Object} [options.saveOptions] - Options to pass to Zotero.Item::save() * @return {Promise} */ - this.importSnapshotFromFile = Zotero.Promise.coroutine(function* (options) { + this.importSnapshotFromFile = async function (options) { Zotero.debug('Importing snapshot from file'); var file = Zotero.File.pathToFile(options.file); @@ -317,7 +317,7 @@ Zotero.Attachments = new function () { var attachmentItem, itemID, destDir, newPath; try { - yield Zotero.DB.executeTransaction(async function () { + await Zotero.DB.executeTransaction(async function () { // Create a new attachment attachmentItem = new Zotero.Item('attachment'); if (libraryID) { @@ -356,7 +356,7 @@ Zotero.Attachments = new function () { } }.bind(this)); try { - yield _postProcessFile(attachmentItem); + await _postProcessFile(attachmentItem); } catch (e) { Zotero.logError(e); @@ -378,7 +378,7 @@ Zotero.Attachments = new function () { throw e; } return attachmentItem; - }); + }; /** @@ -489,7 +489,7 @@ Zotero.Attachments = new function () { throw new Error("'attachment' must be an embedded image"); } - if (!await attachment.fileExists()) { + if (!(await attachment.fileExists())) { throw new Error("Image attachment file doesn't exist"); } @@ -522,7 +522,7 @@ Zotero.Attachments = new function () { * @param {Object} [options.saveOptions] - Options to pass to Zotero.Item::save() * @return {Promise} - A promise for the created attachment item */ - this.importFromURL = Zotero.Promise.coroutine(function* (options) { + this.importFromURL = async function (options) { var libraryID = options.libraryID; var url = options.url; var parentItemID = options.parentItemID; @@ -654,9 +654,9 @@ Zotero.Attachments = new function () { return process(contentType, Zotero.MIME.hasNativeHandler(contentType)); } - var args = yield Zotero.MIME.getMIMETypeFromURL(url, cookieSandbox); + var args = await Zotero.MIME.getMIMETypeFromURL(url, cookieSandbox); return process(...args); - }); + }; /** @@ -743,7 +743,7 @@ Zotero.Attachments = new function () { * @param {Object} [options.saveOptions] - Options to pass to Zotero.Item::save() * @return {Promise} - A promise for the created attachment item */ - this.linkFromURL = Zotero.Promise.coroutine(function* (options) { + this.linkFromURL = async function (options) { Zotero.debug('Linking attachment from URL'); var url = options.url; @@ -807,7 +807,7 @@ Zotero.Attachments = new function () { collections, saveOptions, }); - }); + }; /** @@ -817,7 +817,7 @@ Zotero.Attachments = new function () { * @param {Object} [options.saveOptions] - Options to pass to Zotero.Item::save() * @return {Promise} */ - this.linkFromDocument = Zotero.Promise.coroutine(function* (options) { + this.linkFromDocument = async function (options) { Zotero.debug('Linking attachment from document'); var document = options.document; @@ -833,7 +833,7 @@ Zotero.Attachments = new function () { var title = document.title; // TODO: don't use Mozilla-generated title for images, etc. var contentType = document.contentType; - var item = yield _addToDB({ + var item = await _addToDB({ url, title, linkMode: this.LINK_MODE_LINKED_URL, @@ -845,11 +845,11 @@ Zotero.Attachments = new function () { }); if (Zotero.MIME.isTextType(document.contentType)) { - yield Zotero.Fulltext.indexDocument(document, item.id); + await Zotero.Fulltext.indexDocument(document, item.id); } return item; - }); + }; /** @@ -859,7 +859,7 @@ Zotero.Attachments = new function () { * @param {Object} [options.saveOptions] - Options to pass to Zotero.Item::save() * @return {Promise} - A promise for the created attachment item */ - this.importFromDocument = Zotero.Promise.coroutine(function* (options) { + this.importFromDocument = async function (options) { Zotero.debug('Importing attachment from ' + (options.document ? 'document' : 'browser')); var libraryID = options.libraryID; @@ -885,7 +885,7 @@ Zotero.Attachments = new function () { contentType = "application/pdf"; } - var tmpDir = (yield this.createTemporaryStorageDirectory()).path; + var tmpDir = ((await this.createTemporaryStorageDirectory())).path; try { var fileName = Zotero.File.truncateFileName(this._getFileNameFromURL(url, contentType), 100); var tmpFile = OS.Path.join(tmpDir, fileName); @@ -909,24 +909,24 @@ Zotero.Attachments = new function () { if (browser) { // If we have a full hidden browser, use SingleFile Zotero.debug('Getting snapshot with HiddenBrowser.snapshot()'); - let snapshotContent = yield browser.snapshot(); + let snapshotContent = await browser.snapshot(); // Write main HTML file to disk - yield Zotero.File.putContentsAsync(tmpFile, snapshotContent); + await Zotero.File.putContentsAsync(tmpFile, snapshotContent); } else { // Fallback to nsIWebBrowserPersist Zotero.debug('Saving document with saveDocument()'); - yield Zotero.Utilities.Internal.saveDocument(document, tmpFile); + await Zotero.Utilities.Internal.saveDocument(document, tmpFile); } } else { - yield Zotero.HTTP.download(url, tmpFile); + await Zotero.HTTP.download(url, tmpFile); } var attachmentItem; var destDir; - yield Zotero.DB.executeTransaction(async function () { + await Zotero.DB.executeTransaction(async function () { // Create a new attachment attachmentItem = new Zotero.Item('attachment'); if (libraryID) { @@ -954,7 +954,7 @@ Zotero.Attachments = new function () { await OS.File.move(tmpDir, destDir); }.bind(this)); - yield Zotero.FullText.queueItem(attachmentItem); + await Zotero.FullText.queueItem(attachmentItem); } catch (e) { Zotero.debug(e, 1); @@ -962,10 +962,10 @@ Zotero.Attachments = new function () { // Clean up try { if (tmpDir) { - yield OS.File.removeDir(tmpDir, { ignoreAbsent: true }); + await OS.File.removeDir(tmpDir, { ignoreAbsent: true }); } if (destDir) { - yield OS.File.removeDir(destDir, { ignoreAbsent: true }); + await OS.File.removeDir(destDir, { ignoreAbsent: true }); } } catch (e) { @@ -976,7 +976,7 @@ Zotero.Attachments = new function () { } return attachmentItem; - }); + }; /** * Save an attachment from a nsIInputStream @@ -1238,7 +1238,7 @@ Zotero.Attachments = new function () { } - this.InvalidPDFException = function() { + this.InvalidPDFException = function () { this.message = "Downloaded file was not a supported type (PDF or EPUB)"; this.stack = new Error().stack; }; @@ -2630,7 +2630,7 @@ Zotero.Attachments = new function () { * @param {Number} itemID - Item id * @return {Promise} - Path of new directory */ - this.createDirectoryForItem = Zotero.Promise.coroutine(function* (item) { + this.createDirectoryForItem = async function (item) { if (!(item instanceof Zotero.Item)) { throw new Error("'item' must be a Zotero.Item"); } @@ -2643,11 +2643,11 @@ Zotero.Attachments = new function () { } } else { - yield OS.File.removeDir(dir, { ignoreAbsent: true }); + await OS.File.removeDir(dir, { ignoreAbsent: true }); } - yield Zotero.File.createDirectoryIfMissingAsync(dir); + await Zotero.File.createDirectoryIfMissingAsync(dir); return dir; - }); + }; this.getStorageDirectory = function (item) { @@ -2686,14 +2686,14 @@ Zotero.Attachments = new function () { } - this.createTemporaryStorageDirectory = Zotero.Promise.coroutine(function* () { + this.createTemporaryStorageDirectory = async function () { var tmpDir = Zotero.getStorageDirectory(); tmpDir.append("tmp-" + Zotero.Utilities.randomString(6)); - yield OS.File.makeDir(tmpDir.path, { + await OS.File.makeDir(tmpDir.path, { unixMode: 0o755 }); return tmpDir; - }); + }; /** @@ -2758,7 +2758,7 @@ Zotero.Attachments = new function () { } - this.hasMultipleFiles = Zotero.Promise.coroutine(function* (item) { + this.hasMultipleFiles = async function (item) { if (!item.isAttachment()) { throw new Error("Item is not an attachment"); } @@ -2780,7 +2780,7 @@ Zotero.Attachments = new function () { return false; } - var path = yield item.getFilePathAsync(); + var path = await item.getFilePathAsync(); if (!path) { throw new Error("File not found"); } @@ -2789,7 +2789,7 @@ Zotero.Attachments = new function () { var parent = PathUtils.parent(path); var iterator = new OS.File.DirectoryIterator(parent); try { - yield iterator.forEach((entry) => { + await iterator.forEach((entry) => { if (entry.name.startsWith('.')) { return; } @@ -2803,7 +2803,7 @@ Zotero.Attachments = new function () { iterator.close(); } return numFiles > 1; - }); + }; /** @@ -2813,7 +2813,7 @@ Zotero.Attachments = new function () { * * @param {Zotero.Item} item Attachment item */ - this.getNumFiles = Zotero.Promise.coroutine(function* (item) { + this.getNumFiles = async function (item) { if (!item.isAttachment()) { throw new Error("Item is not an attachment"); } @@ -2832,7 +2832,7 @@ Zotero.Attachments = new function () { return 1; } - var path = yield item.getFilePathAsync(); + var path = await item.getFilePathAsync(); if (!path) { throw new Error("File not found"); } @@ -2841,7 +2841,7 @@ Zotero.Attachments = new function () { var parent = PathUtils.parent(path); var iterator = new OS.File.DirectoryIterator(parent); try { - yield iterator.forEach(function (entry) { + await iterator.forEach(function (entry) { if (entry.name.startsWith('.')) { return; } @@ -2852,7 +2852,7 @@ Zotero.Attachments = new function () { iterator.close(); } return numFiles; - }); + }; /** @@ -2860,7 +2860,7 @@ Zotero.Attachments = new function () { * @param {Boolean} [skipHidden=true] - Don't count hidden files * @return {Promise} - Promise for the total file size in bytes */ - this.getTotalFileSize = Zotero.Promise.coroutine(function* (item, skipHidden = true) { + this.getTotalFileSize = async function (item, skipHidden = true) { if (!item.isAttachment()) { throw new Error("Item is not an attachment"); } @@ -2876,20 +2876,20 @@ Zotero.Attachments = new function () { throw new Error("Invalid attachment link mode"); } - var path = yield item.getFilePathAsync(); + var path = await item.getFilePathAsync(); if (!path) { throw new Error("File not found"); } if (linkMode == Zotero.Attachments.LINK_MODE_LINKED_FILE) { - return (yield OS.File.stat(path)).size; + return ((await OS.File.stat(path))).size; } var size = 0; var parent = PathUtils.parent(path); let iterator = new OS.File.DirectoryIterator(parent); try { - yield iterator.forEach(function (entry) { + await iterator.forEach(function (entry) { if (skipHidden && entry.name.startsWith('.')) { return; } @@ -2914,7 +2914,7 @@ Zotero.Attachments = new function () { iterator.close(); } return size; - }); + }; /** @@ -2986,7 +2986,7 @@ Zotero.Attachments = new function () { * * @return {Zotero.Item} - The new attachment */ - this.copyAttachmentToLibrary = Zotero.Promise.coroutine(function* (attachment, libraryID, parentItemID) { + this.copyAttachmentToLibrary = async function (attachment, libraryID, parentItemID) { if (attachment.libraryID == libraryID) { throw new Error("Attachment is already in library " + libraryID); } @@ -3001,18 +3001,18 @@ Zotero.Attachments = new function () { if (parentItemID) { newAttachment.parentID = parentItemID; } - yield newAttachment.save(); + await newAttachment.save(); // Copy over files if they exist - if (newAttachment.isStoredFileAttachment() && (yield attachment.fileExists())) { + if (newAttachment.isStoredFileAttachment() && ((await attachment.fileExists()))) { let dir = Zotero.Attachments.getStorageDirectory(attachment); - let newDir = yield Zotero.Attachments.createDirectoryForItem(newAttachment); - yield Zotero.File.copyDirectory(dir, newDir); + let newDir = await Zotero.Attachments.createDirectoryForItem(newAttachment); + await Zotero.File.copyDirectory(dir, newDir); } - yield newAttachment.addLinkedItem(attachment); + await newAttachment.addLinkedItem(attachment); return newAttachment; - }); + }; this.convertLinkedFileToStoredFile = async function (item, options = {}) { @@ -3102,7 +3102,7 @@ Zotero.Attachments = new function () { }; - this._getFileNameFromURL = function(url, contentType) { + this._getFileNameFromURL = function (url, contentType) { url = Zotero.Utilities.Internal.parseURL(url); var fileBaseName = url.fileBaseName; @@ -3243,7 +3243,7 @@ Zotero.Attachments = new function () { * Determines if a given document is an instance of PDFJS * @return {Boolean} */ - this.isPDFJSDocument = function(doc) { + this.isPDFJSDocument = function (doc) { // pdf.js HACK // This may no longer be necessary (as of Fx 23) if(doc.contentType === "text/html") { diff --git a/chrome/content/zotero/xpcom/browserDownload.js b/chrome/content/zotero/xpcom/browserDownload.js index d61acd0914..e5927b5db0 100644 --- a/chrome/content/zotero/xpcom/browserDownload.js +++ b/chrome/content/zotero/xpcom/browserDownload.js @@ -150,7 +150,7 @@ Zotero.BrowserDownload = { }, Ci.nsIWebProgress.NOTIFY_LOCATION); hiddenBrowser.load(url); - let blob = await Zotero.Promise.race([ + let blob = await Promise.race([ onLoadTimeoutDeferred.promise, Zotero.Promise.delay(downloadTimeout).then(() => { if (!pdfLoaded) { @@ -235,7 +235,7 @@ Zotero.BrowserDownload = { Zotero.MIMETypeHandler.addHandlers("application/pdf", pdfMIMETypeHandler, true); Zotero.debug(`BrowserDownload: Awaiting the user to clear the captcha or timeout after ${downloadTimeout}`); - let pdfBlob = await Zotero.Promise.race([ + let pdfBlob = await Promise.race([ Zotero.Promise.delay(downloadTimeout).then(() => { if (!pdfFound) { throw new Error(`BrowserDownload: Loading PDF via document viewer timed out after ${downloadTimeout}ms`); diff --git a/chrome/content/zotero/xpcom/cite.js b/chrome/content/zotero/xpcom/cite.js index bfa0004e6b..da14316c0c 100644 --- a/chrome/content/zotero/xpcom/cite.js +++ b/chrome/content/zotero/xpcom/cite.js @@ -136,7 +136,7 @@ Zotero.Cite = { * @param {bib} citeproc-js bibliography object * @param {Set} itemsToRemove Set of items to remove */ - "removeFromBibliography":function(bib, itemsToRemove) { + "removeFromBibliography":function (bib, itemsToRemove) { var removeItems = []; for(let i in bib[0].entry_ids) { for(let j in bib[0].entry_ids[i]) { @@ -189,7 +189,7 @@ Zotero.Cite = { * @param {String} format The format of the output (html, text, or rtf) * @return {String} Bibliography or item list in specified format */ - "makeFormattedBibliographyOrCitationList":function(cslEngine, items, format, asCitationList) { + "makeFormattedBibliographyOrCitationList":function (cslEngine, items, format, asCitationList) { cslEngine.setOutputFormat(format); cslEngine.updateItems(items.map(item => item.id)); @@ -442,7 +442,7 @@ Zotero.Cite = { /** * Get a CSL abbreviation in the format expected by citeproc-js */ -Zotero.Cite.getAbbreviation = new function() { +Zotero.Cite.getAbbreviation = new function () { var abbreviations, abbreviationCategories; @@ -618,7 +618,7 @@ Zotero.Cite.System = function ({ automaticJournalAbbreviations, uppercaseSubtitl this.getAbbreviation = Zotero.Cite.getAbbreviation; } if (uppercaseSubtitles) { - this.uppercase_subtitles = true; // eslint-disable-line camelcase + this.uppercase_subtitles = true; } }; diff --git a/chrome/content/zotero/xpcom/collectionTreeRow.js b/chrome/content/zotero/xpcom/collectionTreeRow.js index 2187df4acc..aeb7c354b1 100644 --- a/chrome/content/zotero/xpcom/collectionTreeRow.js +++ b/chrome/content/zotero/xpcom/collectionTreeRow.js @@ -91,12 +91,12 @@ Zotero.CollectionTreeRow.prototype.isLibrary = function (includeGlobal) return this.type == 'library'; } -Zotero.CollectionTreeRow.prototype.isCollection = function() +Zotero.CollectionTreeRow.prototype.isCollection = function () { return this.type == 'collection'; } -Zotero.CollectionTreeRow.prototype.isSearch = function() +Zotero.CollectionTreeRow.prototype.isSearch = function () { return this.type == 'search'; } @@ -113,7 +113,7 @@ Zotero.CollectionTreeRow.prototype.isRetracted = function () { return this.type == 'retracted'; } -Zotero.CollectionTreeRow.prototype.isTrash = function() +Zotero.CollectionTreeRow.prototype.isTrash = function () { return this.type == 'trash'; } @@ -122,23 +122,23 @@ Zotero.CollectionTreeRow.prototype.isHeader = function () { return this.type == 'header'; } -Zotero.CollectionTreeRow.prototype.isPublications = function() { +Zotero.CollectionTreeRow.prototype.isPublications = function () { return this.type == 'publications'; } -Zotero.CollectionTreeRow.prototype.isGroup = function() { +Zotero.CollectionTreeRow.prototype.isGroup = function () { return this.type == 'group'; } -Zotero.CollectionTreeRow.prototype.isFeed = function() { +Zotero.CollectionTreeRow.prototype.isFeed = function () { return this.type == 'feed'; } -Zotero.CollectionTreeRow.prototype.isFeeds = function() { +Zotero.CollectionTreeRow.prototype.isFeeds = function () { return this.type == 'feeds'; } -Zotero.CollectionTreeRow.prototype.isFeedsOrFeed = function() { +Zotero.CollectionTreeRow.prototype.isFeedsOrFeed = function () { return this.isFeeds() || this.isFeed(); } @@ -146,17 +146,17 @@ Zotero.CollectionTreeRow.prototype.isSeparator = function () { return this.type == 'separator'; } -Zotero.CollectionTreeRow.prototype.isBucket = function() +Zotero.CollectionTreeRow.prototype.isBucket = function () { return this.type == 'bucket'; } -Zotero.CollectionTreeRow.prototype.isShare = function() +Zotero.CollectionTreeRow.prototype.isShare = function () { return this.type == 'share'; } -Zotero.CollectionTreeRow.prototype.isContainer = function() { +Zotero.CollectionTreeRow.prototype.isContainer = function () { return this.isLibrary(true) || this.isCollection() || this.isPublications() || this.isBucket() || this.isFeeds(); } @@ -226,12 +226,12 @@ Zotero.CollectionTreeRow.prototype.__defineGetter__('filesEditable', function () Zotero.CollectionTreeRow.visibilityGroups = {'feed': 'feed', 'feeds': 'feeds'}; -Zotero.CollectionTreeRow.prototype.__defineGetter__('visibilityGroup', function() { +Zotero.CollectionTreeRow.prototype.__defineGetter__('visibilityGroup', function () { return Zotero.CollectionTreeRow.visibilityGroups[this.type] || 'default'; }); -Zotero.CollectionTreeRow.prototype.getName = function() +Zotero.CollectionTreeRow.prototype.getName = function () { switch (this.type) { case 'library': @@ -285,8 +285,7 @@ Zotero.CollectionTreeRow.prototype.getTrashedCollections = async function () { }; -Zotero.CollectionTreeRow.prototype.getItems = Zotero.Promise.coroutine(function* () -{ +Zotero.CollectionTreeRow.prototype.getItems = async function () { switch (this.type) { // Fake results if this is a shared library case 'share': @@ -296,7 +295,7 @@ Zotero.CollectionTreeRow.prototype.getItems = Zotero.Promise.coroutine(function* return this.ref.getItems(); } - var ids = yield this.getSearchResults(); + var ids = await this.getSearchResults(); // Filter out items that exist in the items table (where search results come from) but that haven't // yet been registered. This helps prevent unloaded-data crashes when switching collections while @@ -313,18 +312,18 @@ Zotero.CollectionTreeRow.prototype.getItems = Zotero.Promise.coroutine(function* } return Zotero.Items.getAsync(ids); -}); +}; -Zotero.CollectionTreeRow.prototype.getSearchResults = Zotero.Promise.coroutine(function* (asTempTable) { +Zotero.CollectionTreeRow.prototype.getSearchResults = async function (asTempTable) { if (Zotero.CollectionTreeCache.lastTreeRow && Zotero.CollectionTreeCache.lastTreeRow.id !== this.id) { Zotero.CollectionTreeCache.clear(); } if(!Zotero.CollectionTreeCache.lastResults) { - let s = yield this.getSearchObject(); + let s = await this.getSearchObject(); Zotero.CollectionTreeCache.error = false; try { - Zotero.CollectionTreeCache.lastResults = yield s.search(); + Zotero.CollectionTreeCache.lastResults = await s.search(); } catch (e) { Zotero.logError(e); @@ -337,19 +336,19 @@ Zotero.CollectionTreeRow.prototype.getSearchResults = Zotero.Promise.coroutine(f if(asTempTable) { if(!Zotero.CollectionTreeCache.lastTempTable) { - Zotero.CollectionTreeCache.lastTempTable = yield Zotero.Search.idsToTempTable(Zotero.CollectionTreeCache.lastResults); + Zotero.CollectionTreeCache.lastTempTable = await Zotero.Search.idsToTempTable(Zotero.CollectionTreeCache.lastResults); } return Zotero.CollectionTreeCache.lastTempTable; } return Zotero.CollectionTreeCache.lastResults; -}); +}; /* * Returns the search object for the currently display * * This accounts for the collection, saved search, quicksearch, tags, etc. */ -Zotero.CollectionTreeRow.prototype.getSearchObject = Zotero.Promise.coroutine(function* () { +Zotero.CollectionTreeRow.prototype.getSearchObject = async function () { if (Zotero.CollectionTreeCache.lastTreeRow && Zotero.CollectionTreeCache.lastTreeRow.id !== this.id) { Zotero.CollectionTreeCache.clear(); } @@ -365,7 +364,7 @@ Zotero.CollectionTreeRow.prototype.getSearchObject = Zotero.Promise.coroutine(fu var s = this.ref; } else if (this.isDuplicates()) { - var s = yield this.ref.getSearchObject(); + var s = await this.ref.getSearchObject(); let tmpTable; for (let id in s.conditions) { let c = s.conditions[id]; @@ -442,7 +441,7 @@ Zotero.CollectionTreeRow.prototype.getSearchObject = Zotero.Promise.coroutine(fu Zotero.CollectionTreeCache.lastTreeRow = this; Zotero.CollectionTreeCache.lastSearch = s2; return s2; -}); +}; Zotero.CollectionTreeRow.prototype.getChildTags = function () { Zotero.warn("Zotero.CollectionTreeRow::getChildTags() is deprecated -- use getTags() instead"); @@ -485,7 +484,7 @@ Zotero.CollectionTreeRow.prototype.setTags = function (tags) { /* * Returns TRUE if saved search, quicksearch or tag filter */ -Zotero.CollectionTreeRow.prototype.isSearchMode = function() { +Zotero.CollectionTreeRow.prototype.isSearchMode = function () { switch (this.type) { case 'search': case 'publications': diff --git a/chrome/content/zotero/xpcom/cookieSandbox.js b/chrome/content/zotero/xpcom/cookieSandbox.js index 4832b074b0..c735c451bf 100755 --- a/chrome/content/zotero/xpcom/cookieSandbox.js +++ b/chrome/content/zotero/xpcom/cookieSandbox.js @@ -68,7 +68,7 @@ Zotero.CookieSandbox.init = function () { * Normalizes the host string: lower-case, remove leading period, some more cleanup * @param {String} host; */ -Zotero.CookieSandbox.normalizeHost = function(host) { +Zotero.CookieSandbox.normalizeHost = function (host) { return host.trim().toLowerCase().replace(/^\.+|[:\/].*/g, ''); } @@ -76,7 +76,7 @@ Zotero.CookieSandbox.normalizeHost = function(host) { * Normalizes the path string * @param {String} path; */ -Zotero.CookieSandbox.normalizePath = function(path) { +Zotero.CookieSandbox.normalizePath = function (path) { return '/' + path.trim().replace(/^\/+|[?#].*/g, ''); } @@ -84,7 +84,7 @@ Zotero.CookieSandbox.normalizePath = function(path) { * Generates a semicolon-separated string of cookie values from a list of cookies * @param {Object} cookies Object containing key: value cookie pairs */ -Zotero.CookieSandbox.generateCookieString = function(cookies) { +Zotero.CookieSandbox.generateCookieString = function (cookies) { var str = ''; for(var key in cookies) { str += '; ' + key + '=' + cookies[key]; @@ -106,7 +106,7 @@ Zotero.CookieSandbox.prototype = { * @param {nsIURI} [uri] URI of the header origin. Used to verify same origin. If omitted validation is not performed */ - "addCookiesFromHeader":function(cookieString, uri) { + "addCookiesFromHeader":function (cookieString, uri) { var cookies = cookieString.split("\n"); if(uri) { var validDomain = '.' + Zotero.CookieSandbox.normalizeHost(uri.host); @@ -164,7 +164,7 @@ Zotero.CookieSandbox.prototype = { * Attach CookieSandbox to a specific browser * @param {Browser} browser */ - "attachToBrowser":function(browser) { + "attachToBrowser":function (browser) { Zotero.CookieSandbox.Observer.trackedBrowsers.set(browser, this); }, @@ -172,7 +172,7 @@ Zotero.CookieSandbox.prototype = { * Attach CookieSandbox to a specific XMLHttpRequest * @param {nsIInterfaceRequestor} ir */ - "attachToInterfaceRequestor": function(ir) { + "attachToInterfaceRequestor": function (ir) { if (typeof ir.QueryInterface === 'function') { ir = ir.QueryInterface(Components.interfaces.nsIInterfaceRequestor); } @@ -188,7 +188,7 @@ Zotero.CookieSandbox.prototype = { * @param {Boolean} [secure] Whether the cookie has the secure attribute set * @param {Boolean} [hostOnly] Whether the cookie is a host-only cookie */ - "setCookie": function(cookiePair, host, path, secure, hostOnly) { + "setCookie": function (cookiePair, host, path, secure, hostOnly) { var splitAt = cookiePair.indexOf('='); if(splitAt === -1) { Zotero.debug("CookieSandbox: Not setting invalid cookie."); @@ -230,7 +230,7 @@ Zotero.CookieSandbox.prototype = { * Returns a list of cookies that should be sent to the given URI * @param {nsIURI} uri */ - "getCookiesForURI": function(uri) { + "getCookiesForURI": function (uri) { var hostParts = Zotero.CookieSandbox.normalizeHost(uri.host).split('.'), pathParts = Zotero.CookieSandbox.normalizePath(uri.filePath || uri.pathQueryRef).split('/'), cookies = {}, found = false, secure = uri.scheme.toUpperCase() == 'HTTPS'; @@ -250,7 +250,7 @@ Zotero.CookieSandbox.prototype = { return found ? cookies : null; }, - "_getCookiesForPath": function(cookies, cookiePaths, pathParts, secure, isHost) { + "_getCookiesForPath": function (cookies, cookiePaths, pathParts, secure, isHost) { var found = false; var path = ''; for(var i=0, n=pathParts.length; i