在chromium源码中,blink有大量的 Member模板

在chromium源码中,blink有


  Member<AgentGroupScheduler> agent_group_scheduler_;
  Member<PageAnimator> animator_;
  const Member<AutoscrollController> autoscroll_controller_;
  Member<ChromeClient> chrome_client_;
  const Member<DragCaret> drag_caret_;
  const Member<DragController> drag_controller_;
  const Member<FocusController> focus_controller_;
  const Member<ContextMenuController> context_menu_controller_;
  const Member<PageScaleConstraintsSet> page_scale_constraints_set_;

大量的 Member模板,比如 third_party/blink/renderer/core/page/page.h中

这个Member与v8引擎有关,说明它的模板参数是个可垃圾回收对象,强指针。

比如举个例子  Member<PageAnimator> animator_;:

class CORE_EXPORT PageAnimator final : public GarbageCollected<PageAnimator> {
 public:
  explicit PageAnimator(Page&);

在 third_party/blink/renderer/platform/heap/garbage_collected.h

template <typename T>

而它的Member在v8/include/cppgc/member.h


/**
 * Members are used in classes to contain strong pointers to other garbage
 * collected objects. All Member fields of a class must be traced in the class'
 * trace method.
 */
template <typename T>
using Member = internal::BasicMember<
    T, internal::StrongMemberTag, internal::DijkstraWriteBarrierPolicy,
    internal::DefaultMemberCheckingPolicy, internal::DefaultMemberStorage>;

/**
 * WeakMember is similar to Member in that it is used to point to other garbage
 * collected objects. However instead of creating a strong pointer to the
 * object, the WeakMember creates a weak pointer, which does not keep the
 * pointee alive. Hence if all pointers to to a heap allocated object are weak
 * the object will be garbage collected. At the time of GC the weak pointers
 * will automatically be set to null.
 */
template <typename T>
using WeakMember = internal::BasicMember<
    T, internal::WeakMemberTag, internal::DijkstraWriteBarrierPolicy,
    internal::DefaultMemberCheckingPolicy, internal::DefaultMemberStorage>;

/**
 * UntracedMember is a pointer to an on-heap object that is not traced for some
 * reason. Do not use this unless you know what you are doing. Keeping raw
 * pointers to on-heap objects is prohibited unless used from stack. Pointee
 * must be kept alive through other means.
 */
template <typename T>
using UntracedMember = internal::BasicMember<
    T, internal::UntracedMemberTag, internal::NoWriteBarrierPolicy,
    internal::DefaultMemberCheckingPolicy, internal::DefaultMemberStorage>;

 

posted @ 2023-05-17 16:37  Bigben  阅读(146)  评论(0编辑  收藏  举报