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

Unified Diff: src/heap/objects-visiting-inl.h

Issue 2915793002: [api] Prototype WeakRef implementation
Patch Set: Created 3 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/heap/objects-visiting.cc ('k') | src/heap/scavenger.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/heap/objects-visiting-inl.h
diff --git a/src/heap/objects-visiting-inl.h b/src/heap/objects-visiting-inl.h
index 2b82c6b29ef0a7f4ddf9e0fa80ce920535723c70..2adc9dcb23f1eab508549d79e8436ec460c1a362 100644
--- a/src/heap/objects-visiting-inl.h
+++ b/src/heap/objects-visiting-inl.h
@@ -164,6 +164,8 @@ void StaticMarkingVisitor<StaticVisitor>::Initialize() {
table_.Register(kVisitJSWeakCollection, &VisitWeakCollection);
+ table_.Register(kVisitJSWeakRef, &VisitWeakRef);
+
table_.Register(
kVisitOddball,
&FixedBodyVisitor<StaticVisitor, Oddball::BodyDescriptor, void>::Visit);
@@ -399,6 +401,35 @@ void StaticMarkingVisitor<StaticVisitor>::VisitWeakCollection(
StaticVisitor::MarkObjectWithoutPush(heap, obj);
}
+template <typename StaticVisitor>
+void StaticMarkingVisitor<StaticVisitor>::VisitWeakRef(
+ Map* map, HeapObject* object) {
+ Heap* heap = map->GetHeap();
+ JSWeakRef* weak_ref =
+ reinterpret_cast<JSWeakRef*>(object);
+
+ if (weak_ref->executor() != nullptr) {
+ StaticVisitor::MarkObject(heap, weak_ref->executor());
+ }
+ if (weak_ref->holdings() != nullptr && weak_ref->holdings()->IsHeapObject()) {
+ StaticVisitor::MarkObject(heap,
+ reinterpret_cast<HeapObject*>(weak_ref->holdings()));
+ }
+ if (weak_ref->target() != nullptr) {
+ StaticVisitor::MarkObject(heap, weak_ref->target());
+ if (weak_ref->held()) {
+ if (!weak_ref->target()->cleared()) {
+ StaticVisitor::MarkObject(heap,
+ reinterpret_cast<JSObject*>(weak_ref->target()->value()));
+ }
+ } else if (weak_ref->target()->cleared()) {
+ weak_ref->set_target(nullptr);
+ weak_ref->set_held(false);
+ weak_ref->set_queued(true);
+ }
+ }
+}
+
template <typename StaticVisitor>
void StaticMarkingVisitor<StaticVisitor>::VisitCode(Map* map,
« no previous file with comments | « src/heap/objects-visiting.cc ('k') | src/heap/scavenger.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698