Skip to content

Move to gin::Wrappable based on cppgc #47922

Open

Description

@deepak1556

Confirmation

Description

Refs https://chromium-review.googlesource.com/c/chromium/src/+/6700110

Move from gin::DeprecatedWrappable to gin::Wrappable based on cppgc

  • Run with ProcessInitializationFlags::kNoInitializeCppgc for all processes, V8::Initialize takes care of cppgc initialization and isolateholder initialization takes care of cppheap setup as part of isolate initialization

Activity

  1. added
    upgrade-follow-up
    on Jul 31, 2025
  2. added theissue type on Jul 31, 2025
  3. self-assigned this
    on Jul 31, 2025
  4. deepak1556 commented on Aug 1, 2025

    @deepak1556
    MemberAuthor

    The core parts of the transition for a simple wrappable object involves, example: https://chromium-review.googlesource.com/c/chromium/src/+/6523561

    Header File:

    1. Replace gin::DeprecatedWrappable<T> => gin::Wrappable<T>
    2. Replace gin::DeprecatedWrapperInfo => gin::WrapperInfo
    3. Override gin::Wrappable::wrapper_info() to use the static variable, check the function declaration for reason around using virtual dispatch to access the static variable https://source.chromium.org/chromium/chromium/src/+/main:gin/wrappable.h;l=74-78
    gin::WrapperInfo* wrapper_info() const override { return &kWrapperInfo; }
    
    1. Replace gin::DeprecatedObjectTemplateBuilder => gin::ObjectTemplateBuilder

    Implementation File:

    1. Declaring a pointer tag in gin/public/wrappable_pointer_tags.h https://source.chromium.org/chromium/chromium/src/+/main:gin/public/wrappable_pointer_tags.h. The tag will be used as type check when dereferencing a wrapper from the cpp heap
    2. Defining T::WrapperInfo with the pointer tag
    gin::WrapperInfo T::kWrapperInfo = 
        {{gin::kEmbedderNativeGin}, <declared pointer tag>};
    
    1. gin::CreateHandle will be replaced by cppgc::MakeGarbageCollected<T> which will return an pointer T*
    // old
    gin::Handle<T> T::Create(v8::Isolate* isolate, ...args) {
      return gin::CreateHandle(isolate, new T(...args));
    }
    
    // new
    T* T::Create(v8::Isolate* isolate, ...args) {
      return cppgc::MakeGarbageCollected<T>(
          isolate->GetCppHeap()->GetAllocationHandle(), ...args);
     }
    
    1. Places where a wrapper object is needed should be extracted from the above cpp heap allocated object via gin::ConvertToV8. This is possible because of the converters in https://source.chromium.org/chromium/chromium/src/+/main:gin/wrappable.h;l=108-148
  5. deepak1556 commented on Aug 4, 2025

    @deepak1556
    MemberAuthor

    Pre-req:

    • Make gin_helper::EventEmitterMixin<T> inherit from cppgc::GarbageCollectedMixin
    • Create gin_helper::SelfKeepAlive<T> that uses cppgc::Persistent

    shell/browser

    shell/common

    • electron_api_native_image
    • electron_api_url_loader
      • Make JSChunkedDataPipeGetter a gin::Wrappable, and make it a cppgc::Member of the SimpleURLLoaderWrapper class, trace it
    • ChunkedDataPipeReadableStream
    • gin_helper::Constructible
    • gin_helper::internal::Event
    • gin_helper::internal::ReplyChannel

    shell/renderer

    • IPCBase
    • WebFrameRenderer
    • ParentPort
  6. deepak1556 commented on Aug 28, 2025

    @deepak1556
    MemberAuthor

    Following changes can be used to run the blink-gc-plugin to get some compile time sanity. The plugin was created for Oilpan project of Blink but it has been adopted to cover cppgc namespaces in https://chromium-review.googlesource.com/c/chromium/src/+/2655961

    diff --git a/BUILD.gn b/BUILD.gn
    index bcc0720928..0b5dba5453 100644
    --- a/BUILD.gn
    +++ b/BUILD.gn
    @@ -542,6 +542,12 @@ source_set("electron_lib") {
         "V8_DEPRECATION_WARNINGS",
       ]
       libs = []
    +  cflags = [
    +    "-Xclang",
    +    "-add-plugin",
    +    "-Xclang",
    +    "blink-gc-plugin",
    +  ]
     
       if (is_linux) {
         defines += [ "GDK_DISABLE_DEPRECATION_WARNINGS" ]
    diff --git a/shell/common/gin_helper/self_keep_alive.h b/shell/common/gin_helper/self_keep_alive.h
    index 0e0c622f03..ddb583ec45 100644
    --- a/shell/common/gin_helper/self_keep_alive.h
    +++ b/shell/common/gin_helper/self_keep_alive.h
    @@ -11,7 +11,7 @@ namespace gin_helper {
     
     // Based on third_party/blink/renderer/platform/heap/self_keep_alive.h
     template <typename Self>
    -class SelfKeepAlive final {
    +class __attribute__((annotate("blink_gc_plugin_ignore"))) SelfKeepAlive final {
       GIN_DISALLOW_NEW();
     
      public:
    diff --git a/shell/renderer/preload_realm_context.cc b/shell/renderer/preload_realm_context.cc
    index 1912c9aabc..5757979072 100644
    --- a/shell/renderer/preload_realm_context.cc
    +++ b/shell/renderer/preload_realm_context.cc
    @@ -194,6 +194,7 @@ class PreloadRealmLifetimeController
       std::unique_ptr<base::ProcessMetrics> metrics_;
       raw_ptr<ServiceWorkerData> service_worker_data_;
     
    +  __attribute__((annotate("blink_gc_plugin_ignore")))
       blink::Persistent<PreloadRealmLifetimeController> self_;
     };
     
  7. deepak1556 commented on Mar 26, 2026

    @deepak1556
    MemberAuthor

    Temporary hold off on transitioning any new classes till #50465 is merged and we got the clang plugin enabled by default on main.

  8. deepak1556 commented on Apr 10, 2026

    @deepak1556
    MemberAuthor

    Plugin has been enabled by default.

  9. added a commit that references this issue on May 20, 2026
  10. muhamadhidayat3781-ux commented on Jun 7, 2026

    @muhamadhidayat3781-ux
  11. deepak1556 commented on Jun 10, 2026

    @deepak1556
    MemberAuthor

    Upstream removed the old classes https://chromium-review.googlesource.com/c/chromium/src/+/7837883, the patch maintained in 7e39ee1 can be removed once this transition is complete.

  12. added a commit that references this issue on Jul 14, 2026
  13. added a commit that references this issue on Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

upgrade-follow-up

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions