Bug 1413488 - [Form Autofill] Rename the "data" property of "AutofillRecords" to "_data". r=seanlee

MozReview-Commit-ID: CmvqUW9PrrW

--HG--
extra : rebase_source : fe0e5d5570335d0ae0078cfb604a29d70d0a29f1
This commit is contained in:
Luke Chang 2017-11-16 13:25:43 +08:00
Родитель 9214b56b5a
Коммит ecdb3157e8
4 изменённых файлов: 33 добавлений и 33 удалений

Просмотреть файл

@ -265,7 +265,7 @@ class AutofillRecords {
this._schemaVersion = schemaVersion;
let hasChanges = (result, record) => this._migrateRecord(record) || result;
if (this.data.reduce(hasChanges, false)) {
if (this._data.reduce(hasChanges, false)) {
this._store.saveSoon();
}
}
@ -286,7 +286,7 @@ class AutofillRecords {
* @returns {array}
* The data object.
*/
get data() {
get _data() {
return this._store.data[this._collectionName];
}
@ -322,9 +322,9 @@ class AutofillRecords {
includeDeleted: true,
});
if (index > -1) {
let existing = this.data[index];
let existing = this._data[index];
if (existing.deleted) {
this.data.splice(index, 1);
this._data.splice(index, 1);
} else {
throw new Error(`Record ${recordToSave.guid} already exists`);
}
@ -372,7 +372,7 @@ class AutofillRecords {
sync.changeCounter = 0;
}
this.data.push(recordToSave);
this._data.push(recordToSave);
this._store.saveSoon();
@ -408,7 +408,7 @@ class AutofillRecords {
}
// Clone the record before modifying it to avoid exposing incomplete changes.
let recordFound = this._clone(this.data[recordFoundIndex]);
let recordFound = this._clone(this._data[recordFoundIndex]);
this._stripComputedFields(recordFound);
let recordToUpdate = this._clone(record);
@ -445,7 +445,7 @@ class AutofillRecords {
}
this._computeFields(recordFound);
this.data[recordFoundIndex] = recordFound;
this._data[recordFoundIndex] = recordFound;
this._store.saveSoon();
@ -496,7 +496,7 @@ class AutofillRecords {
this.log.warn("attempting to remove non-existing entry", guid);
return;
}
let existing = this.data[index];
let existing = this._data[index];
if (existing.deleted) {
return; // already a tombstone - don't touch it.
}
@ -504,7 +504,7 @@ class AutofillRecords {
if (existingSync) {
// existing sync metadata means it has been synced. This means we must
// leave a tombstone behind.
this.data[index] = {
this._data[index] = {
guid,
timeLastModified: Date.now(),
deleted: true,
@ -514,7 +514,7 @@ class AutofillRecords {
} else {
// If there's no sync meta-data, this record has never been synced, so
// we can delete it.
this.data.splice(index, 1);
this._data.splice(index, 1);
}
}
@ -564,7 +564,7 @@ class AutofillRecords {
getAll({rawData = false, includeDeleted = false} = {}) {
this.log.debug("getAll", rawData, includeDeleted);
let records = this.data.filter(r => !r.deleted || includeDeleted);
let records = this._data.filter(r => !r.deleted || includeDeleted);
// Records are cloned to avoid accidental modifications from outside.
let clonedRecords = records.map(r => this._cloneAndCleanUp(r));
clonedRecords.forEach(record => {
@ -712,12 +712,12 @@ class AutofillRecords {
* it's uploaded.
*/
_replaceRecordAt(index, remoteRecord, {keepSyncMetadata = false} = {}) {
let localRecord = this.data[index];
let localRecord = this._data[index];
let newRecord = this._clone(remoteRecord);
this._stripComputedFields(newRecord);
this.data[index] = newRecord;
this._data[index] = newRecord;
if (keepSyncMetadata) {
// It's safe to move the Sync metadata from the old record to the new
@ -772,7 +772,7 @@ class AutofillRecords {
this._getSyncMetaData(forkedLocalRecord, true);
this._computeFields(forkedLocalRecord);
this.data.push(forkedLocalRecord);
this._data.push(forkedLocalRecord);
return forkedLocalRecord;
}
@ -803,7 +803,7 @@ class AutofillRecords {
throw new Error(`Record ${remoteRecord.guid} not found`);
}
let localRecord = this.data[localIndex];
let localRecord = this._data[localIndex];
let sync = this._getSyncMetaData(localRecord, true);
let forkedGUID = null;
@ -857,11 +857,11 @@ class AutofillRecords {
let sync = this._getSyncMetaData(tombstone, true);
sync.changeCounter = 0;
this.data.push(tombstone);
this._data.push(tombstone);
return;
}
let existing = this.data[index];
let existing = this._data[index];
let sync = this._getSyncMetaData(existing, true);
if (sync.changeCounter > 0) {
// Deleting a record with unsynced local changes. To avoid potential
@ -878,7 +878,7 @@ class AutofillRecords {
// Removing a record that's not changed locally, and that's not already
// deleted. Replace the record with a synced tombstone.
this.data[index] = {
this._data[index] = {
guid,
timeLastModified: Date.now(),
deleted: true,
@ -900,7 +900,7 @@ class AutofillRecords {
pullSyncChanges() {
let changes = {};
let profiles = this.data;
let profiles = this._data;
for (let profile of profiles) {
let sync = this._getSyncMetaData(profile, true);
if (sync.changeCounter < 1) {
@ -957,7 +957,7 @@ class AutofillRecords {
* metadata for all items is removed.
*/
resetSync() {
for (let record of this.data) {
for (let record of this._data) {
delete record._sync;
}
// XXX - we should probably also delete all tombstones?
@ -987,7 +987,7 @@ class AutofillRecords {
}
let index = this._findIndexByGUID(oldID);
let profile = this.data[index];
let profile = this._data[index];
if (!profile) {
throw new Error("changeGUID: no source record");
}
@ -1037,7 +1037,7 @@ class AutofillRecords {
// handled them separately when applying the record.
throw new Error("Tombstones can't have duplicates");
}
let localRecords = this.data;
let localRecords = this._data;
for (let localRecord of localRecords) {
if (localRecord.deleted) {
continue;
@ -1110,11 +1110,11 @@ class AutofillRecords {
_findByGUID(guid, {includeDeleted = false} = {}) {
let found = this._findIndexByGUID(guid, {includeDeleted});
return found < 0 ? undefined : this.data[found];
return found < 0 ? undefined : this._data[found];
}
_findIndexByGUID(guid, {includeDeleted = false} = {}) {
return this.data.findIndex(record => {
return this._data.findIndex(record => {
return record.guid == guid && (!record.deleted || includeDeleted);
});
}
@ -1178,7 +1178,7 @@ class AutofillRecords {
*/
mergeToStorage(targetRecord, strict = false) {
let mergedGUIDs = [];
for (let record of this.data) {
for (let record of this._data) {
if (!record.deleted && this.mergeIfPossible(record.guid, targetRecord, strict)) {
mergedGUIDs.push(record.guid);
}
@ -1665,7 +1665,7 @@ class CreditCards extends AutofillRecords {
getDuplicateGuid(targetCreditCard) {
let clonedTargetCreditCard = this._clone(targetCreditCard);
this._normalizeRecord(clonedTargetCreditCard);
for (let creditCard of this.data) {
for (let creditCard of this._data) {
let isDuplicate = this.VALID_FIELDS.every(field => {
if (!clonedTargetCreditCard[field]) {
return !creditCard[field];

Просмотреть файл

@ -26,4 +26,4 @@ MOCHITEST_MANIFESTS += ['test/mochitest/mochitest.ini']
JAR_MANIFESTS += ['jar.mn']
with Files('**'):
BUG_COMPONENT = ('Toolkit', 'Form Manager')
BUG_COMPONENT = ('Toolkit', 'Form Autofill')

Просмотреть файл

@ -333,7 +333,7 @@ add_task(async function test_add() {
// Empty string should be deleted before saving.
profileStorage.addresses.add(TEST_ADDRESS_WITH_EMPTY_FIELD);
let address = profileStorage.addresses.data[2];
let address = profileStorage.addresses._data[2];
do_check_eq(address.name, TEST_ADDRESS_WITH_EMPTY_FIELD.name);
do_check_eq(address["street-address"], undefined);
@ -393,8 +393,8 @@ add_task(async function test_update() {
do_check_eq(getSyncChangeCounter(profileStorage.addresses, guid), 2);
// Empty string should be deleted while updating.
profileStorage.addresses.update(profileStorage.addresses.data[0].guid, TEST_ADDRESS_WITH_EMPTY_FIELD);
address = profileStorage.addresses.data[0];
profileStorage.addresses.update(profileStorage.addresses._data[0].guid, TEST_ADDRESS_WITH_EMPTY_FIELD);
address = profileStorage.addresses._data[0];
do_check_eq(address.name, TEST_ADDRESS_WITH_EMPTY_FIELD.name);
do_check_eq(address["street-address"], undefined);

Просмотреть файл

@ -256,7 +256,7 @@ add_task(async function test_add() {
// Empty string should be deleted before saving.
profileStorage.creditCards.add(TEST_CREDIT_CARD_WITH_EMPTY_FIELD);
let creditCard = profileStorage.creditCards.data[2];
let creditCard = profileStorage.creditCards._data[2];
do_check_eq(creditCard["cc-exp-month"], TEST_CREDIT_CARD_WITH_EMPTY_FIELD["cc-exp-month"]);
do_check_eq(creditCard["cc-name"], undefined);
@ -299,8 +299,8 @@ add_task(async function test_update() {
do_check_credit_card_matches(creditCard, TEST_CREDIT_CARD_3);
// Empty string should be deleted while updating.
profileStorage.creditCards.update(profileStorage.creditCards.data[0].guid, TEST_CREDIT_CARD_WITH_EMPTY_FIELD);
creditCard = profileStorage.creditCards.data[0];
profileStorage.creditCards.update(profileStorage.creditCards._data[0].guid, TEST_CREDIT_CARD_WITH_EMPTY_FIELD);
creditCard = profileStorage.creditCards._data[0];
do_check_eq(creditCard["cc-exp-month"], TEST_CREDIT_CARD_WITH_EMPTY_FIELD["cc-exp-month"]);
do_check_eq(creditCard["cc-name"], undefined);