From 8037a4bf79b8ae49162c2b6f099d62ec17a7f283 Mon Sep 17 00:00:00 2001 From: Gil Date: Thu, 24 May 2018 11:00:23 -0700 Subject: Replace Objective-C assertions with C++ assertions (#1327) * Migrate FSTFail to HARD_FAIL * FSTCFail -> HARD_FAIL * FSTCAssert -> HARD_ASSERT * FSTAssert -> HARD_ASSERT * Replace FSTAssert with NSAssert in dead Objective-C code * Remove FSTAssert.h --- Firestore/Source/Local/FSTLocalStore.mm | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'Firestore/Source/Local/FSTLocalStore.mm') diff --git a/Firestore/Source/Local/FSTLocalStore.mm b/Firestore/Source/Local/FSTLocalStore.mm index 245dd62..7469c71 100644 --- a/Firestore/Source/Local/FSTLocalStore.mm +++ b/Firestore/Source/Local/FSTLocalStore.mm @@ -36,12 +36,12 @@ #import "Firestore/Source/Model/FSTMutation.h" #import "Firestore/Source/Model/FSTMutationBatch.h" #import "Firestore/Source/Remote/FSTRemoteEvent.h" -#import "Firestore/Source/Util/FSTAssert.h" #include "Firestore/core/src/firebase/firestore/auth/user.h" #include "Firestore/core/src/firebase/firestore/core/target_id_generator.h" #include "Firestore/core/src/firebase/firestore/model/document_key.h" #include "Firestore/core/src/firebase/firestore/model/snapshot_version.h" +#include "Firestore/core/src/firebase/firestore/util/hard_assert.h" #include "Firestore/core/src/firebase/firestore/util/log.h" using firebase::firestore::auth::User; @@ -236,10 +236,10 @@ NS_ASSUME_NONNULL_BEGIN - (FSTMaybeDocumentDictionary *)rejectBatchID:(FSTBatchID)batchID { return self.persistence.run("Reject batch", [&]() -> FSTMaybeDocumentDictionary * { FSTMutationBatch *toReject = [self.mutationQueue lookupMutationBatch:batchID]; - FSTAssert(toReject, @"Attempt to reject nonexistent batch!"); + HARD_ASSERT(toReject, "Attempt to reject nonexistent batch!"); FSTBatchID lastAcked = [self.mutationQueue highestAcknowledgedBatchID]; - FSTAssert(batchID > lastAcked, @"Acknowledged batches can't be rejected."); + HARD_ASSERT(batchID > lastAcked, "Acknowledged batches can't be rejected."); DocumentKeySet affected = [self removeMutationBatch:toReject]; @@ -304,7 +304,7 @@ NS_ASSUME_NONNULL_BEGIN [queryCache addMatchingKeys:update.addedDocuments forTargetID:targetID]; } else { - FSTFail(@"Unknown mapping type: %@", mapping); + HARD_FAIL("Unknown mapping type: %s", mapping); } } }]; @@ -345,10 +345,9 @@ NS_ASSUME_NONNULL_BEGIN const SnapshotVersion &lastRemoteVersion = [self.queryCache lastRemoteSnapshotVersion]; const SnapshotVersion &remoteVersion = remoteEvent.snapshotVersion; if (remoteVersion != SnapshotVersion::None()) { - FSTAssert(remoteVersion >= lastRemoteVersion, - @"Watch stream reverted to previous snapshot?? (%s < %s)", - remoteVersion.timestamp().ToString().c_str(), - lastRemoteVersion.timestamp().ToString().c_str()); + HARD_ASSERT(remoteVersion >= lastRemoteVersion, + "Watch stream reverted to previous snapshot?? (%s < %s)", + remoteVersion.timestamp().ToString(), lastRemoteVersion.timestamp().ToString()); [self.queryCache setLastRemoteSnapshotVersion:remoteVersion]; } @@ -369,7 +368,7 @@ NS_ASSUME_NONNULL_BEGIN FSTReferenceSet *localViewReferences = self.localViewReferences; for (FSTLocalViewChanges *view in viewChanges) { FSTQueryData *queryData = [self.queryCache queryDataForQuery:view.query]; - FSTAssert(queryData, @"Local view changes contain unallocated query."); + HARD_ASSERT(queryData, "Local view changes contain unallocated query."); FSTTargetID targetID = queryData.targetID; for (const DocumentKey &key : view.removedKeys) { [self->_persistence.referenceDelegate removeReference:key target:targetID]; @@ -409,8 +408,8 @@ NS_ASSUME_NONNULL_BEGIN }); // Sanity check to ensure that even when resuming a query it's not currently active. FSTBoxedTargetID *boxedTargetID = @(queryData.targetID); - FSTAssert(!self.targetIDs[boxedTargetID], @"Tried to allocate an already allocated query: %@", - query); + HARD_ASSERT(!self.targetIDs[boxedTargetID], "Tried to allocate an already allocated query: %s", + query); self.targetIDs[boxedTargetID] = queryData; return queryData; } @@ -418,7 +417,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)releaseQuery:(FSTQuery *)query { self.persistence.run("Release query", [&]() { FSTQueryData *queryData = [self.queryCache queryDataForQuery:query]; - FSTAssert(queryData, @"Tried to release nonexistent query: %@", query); + HARD_ASSERT(queryData, "Tried to release nonexistent query: %s", query); [self.localViewReferences removeReferencesForID:queryData.targetID]; if (self.garbageCollector.isEager) { @@ -530,14 +529,14 @@ NS_ASSUME_NONNULL_BEGIN FSTMaybeDocument *_Nullable doc = remoteDoc; auto ackVersionIter = versions.find(docKey); - FSTAssert(ackVersionIter != versions.end(), - @"docVersions should contain every doc in the write."); + HARD_ASSERT(ackVersionIter != versions.end(), + "docVersions should contain every doc in the write."); const SnapshotVersion &ackVersion = ackVersionIter->second; if (!doc || doc.version < ackVersion) { doc = [batch applyTo:doc documentKey:docKey mutationBatchResult:batchResult]; if (!doc) { - FSTAssert(!remoteDoc, @"Mutation batch %@ applied to document %@ resulted in nil.", batch, - remoteDoc); + HARD_ASSERT(!remoteDoc, "Mutation batch %s applied to document %s resulted in nil.", batch, + remoteDoc); } else { [self.remoteDocumentCache addEntry:doc]; } -- cgit v1.2.3