js-weak-refs.tq 1.61 KB
Newer Older
Tobias Tebbi's avatar
Tobias Tebbi committed
1 2 3 4
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6 7 8
bitfield struct FinalizationRegistryFlags extends uint31 {
  scheduled_for_cleanup: bool: 1 bit;
}

9
extern class JSFinalizationRegistry extends JSObject {
Tobias Tebbi's avatar
Tobias Tebbi committed
10
  native_context: NativeContext;
11
  cleanup: Callable;
Tobias Tebbi's avatar
Tobias Tebbi committed
12 13 14
  active_cells: Undefined|WeakCell;
  cleared_cells: Undefined|WeakCell;
  key_map: Object;
15 16 17
  // For the linked list of FinalizationRegistries that need cleanup. This
  // link is weak.
  next_dirty: Undefined|JSFinalizationRegistry;
18
  flags: SmiTagged<FinalizationRegistryFlags>;
Tobias Tebbi's avatar
Tobias Tebbi committed
19 20 21 22
}

@generateCppClass
extern class WeakCell extends HeapObject {
23
  finalization_registry: Undefined|JSFinalizationRegistry;
Tobias Tebbi's avatar
Tobias Tebbi committed
24
  target: Undefined|JSReceiver;
25 26
  unregister_token: JSAny;
  holdings: JSAny;
Tobias Tebbi's avatar
Tobias Tebbi committed
27

28
  // For storing doubly linked lists of WeakCells in JSFinalizationRegistry's
Tobias Tebbi's avatar
Tobias Tebbi committed
29 30 31 32
  // "active_cells" and "cleared_cells" lists.
  prev: Undefined|WeakCell;
  next: Undefined|WeakCell;

33
  // For storing doubly linked lists of WeakCells per key in
34 35 36
  // JSFinalizationRegistry's key-based hashmap. The key is the identity hash
  // of unregister_token. WeakCell also needs to know its token, so that we
  // can remove its corresponding key from the key_map when we remove the last
37 38
  // WeakCell associated with it or when the unregister_token dies. The
  // unregister token is stored above, after target, as both are weak.
Tobias Tebbi's avatar
Tobias Tebbi committed
39 40 41 42 43 44 45 46
  key_list_prev: Undefined|WeakCell;
  key_list_next: Undefined|WeakCell;
}

@generateCppClass
extern class JSWeakRef extends JSObject {
  target: Undefined|JSReceiver;
}