mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 04:15:43 +00:00
Bug 760342 - Check explicitly for mis-use of HashTable::Enum; r=luke
If a user does removeFront or rekeyFront on an Enum, then continues to use it, it will fail, potentially randomly. This patch makes the failure explicit in debug builds.
This commit is contained in:
parent
ab80151f3b
commit
722da9452b
@ -142,21 +142,23 @@ class HashTable : private AllocPolicy
|
||||
protected:
|
||||
friend class HashTable;
|
||||
|
||||
Range(Entry *c, Entry *e) : cur(c), end(e) {
|
||||
Range(Entry *c, Entry *e) : cur(c), end(e), validEntry(true) {
|
||||
while (cur < end && !cur->isLive())
|
||||
++cur;
|
||||
}
|
||||
|
||||
Entry *cur, *end;
|
||||
DebugOnly<bool> validEntry;
|
||||
|
||||
public:
|
||||
Range() : cur(NULL), end(NULL) {}
|
||||
Range() : cur(NULL), end(NULL), validEntry(false) {}
|
||||
|
||||
bool empty() const {
|
||||
return cur == end;
|
||||
}
|
||||
|
||||
T &front() const {
|
||||
JS_ASSERT(validEntry);
|
||||
JS_ASSERT(!empty());
|
||||
return cur->t;
|
||||
}
|
||||
@ -165,6 +167,7 @@ class HashTable : private AllocPolicy
|
||||
JS_ASSERT(!empty());
|
||||
while (++cur < end && !cur->isLive())
|
||||
continue;
|
||||
validEntry = true;
|
||||
}
|
||||
};
|
||||
|
||||
@ -205,6 +208,7 @@ class HashTable : private AllocPolicy
|
||||
void removeFront() {
|
||||
table.remove(*this->cur);
|
||||
removed = true;
|
||||
this->validEntry = false;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -221,6 +225,7 @@ class HashTable : private AllocPolicy
|
||||
table.remove(*this->cur);
|
||||
table.add(l, e);
|
||||
added = true;
|
||||
this->validEntry = false;
|
||||
}
|
||||
|
||||
void rekeyFront(const Key &k) {
|
||||
|
@ -187,7 +187,6 @@ class WeakMap : public HashMap<Key, Value, HashPolicy, RuntimeAllocPolicy>, publ
|
||||
markedAny = true;
|
||||
e.rekeyFront(k);
|
||||
}
|
||||
JS_ASSERT_IF(keyIsMarked, gc::IsMarked(&e.front().value));
|
||||
}
|
||||
return markedAny;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user