www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 7d404e8d4ad636987acfe33d0b8620263004d6d0
parent 9fb42b6788f53885998d50a94fe5efff76094f71
Author: Dan Stillman <dstillman@zotero.org>
Date:   Tue, 12 Jan 2016 01:57:39 -0500

Closes #896, Legacy array/generator comprehension is removed in Firefox 46

Possible there are some bugs here (and it also may fix a couple existing bugs).

Diffstat:
Mchrome/content/zotero/bindings/itembox.xml | 2+-
Mchrome/content/zotero/fileInterface.js | 7+++++--
Mchrome/content/zotero/integration/editBibliographyDialog.js | 2+-
Mchrome/content/zotero/integration/quickFormat.js | 10+++++++---
Mchrome/content/zotero/locateManager.xul | 2+-
Mchrome/content/zotero/rtfScan.js | 2+-
Mchrome/content/zotero/tools/cslpreview.js | 10+++++++---
Mchrome/content/zotero/xpcom/cite.js | 4++--
Mchrome/content/zotero/xpcom/data/tag.js | 2+-
Mchrome/content/zotero/xpcom/fulltext.js | 2+-
Mchrome/content/zotero/xpcom/integration.js | 21++++++++++++---------
Mchrome/content/zotero/xpcom/itemTreeView.js | 2+-
Mchrome/content/zotero/xpcom/locateManager.js | 23+++++++++++++++--------
Mchrome/content/zotero/xpcom/proxy.js | 4++--
Mchrome/content/zotero/xpcom/quickCopy.js | 7+++++--
Mchrome/content/zotero/xpcom/server_connector.js | 2+-
Mchrome/content/zotero/xpcom/storage.js | 5+++--
Mchrome/content/zotero/xpcom/storage/request.js | 2+-
Mchrome/content/zotero/xpcom/style.js | 8++++----
Mchrome/content/zotero/xpcom/sync.js | 4++--
Mchrome/content/zotero/xpcom/translation/translator.js | 2+-
Mchrome/content/zotero/xpcom/utilities_internal.js | 15++++++++++-----
Mchrome/content/zotero/xpcom/zotero.js | 3++-
23 files changed, 86 insertions(+), 55 deletions(-)

