35 if (IsUndefined(finalization_registry->key_map(), isolate)) {
36 key_map = SimpleNumberDictionary::New(isolate, 1);
39 handle(Cast<SimpleNumberDictionary>(finalization_registry->key_map()),
49 if (entry.is_found()) {
50 Tagged<Object> value = key_map->ValueAt(entry);
51 Tagged<WeakCell> existing_weak_cell = Cast<WeakCell>(value);
52 existing_weak_cell->set_key_list_prev(*weak_cell);
53 weak_cell->set_key_list_next(existing_weak_cell);
56 finalization_registry->set_key_map(*key_map);
74 GCNotifyUpdatedSlotCallback gc_notify_updated_slot) {
79 if (IsUndefined(key_map(), isolate)) {
88 if (IsUndefined(hash, isolate)) {
98 bool was_present =
false;
105 while (!IsUndefined(value, isolate)) {
108 value = weak_cell->key_list_next();
109 if (weak_cell->unregister_token() == unregister_token) {
111 switch (removal_mode) {
113 weak_cell->RemoveFromFinalizationRegistryCells(isolate);
120 weak_cell->set_unregister_token(undefined);
121 weak_cell->set_key_list_prev(undefined);
122 weak_cell->set_key_list_next(undefined);
127 weak_cell->set_key_list_prev(new_key_list_prev);
128 gc_notify_updated_slot(weak_cell,
129 weak_cell->RawField(WeakCell::kKeyListPrevOffset),
131 weak_cell->set_key_list_next(undefined);
132 if (IsUndefined(new_key_list_prev, isolate)) {
133 new_key_list_head = weak_cell;
135 DCHECK(IsWeakCell(new_key_list_head));
137 prev_cell->set_key_list_next(weak_cell);
138 gc_notify_updated_slot(
139 prev_cell, prev_cell->RawField(WeakCell::kKeyListNextOffset),
142 new_key_list_prev = weak_cell;
145 if (IsUndefined(new_key_list_head, isolate)) {
147 key_map->ClearEntry(entry);
148 key_map->ElementRemoved();
150 key_map->ValueAtPut(entry, new_key_list_head);
151 gc_notify_updated_slot(key_map, key_map->RawFieldOfValueAt(entry),
171 GCNotifyUpdatedSlotCallback gc_notify_updated_slot) {
182 if (IsWeakCell(prev())) {
185 prev_cell->set_next(next());
186 gc_notify_updated_slot(prev_cell,
187 prev_cell->RawField(WeakCell::kNextOffset), next());
190 fr->set_active_cells(next());
191 gc_notify_updated_slot(
192 fr, fr->RawField(JSFinalizationRegistry::kActiveCellsOffset), next());
194 if (IsWeakCell(next())) {
196 next_cell->set_prev(prev());
197 gc_notify_updated_slot(next_cell,
198 next_cell->RawField(WeakCell::kPrevOffset), prev());
203 if (IsWeakCell(cleared_head)) {
205 cleared_head_cell->set_prev(*
this);
206 gc_notify_updated_slot(cleared_head_cell,
207 cleared_head_cell->RawField(WeakCell::kPrevOffset),
210 set_next(fr->cleared_cells());
211 gc_notify_updated_slot(*
this, RawField(WeakCell::kNextOffset), next());
212 fr->set_cleared_cells(*
this);
213 gc_notify_updated_slot(
214 fr, fr->RawField(JSFinalizationRegistry::kClearedCellsOffset), *
this);
228 if (fr->active_cells() == *
this) {
229 DCHECK(IsUndefined(prev(), isolate));
230 fr->set_active_cells(next());
231 }
else if (fr->cleared_cells() == *
this) {
232 DCHECK(!IsWeakCell(prev()));
233 fr->set_cleared_cells(next());
235 DCHECK(IsWeakCell(prev()));
237 prev_cell->set_next(next());
239 if (IsWeakCell(next())) {
241 next_cell->set_prev(prev());