gc-safe-coding

Enforce GC-safe C++ coding rules for Hermes VM runtime.

11.2k|839|Updated Oct 22, 2018
One-click install
npx skills add https://github.com/facebook/hermes --skill gc-safe-coding
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: gc-safe-coding
Source: https://github.com/facebook/hermes/tree/main/.claude/skills/gc-safe-coding
Command: npx skills add https://github.com/facebook/hermes --skill gc-safe-coding

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides essential guidelines for writing and reviewing C++ code within the Hermes VM runtime, specifically focusing on memory safety and preventing crashes related to garbage collection.

Core Features & Use Cases

  • GC Safepoint Management: Ensures that raw pointers and PseudoHandles to GC objects are properly rooted before any operation that might trigger a garbage collection.
  • Modern Rooting Techniques: Mandates the use of Locals and PinnedValue for new code, discouraging older methods like GCScope and makeHandle().
  • Robust Error Handling: Emphasizes checking CallResult for exceptions before using the returned values.
  • Use Case: When developing new features or fixing bugs in the core VM logic of Hermes, developers must adhere to these rules to maintain runtime stability and prevent memory corruption.

Quick Start

Follow the checklist provided in the skill's documentation to ensure your C++ code is GC-safe.

Frequently Asked Questions about gc-safe-coding

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write GC-safe C++ code in the Hermes VM runtime?

To write GC-safe C++ code in the Hermes VM runtime, you must use modern rooting techniques like Locals and PinnedValue, and ensure raw pointers are properly rooted before operations that might trigger garbage collection.

Why do I need to root raw pointers to GC objects before a safepoint?

Rooting raw pointers to GC objects before a safepoint is required to prevent memory corruption and crashes, because garbage collection can move or reclaim unrooted objects during runtime operations.

What rooting patterns should I use for new Hermes VM C++ code?

For new Hermes VM C++ code, you should use Locals and PinnedValue rooting patterns, while avoiding older methods like GCScope and makeHandle() to ensure proper memory safety.

How do I handle CallResult exceptions when using Hermes VM APIs?

To handle CallResult exceptions in Hermes VM APIs, you must explicitly check the CallResult for exceptions before using the returned values to prevent runtime instability and ensure robust error handling.

When should I avoid GCScope and makeHandle() in Hermes runtime development?

You should avoid GCScope and makeHandle() when developing new features or fixing bugs in the core Hermes VM logic, as modern rooting techniques like Locals and PinnedValue are mandated for memory safety.

Does Hermes VM C++ code review require checking specific garbage collection rules?

Yes, Hermes VM C++ code review requires enforcing strict rules for GC-managed types, handles, and safepoints, ensuring developers adhere to specific rooting patterns to prevent memory corruption.