Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Unified Diff: src/objects.cc

Issue 1145183004: Debugger: use weak cells to implement ScriptCache. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index ecb5bf1b5164265ae48d7f4be04d01181a7c8c65..f919c9da78d7c7539fbf04b35c30b19e3182872a 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -16411,6 +16411,49 @@ void WeakHashTable::AddEntry(int entry, Handle<WeakCell> key_cell,
}
+#ifdef DEBUG
+Object* WeakValueHashTable::LookupWeak(Handle<Object> key) {
+ Object* value = Lookup(key);
+ if (value->IsWeakCell() && !WeakCell::cast(value)->cleared()) {
+ value = WeakCell::cast(value)->value();
+ }
+ return value;
+}
+#endif // DEBUG
+
+
+Handle<WeakValueHashTable> WeakValueHashTable::PutWeak(
+ Handle<WeakValueHashTable> table, Handle<Object> key,
+ Handle<HeapObject> value) {
+ Handle<WeakCell> cell = value->GetIsolate()->factory()->NewWeakCell(value);
+ return Handle<WeakValueHashTable>::cast(
+ Put(Handle<ObjectHashTable>::cast(table), key, cell));
+}
+
+
+Handle<FixedArray> WeakValueHashTable::GetWeakValues(
+ Handle<WeakValueHashTable> table) {
+ Isolate* isolate = table->GetIsolate();
+ uint32_t capacity = table->Capacity();
+ Handle<FixedArray> results = isolate->factory()->NewFixedArray(capacity);
+ int length = 0;
+ for (uint32_t i = 0; i < capacity; i++) {
+ uint32_t key_index = table->EntryToIndex(i);
+ Object* key = table->get(key_index);
+ if (!table->IsKey(key)) continue;
+ uint32_t value_index = table->EntryToValueIndex(i);
+ WeakCell* value_cell = WeakCell::cast(table->get(value_index));
+ if (value_cell->cleared()) {
+ table->RemoveEntry(i);
+ } else {
+ results->set(length++, value_cell->value());
+ }
+ }
+ results->Shrink(length);
+ return results;
+}
+
+
template<class Derived, class Iterator, int entrysize>
Handle<Derived> OrderedHashTable<Derived, Iterator, entrysize>::Allocate(
Isolate* isolate, int capacity, PretenureFlag pretenure) {
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698