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:
Terrence Cole 2012-06-01 15:41:27 -07:00
parent 0a03ebec4c
commit c15ef6f2b8
2 changed files with 7 additions and 3 deletions

View File

@ -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) {

View File

@ -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;
}