Index: src/unique.h |
diff --git a/src/unique.h b/src/unique.h |
index 38cc336426fa8403db3241b3fcf1fe360d2a368f..96a5329754a44589f8346d5ce0f0bc23f20adeac 100644 |
--- a/src/unique.h |
+++ b/src/unique.h |
@@ -83,29 +83,41 @@ class Unique V8_FINAL { |
template <typename U> |
bool operator==(const Unique<U>& other) const { |
+ ASSERT(IsInitialized() && other.IsInitialized()); |
return raw_address_ == other.raw_address_; |
} |
template <typename U> |
bool operator!=(const Unique<U>& other) const { |
+ ASSERT(IsInitialized() && other.IsInitialized()); |
return raw_address_ != other.raw_address_; |
} |
intptr_t Hashcode() const { |
+ ASSERT(IsInitialized()); |
return reinterpret_cast<intptr_t>(raw_address_); |
} |
- bool IsNull() { |
+ bool IsNull() const { |
+ ASSERT(IsInitialized()); |
return raw_address_ == NULL; |
} |
- // Don't do this unless you have access to the heap! |
- // No, seriously! You can compare and hash and set-ify uniques that were |
- // all created at the same time; please don't dereference. |
- Handle<T> handle() { |
+ // Extract the handle from this Unique in order to dereference it. |
+ // WARNING: Only do this if you have access to the heap. |
+ Handle<T> handle() const { |
return handle_; |
} |
+ bool IsInitialized() const { |
+ return raw_address_ != NULL || handle_.is_null(); |
+ } |
+ |
+ // TODO(titzer): this is a hack to migrate to Unique<T> incrementally. |
+ static Unique<T> CreateUninitialized(Handle<T> handle) { |
+ return Unique<T>(static_cast<Address>(NULL), handle); |
+ } |
+ |
friend class UniqueSet<T>; // Uses internal details for speed. |
template <class U> |
friend class Unique; // For comparing raw_address values. |
@@ -124,6 +136,7 @@ class UniqueSet V8_FINAL : public ZoneObject { |
// Add a new element to this unique set. Mutates this set. O(|this|). |
void Add(Unique<T> uniq, Zone* zone) { |
+ ASSERT(uniq.IsInitialized()); |
// Keep the set sorted by the {raw_address} of the unique elements. |
for (int i = 0; i < size_; i++) { |
if (array_[i] == uniq) return; |