From c15ef6f2b80fc9c8c7ae379293f73972173ec3c3 Mon Sep 17 00:00:00 2001 From: Terrence Cole Date: Fri, 1 Jun 2012 15:41:27 -0700 Subject: [PATCH] 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. --- js/public/HashTable.h | 9 +++++++-- js/src/jsweakmap.h | 1 - 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/js/public/HashTable.h b/js/public/HashTable.h index ae5cc21aac8f..9e2caab51375 100644 --- a/js/public/HashTable.h +++ b/js/public/HashTable.h @@ -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 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) { diff --git a/js/src/jsweakmap.h b/js/src/jsweakmap.h index a4d05d29e910..7680151b37b9 100644 --- a/js/src/jsweakmap.h +++ b/js/src/jsweakmap.h @@ -187,7 +187,6 @@ class WeakMap : public HashMap, publ markedAny = true; e.rekeyFront(k); } - JS_ASSERT_IF(keyIsMarked, gc::IsMarked(&e.front().value)); } return markedAny; }