Addresses #597, Don't iterate Array with for...in

This commit is contained in:
Simon Kornblith 2011-09-05 06:29:35 +00:00
parent 31f3733cbf
commit 3c552ac628

View file

@ -23,7 +23,7 @@
***** END LICENSE BLOCK ***** ***** END LICENSE BLOCK *****
*/ */
const Zotero_TranslatorTester_IGNORE_FIELDS = ["complete", "accessDate", "checkFields"]; var Zotero_TranslatorTester_IGNORE_FIELDS = ["complete", "accessDate", "checkFields"];
/** /**
* A tool to run unit tests for a given translator * A tool to run unit tests for a given translator
@ -66,7 +66,7 @@ Zotero_TranslatorTester = function(translator, type, debug) {
Zotero.logError(e); Zotero.logError(e);
} }
for(var i in testObject) { for(var i=0, n=testObject.length; i<n; i++) {
if(testObject[i].type === type) { if(testObject[i].type === type) {
this.tests.push(testObject[i]); this.tests.push(testObject[i]);
this.pending.push(testObject[i]); this.pending.push(testObject[i]);
@ -93,7 +93,7 @@ Zotero_TranslatorTester._sanitizeItem = function(item, forSave) {
} }
// remove fields to be ignored // remove fields to be ignored
for(var j in Zotero_TranslatorTester_IGNORE_FIELDS) { for(var j=0, n=Zotero_TranslatorTester_IGNORE_FIELDS.length; j<n; j++) {
if(forSave) { if(forSave) {
delete item[Zotero_TranslatorTester_IGNORE_FIELDS[j]] delete item[Zotero_TranslatorTester_IGNORE_FIELDS[j]]
} else { } else {
@ -285,7 +285,7 @@ Zotero_TranslatorTester.prototype._checkResult = function(test, translate, retur
return; return;
} }
for(var i in test.items) { for(var i=0, n=test.items.length; i<n; i++) {
var testItem = Zotero_TranslatorTester._sanitizeItem(test.items[i]); var testItem = Zotero_TranslatorTester._sanitizeItem(test.items[i]);
var translatedItem = Zotero_TranslatorTester._sanitizeItem(translate.newItems[i]); var translatedItem = Zotero_TranslatorTester._sanitizeItem(translate.newItems[i]);
@ -348,7 +348,9 @@ Zotero_TranslatorTester.prototype._createTest = function(translate, multipleMode
if(multipleMode) { if(multipleMode) {
var items = "multiple"; var items = "multiple";
} else { } else {
for(var i in translate.newItems) Zotero_TranslatorTester._sanitizeItem(translate.newItems[i], true); for(var i=0, n=translate.newItems; i<n; i++) {
Zotero_TranslatorTester._sanitizeItem(translate.newItems[i], true);
}
var items = translate.newItems; var items = translate.newItems;
} }