diff --git a/chrome/content/zotero/bindings/itembox.xml b/chrome/content/zotero/bindings/itembox.xml @@ -1729,7 +1729,7 @@ this._addCreatorRow = false; //Filter out bad names - var nameArray = [tempName for each(tempName in rawNameArray) if(tempName)]; + var nameArray = rawNameArray.filter(name => name); //If not adding names at the end of the creator list, make new creator //entries and then shift down existing creators. diff --git a/chrome/content/zotero/fileInterface.js b/chrome/content/zotero/fileInterface.js @@ -328,7 +328,7 @@ var Zotero_File_Interface = new function() { translation.setHandler("done", function(obj, worked) { // add items to import collection if(importCollection) { - importCollection.addItems([item.id for each(item in obj.newItems)]); + importCollection.addItems(obj.newItems.map(item => item.id)); } Zotero.DB.commitTransaction(); @@ -467,7 +467,10 @@ var Zotero_File_Interface = new function() { getService(Components.interfaces.nsIClipboard); var style = Zotero.Styles.get(style).getCiteProc(locale); - var citation = {"citationItems":[{id:item.id} for each(item in items)], properties:{}}; + var citation = { + citationItems: items.map(item => ({ id: item.id })), + properties: {} + }; // add HTML var bibliography = style.previewCitationCluster(citation, [], [], "html"); diff --git a/chrome/content/zotero/integration/editBibliographyDialog.js b/chrome/content/zotero/integration/editBibliographyDialog.js @@ -99,7 +99,7 @@ var Zotero_Bibliography_Dialog = new function () { _addButton.disabled = true; _removeButton.disabled = false; _updateRevertButtonStatus(); - [_itemList.toggleItemSelection(item) for each(item in itemsToSelect)]; + itemsToSelect.forEach(item => _itemList.toggleItemSelection(item)); _itemList.ensureIndexIsVisible(itemsToSelect[0]); } _suppressAllSelectEvents = false; diff --git a/chrome/content/zotero/integration/quickFormat.js b/chrome/content/zotero/integration/quickFormat.js @@ -303,9 +303,13 @@ var Zotero_QuickFormat = new function () { citedItemsMatchingSearch = []; for(var i=0, iCount=citedItems.length; i<iCount; i++) { // Generate a string to search for each item - var item = citedItems[i], - itemStr = [creator.ref.firstName+" "+creator.ref.lastName for (creator of item.getCreators())]; - itemStr = itemStr.concat([item.getField("title"), item.getField("date", true, true).substr(0, 4)]).join(" "); + let item = citedItems[i]; + let itemStr = item.getCreators() + .map(creator => { + creator.ref.firstName + " " + creator.ref.lastName + }) + .concat([item.getField("title"), item.getField("date", true, true).substr(0, 4)]) + .join(" "); // See if words match for(var j=0, jCount=splits.length; j<jCount; j++) { diff --git a/chrome/content/zotero/locateManager.xul b/chrome/content/zotero/locateManager.xul @@ -231,7 +231,7 @@ To add a new preference: hidden = false; } - [engine.hidden = hidden for each(engine in Zotero.LocateManager.getEngines())]; + Zotero.LocateManager.getEngines().forEach(engine => engine.hidden = hidden); refreshLocateEnginesList(); } diff --git a/chrome/content/zotero/rtfScan.js b/chrome/content/zotero/rtfScan.js @@ -528,7 +528,7 @@ var Zotero_RTFScan = new function() { } Zotero.debug(cslCitations); - itemIDs = [itemID for(itemID in itemIDs)]; + itemIDs = Object.keys(itemIDs); Zotero.debug(itemIDs); // prepare the list of rendered citations diff --git a/chrome/content/zotero/tools/cslpreview.js b/chrome/content/zotero/tools/cslpreview.js @@ -95,13 +95,17 @@ var Zotero_CSL_Preview = new function() { // Generate multiple citations var citations = styleEngine.previewCitationCluster( - {"citationItems":[{"id":item.id} for each(item in items)], "properties":{}}, - [], [], "html"); + { + citationItems: items.map(item => ({ id: item.id })), + properties: {} + }, + [], [], "html" + ); // Generate bibliography var bibliography = ''; if(style.hasBibliography) { - styleEngine.updateItems([item.id for each(item in items)]); + styleEngine.updateItems(items.map(item => item.id)); bibliography = Zotero.Cite.makeFormattedBibliography(styleEngine, "html"); } diff --git a/chrome/content/zotero/xpcom/cite.js b/chrome/content/zotero/xpcom/cite.js @@ -73,7 +73,7 @@ Zotero.Cite = { */ "makeFormattedBibliographyOrCitationList":function(cslEngine, items, format, asCitationList) { cslEngine.setOutputFormat(format); - cslEngine.updateItems([item.id for each(item in items)]); + cslEngine.updateItems(items.map(item => item.id)); if(!asCitationList) { var bibliography = Zotero.Cite.makeFormattedBibliography(cslEngine, format); @@ -297,7 +297,7 @@ Zotero.Cite = { var slashIndex; if(id instanceof Array) { - return [Zotero.Cite.getItem(anId) for each(anId in id)]; + return id.map(anId => Zotero.Cite.getItem(anId)); } else if(typeof id === "string" && (slashIndex = id.indexOf("/")) !== -1) { var sessionID = id.substr(0, slashIndex), session = Zotero.Integration.sessions[sessionID], diff --git a/chrome/content/zotero/xpcom/data/tag.js b/chrome/content/zotero/xpcom/data/tag.js @@ -224,7 +224,7 @@ Zotero.Tag.prototype.getLinkedItems = function (asIDs) { } // Return Zotero.Item objects - return [item for each(item in this._linkedItems)]; + return Object.keys(this._linkedItems).map(id => this._linkedItems[id]); } diff --git a/chrome/content/zotero/xpcom/fulltext.js b/chrome/content/zotero/xpcom/fulltext.js @@ -446,7 +446,7 @@ Zotero.Fulltext = new function(){ Zotero.DB.query("DELETE FROM indexing.fulltextWords"); while (words.length > 0) { chunk = words.splice(0, 100); - Zotero.DB.query('INSERT INTO indexing.fulltextWords (word) ' + ['SELECT ?' for (word of chunk)].join(' UNION '), chunk); + Zotero.DB.query('INSERT INTO indexing.fulltextWords (word) ' + chunk.map(x => 'SELECT ?').join(' UNION '), chunk); } Zotero.DB.query('INSERT OR IGNORE INTO fulltextWords (word) SELECT word FROM indexing.fulltextWords'); Zotero.DB.query('DELETE FROM fulltextItemWords WHERE itemID = ?', [itemID]); diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js @@ -1554,7 +1554,7 @@ Zotero.Integration.Fields.prototype.updateDocument = function(forceCitations, fo Zotero.Integration.Fields.prototype._updateDocument = function(forceCitations, forceBibliography, ignoreCitationChanges) { if(this.progressCallback) { - var nFieldUpdates = [i for(i in this._session.updateIndices)].length; + var nFieldUpdates = Object.keys(this._session.updateIndices).length; if(this._session.bibliographyHasChanged || forceBibliography) { nFieldUpdates += this._bibliographyFields.length*5; } @@ -1989,11 +1989,13 @@ Zotero.Integration.CitationEditInterface.prototype = { */ "_getItems":function() { var citationsByItemID = this._session.citationsByItemID; - var ids = [itemID for(itemID in citationsByItemID) - if(citationsByItemID[itemID] && citationsByItemID[itemID].length + var ids = Object.keys(citationsByItemID).filter(itemID => { + return citationsByItemID[itemID] + && citationsByItemID[itemID].length // Exclude the present item && (citationsByItemID[itemID].length > 1 - || citationsByItemID[itemID][0].properties.zoteroIndex !== this._fieldIndex))]; + || citationsByItemID[itemID][0].properties.zoteroIndex !== this._fieldIndex); + }); // Sort all previously cited items at top, and all items cited later at bottom var fieldIndex = this._fieldIndex; @@ -2565,7 +2567,7 @@ Zotero.Integration.Session.prototype.getBibliography = function() { Zotero.Integration.Session.prototype.updateUncitedItems = function() { // There appears to be a bug somewhere here. if(Zotero.Debug.enabled) Zotero.debug("Integration: style.updateUncitedItems("+this.uncitedItems.toSource()+")"); - this.style.updateUncitedItems([parseInt(i) for(i in this.uncitedItems)]); + this.style.updateUncitedItems(Object.keys(this.uncitedItems).map(i => parseInt(i))); } /** @@ -2662,9 +2664,9 @@ Zotero.Integration.Session.prototype._updateCitations = function() { if(Zotero.Debug.enabled) { Zotero.debug("Integration: Indices of new citations"); - Zotero.debug([key for(key in this.newIndices)]); + Zotero.debug(Object.keys(this.newIndices)); Zotero.debug("Integration: Indices of updated citations"); - Zotero.debug([key for(key in this.updateIndices)]); + Zotero.debug(Object.keys(this.updateIndices)); } @@ -2818,8 +2820,9 @@ Zotero.Integration.Session.prototype.getBibliographyData = function() { } // look for custom bibliography entries - bibliographyData.custom = [[this.uriMap.getURIsForItemID(id), this.customBibliographyText[id]] - for(id in this.customBibliographyText)]; + bibliographyData.custom = Object.keys(this.customBibliographyText) + .map(id => [this.uriMap.getURIsForItemID(id), this.customBibliographyText[id]]); + if(bibliographyData.uncited || bibliographyData.custom) { return JSON.stringify(bibliographyData); diff --git a/chrome/content/zotero/xpcom/itemTreeView.js b/chrome/content/zotero/xpcom/itemTreeView.js @@ -2428,7 +2428,7 @@ Zotero.ItemTreeView.prototype.onColumnPickerShowing = function (event) { moreMenuPopup.setAttribute('anonid', id + '-popup'); let treecols = menupopup.parentNode.parentNode; - let subs = [x.getAttribute('label') for (x of treecols.getElementsByAttribute('submenu', 'true'))]; + let subs = treecols.getElementsByAttribute('submenu', 'true').map(x => x.getAttribute('label')); var moreItems = []; diff --git a/chrome/content/zotero/xpcom/locateManager.js b/chrome/content/zotero/xpcom/locateManager.js @@ -42,8 +42,8 @@ Zotero.LocateManager = new function() { _jsonFile = _getLocateFile(); if(_jsonFile.exists()) { - _locateEngines = [new LocateEngine(engine) - for each(engine in JSON.parse(Zotero.File.getContents(_jsonFile)))]; + _locateEngines = JSON.parse(Zotero.File.getContents(_jsonFile)) + .map(engine => new LocateEngine(engine)); } else { this.restoreDefaultEngines(); } @@ -67,8 +67,10 @@ Zotero.LocateManager = new function() { /** * Gets all default search engines (not currently used) */ - this.getDefaultEngines = function() [new LocateEngine(engine) - for each(engine in JSON.parse(Zotero.File.getContentsFromURL(_getDefaultFile())))]; + this.getDefaultEngines = function () { + return JSON.parse(Zotero.File.getContentsFromURL(_getDefaultFile())) + .map(engine => new LocateEngine(engine)); + } /** * Returns an array of all search engines @@ -78,7 +80,9 @@ Zotero.LocateManager = new function() { /** * Returns an array of all search engines visible that should be visible in the dropdown */ - this.getVisibleEngines = function() [engine for each(engine in _locateEngines) if(!engine.hidden)]; + this.getVisibleEngines = function () { + return _locateEngines.filter(engine => !engine.hidden); + } /** * Returns an engine with a specific name @@ -285,12 +289,12 @@ Zotero.LocateManager = new function() { return false; } - return [encodeURIComponent(val) for each(val in itemOpenURL["rft."+param])]; + return itemOpenURL["rft."+param].map(val => encodeURIComponent(val)); } else if(ns === "info:ofi/fmt:kev:mtx:ctx") { if(!OPENURL_CONTEXT_MAPPINGS[param] || !itemOpenURL[OPENURL_CONTEXT_MAPPINGS[param]]) { return false; } - return [encodeURIComponent(val) for each(val in itemOpenURL[OPENURL_CONTEXT_MAPPINGS[param]])]; + return itemOpenURL[OPENURL_CONTEXT_MAPPINGS[param]].map(val => encodeURIComponent(val)); } else if(ns === "http://www.zotero.org/namespaces/openSearch#") { if(param === "openURL") { var ctx = Zotero.OpenURL.createContextObject(item, "1.0"); @@ -457,7 +461,10 @@ Zotero.LocateManager = new function() { } else { var result = _lookupParam(item, itemAsOpenURL, me, m[1], m[2]); if(result) { - paramsToAdd = paramsToAdd.concat([encodeURIComponent(param)+"="+encodeURIComponent(val) for(val in result)]); + paramsToAdd = paramsToAdd.concat( + result.map(val => + encodeURIComponent(param) + "=" + encodeURIComponent(val)) + ); } else if(m[3]) { // if no param and it wasn't optional, return return null; } diff --git a/chrome/content/zotero/xpcom/proxy.js b/chrome/content/zotero/xpcom/proxy.js @@ -50,8 +50,8 @@ Zotero.Proxies = new function() { var me = this; Zotero.MIMETypeHandler.addObserver(function(ch) { me.observe(ch) }); - var rows = Zotero.DB.query("SELECT * FROM proxies"); - Zotero.Proxies.proxies = [new Zotero.Proxy(row) for each(row in rows)]; + var rows = Zotero.DB.query("SELECT * FROM proxies") || []; + Zotero.Proxies.proxies = rows.map(row => new Zotero.Proxy(row)); for each(var proxy in Zotero.Proxies.proxies) { for each(var host in proxy.hosts) { diff --git a/chrome/content/zotero/xpcom/quickCopy.js b/chrome/content/zotero/xpcom/quickCopy.js @@ -367,8 +367,11 @@ Zotero.QuickCopy = new function() { // Copy citations if shift key pressed if (modified) { var csl = Zotero.Styles.get(format.id).getCiteProc(locale); - csl.updateItems([item.id for each(item in items)]); - var citation = {citationItems:[{id:item.id} for each(item in items)], properties:{}}; + csl.updateItems(items.map(item => item.id)); + var citation = { + citationItems: items.map(item => item.id), + properties: {} + }; var html = csl.previewCitationCluster(citation, [], [], "html"); var text = csl.previewCitationCluster(citation, [], [], "text"); } else { diff --git a/chrome/content/zotero/xpcom/server_connector.js b/chrome/content/zotero/xpcom/server_connector.js @@ -509,7 +509,7 @@ Zotero.Server.Connector.Progress.prototype = { */ "init":function(data, sendResponseCallback) { sendResponseCallback(200, "application/json", - JSON.stringify([Zotero.Server.Connector.AttachmentProgressManager.getProgressForID(id) for each(id in data)])); + JSON.stringify(data.map(id => Zotero.Server.Connector.AttachmentProgressManager.getProgressForID(id)))); } }; diff --git a/chrome/content/zotero/xpcom/storage.js b/chrome/content/zotero/xpcom/storage.js @@ -1840,8 +1840,9 @@ Zotero.Sync.Storage = new function () { var itemIDs = Zotero.DB.columnQuery(sql, params) || []; // Get files by open time - _uploadCheckFiles.filter(function (x) x.timestamp >= minTime); - itemIDs = itemIDs.concat([x.itemID for each(x in _uploadCheckFiles)]) + itemIDs = itemIDs.concat( + _uploadCheckFiles.filter(item => item.timestamp >= minTime).map(item => item.id) + ); return Zotero.Utilities.arrayUnique(itemIDs); } diff --git a/chrome/content/zotero/xpcom/storage/request.js b/chrome/content/zotero/xpcom/storage/request.js @@ -199,7 +199,7 @@ Zotero.Sync.Storage.Request.prototype.start = function () { // // The main sync logic is triggered here. - Q.all([f(this) for each(f in this._onStart)]) + Q.all(this._onStart.map(f => f(this))) .then(function (results) { return { localChanges: results.some(function (val) val && val.localChanges == true), diff --git a/chrome/content/zotero/xpcom/style.js b/chrome/content/zotero/xpcom/style.js @@ -581,10 +581,10 @@ Zotero.Style = function(arg) { //In CSL 0.8.1, the "term" attribute on cs:category stored both //citation formats and fields. - this.categories = [category.getAttribute("term") - for each(category in Zotero.Utilities.xpath(doc, - '/csl:style/csl:info[1]/csl:category', Zotero.Styles.ns)) - if(category.hasAttribute("term"))]; + this.categories = Zotero.Utilities.xpath( + doc, '/csl:style/csl:info[1]/csl:category', Zotero.Styles.ns) + .filter(category => category.hasAttribute("term")) + .map(category => category.getAttribute("term")); } else { //CSL 1.0 introduced a dedicated "citation-format" attribute on cs:category this.categories = Zotero.Utilities.xpathText(doc, diff --git a/chrome/content/zotero/xpcom/sync.js b/chrome/content/zotero/xpcom/sync.js @@ -753,7 +753,7 @@ Zotero.Sync.Runner = new function () { errors = []; } - errors = [this.parseSyncError(e) for each(e in errors)]; + errors = errors.map(e => this.parseSyncError(e)); _errorsByLibrary = {}; var primaryError = this.getPrimaryError(errors); @@ -787,7 +787,7 @@ Zotero.Sync.Runner = new function () { this.getPrimaryError = function (errors) { - errors = [this.parseSyncError(e) for each(e in errors)]; + errors = errors.map(e => this.parseSyncError(e)); // Set highest priority error as the primary (sync error icon) var errorModes = { diff --git a/chrome/content/zotero/xpcom/translation/translator.js b/chrome/content/zotero/xpcom/translation/translator.js @@ -188,7 +188,7 @@ Zotero.Translators = new function() { */ this.getAll = function() { if(!_initialized) this.init(); - return [translator for each(translator in _translators)]; + return Object.keys(_translators).map(i => _translators[i]); } /** diff --git a/chrome/content/zotero/xpcom/utilities_internal.js b/chrome/content/zotero/xpcom/utilities_internal.js @@ -96,7 +96,11 @@ Zotero.Utilities.Internal = { } // convert the binary hash data to a hex string. - return [toHexString(hash.charCodeAt(i)) for (i in hash)].join(""); + var hexStr; + for (let i = 0; i < hash.length; i++) { + hexStr += toHexString(hash.charCodeAt(i)); + } + return hexStr; }, @@ -138,10 +142,11 @@ Zotero.Utilities.Internal = { } // Hex string else { - deferred.resolve( - [toHexString(hash.charCodeAt(i)) - for (i in hash)].join("") - ); + let hexStr; + for (let i = 0; i < hash.length; i++) { + hexStr += toHexString(hash.charCodeAt(i)); + } + deferred.resolve(hexStr); } } }, diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js @@ -434,7 +434,8 @@ Components.utils.import("resource://gre/modules/Services.jsm"); try { var messages = {}; cs.getMessageArray(messages, {}); - _startupErrors = [msg for each(msg in messages.value) if(_shouldKeepError(msg))]; + _startupErrors = Object.keys(messages.value).map(i => messages[i]) + .filter(msg => _shouldKeepError(msg)); } catch(e) { Zotero.logError(e); }