Files
electron/shell/common/gc_plugin.h
Robo 9be03cbe54 fix: enable blink gc plugin (#50465)
chore: address blink gc plugin errors

Key fixes:
- Replace `base::WeakPtrFactory` with `gin::WeakCellFactory` in
  MenuMac, MenuViews, and NetLog, since weak pointers to cppgc-managed
  objects must go through weak cells
- Replace `v8::Global<v8::Value>` with `cppgc::Persistent<Menu>` for
  the menu reference in BaseWindow
- Stop using `gin_helper::Handle<T>` with cppgc types; use raw `T*`
  and add a `static_assert` to prevent future misuse
- Add proper `Trace()` overrides for Menu, MenuMac, MenuViews, and
  NetLog to ensure cppgc members are visited during garbage collection
- Replace `SelfKeepAlive` prevent-GC mechanism in Menu with a
  `cppgc::Persistent` prevent-GC captured in `BindSelfToClosure`
- Introduce `GC_PLUGIN_IGNORE` macro to suppress
  known-safe violations: mojo::Remote fields, ObjC bridging pointers,
  and intentional persistent self-references
- Mark `ArgumentHolder` as `CPPGC_STACK_ALLOCATED()` in both Electron's
  and gin's function_template.h to silence raw-pointer-to-GC-type
  warnings
2026-04-11 03:21:39 +09:00

20 lines
691 B
C

// Copyright (c) 2025 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ELECTRON_SHELL_COMMON_GC_PLUGIN_H_
#define ELECTRON_SHELL_COMMON_GC_PLUGIN_H_
// GC_PLUGIN_IGNORE is used to make the Blink GC plugin ignore a particular
// class or field when checking for proper usage. When using GC_PLUGIN_IGNORE
// a reason must be provided as an argument.
// Based on third_party/blink/renderer/platform/wtf/gc_plugin.h
#if defined(__clang__)
#define GC_PLUGIN_IGNORE(reason) \
__attribute__((annotate("blink_gc_plugin_ignore")))
#else
#define GC_PLUGIN_IGNORE(reason)
#endif
#endif // ELECTRON_SHELL_COMMON_GC_PLUGIN_H_