Skip to content

Commit

Permalink
Closes #896, Legacy array/generator comprehension is removed in Firef…
Browse files Browse the repository at this point in the history
…ox 46

Possible there are some bugs here (and it also may fix a couple existing bugs).
  • Loading branch information
dstillman committed Jan 12, 2016
1 parent 9fb42b6 commit 7d404e8
Show file tree
Hide file tree
Showing 23 changed files with 86 additions and 55 deletions.
2 changes: 1 addition & 1 deletion chrome/content/zotero/bindings/itembox.xml
Expand Up @@ -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.
Expand Down
7 changes: 5 additions & 2 deletions chrome/content/zotero/fileInterface.js
Expand Up @@ -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();
Expand Down Expand Up @@ -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");
Expand Down
Expand Up @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions chrome/content/zotero/integration/quickFormat.js
Expand Up @@ -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++) {
Expand Down
2 changes: 1 addition & 1 deletion chrome/content/zotero/locateManager.xul
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion chrome/content/zotero/rtfScan.js
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions chrome/content/zotero/tools/cslpreview.js
Expand Up @@ -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");
}

Expand Down
4 changes: 2 additions & 2 deletions chrome/content/zotero/xpcom/cite.js
Expand Up @@ -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);
Expand Down Expand Up @@ -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],
Expand Down
2 changes: 1 addition & 1 deletion chrome/content/zotero/xpcom/data/tag.js
Expand Up @@ -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]);
}


Expand Down
2 changes: 1 addition & 1 deletion chrome/content/zotero/xpcom/fulltext.js
Expand Up @@ -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]);
Expand Down
21 changes: 12 additions & 9 deletions chrome/content/zotero/xpcom/integration.js
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)));
}

/**
Expand Down Expand Up @@ -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));
}


Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion chrome/content/zotero/xpcom/itemTreeView.js
Expand Up @@ -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 = [];

Expand Down
23 changes: 15 additions & 8 deletions chrome/content/zotero/xpcom/locateManager.js
Expand Up @@ -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();
}
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions chrome/content/zotero/xpcom/proxy.js
Expand Up @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions chrome/content/zotero/xpcom/quickCopy.js
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion chrome/content/zotero/xpcom/server_connector.js
Expand Up @@ -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))));
}
};

Expand Down
5 changes: 3 additions & 2 deletions chrome/content/zotero/xpcom/storage.js
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion chrome/content/zotero/xpcom/storage/request.js
Expand Up @@ -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),
Expand Down
8 changes: 4 additions & 4 deletions chrome/content/zotero/xpcom/style.js
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions chrome/content/zotero/xpcom/sync.js
Expand Up @@ -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);
Expand Down Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion chrome/content/zotero/xpcom/translation/translator.js
Expand Up @@ -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]);
}

/**
Expand Down
15 changes: 10 additions & 5 deletions chrome/content/zotero/xpcom/utilities_internal.js
Expand Up @@ -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;
},


Expand Down Expand Up @@ -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);
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion chrome/content/zotero/xpcom/zotero.js
Expand Up @@ -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);
}
Expand Down

4 comments on commit 7d404e8

@adam3smith
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dstillman -- I believe this caused the error reported here https://forums.zotero.org/discussion/57390/already-cited-articles-not-showing-up-anymore-in-word/#Item_7, i.e. quick format search of cited items only searches on title, not on creator anymore

@dstillman
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks — fixed in 11e3603, out now in 4.0.29.6.

@Dennisdd
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dstillman : Thanks, Dan. When will this be fixed for the standalone?

@dstillman
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll hopefully have a new Standalone version out with this fix in the next few days.

Please sign in to comment.