cpp

Write modern C++ code for V8 FFI wrappers with RAII and handle scopes.

11|Updated Nov 11, 2025
One-click install
npx skills add https://github.com/zig-whatwg/crane --skill cpp
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cpp
Source: https://github.com/zig-whatwg/crane/tree/main/skills/cpp
Command: npx skills add https://github.com/zig-whatwg/crane --skill cpp

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides a disciplined approach to writing high-quality, modern, and safe C++ code for V8 FFI wrappers and native integrations, reducing bugs and improving reliability.

Core Features & Use Cases

  • Modern C++ Practices: RAII, const-correctness, smart pointers, and explicit ownership to prevent leaks.
  • V8 FFI Patterns: Safe HandleScope usage, Local/Global handles, and proper context management for wrappers.
  • Safe Interoperability: Type-safe APIs, clear lifetime semantics, and ergonomic boundaries between C++ and Zig.

Quick Start

Create a minimal V8 wrapper skeleton in your project that demonstrates a simple FFI function using a v8::HandleScope, a Localv8::String return value, and a straightforward ownership model. Use this as a baseline to apply the patterns described in this skill.

Frequently Asked Questions about cpp

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

FAQPage Schema
What are modern C++ best practices for writing V8 FFI wrappers?

Modern C++ V8 FFI wrappers require RAII, const-correctness, and smart pointers to ensure safe memory management. You must use explicit HandleScope management and clear ownership models to prevent leaks and maintain reliable native integrations.

How do I manage V8 HandleScope and Local handles in a C++ wrapper?

To manage V8 HandleScope in C++, create a v8::HandleScope on the stack before allocating Local handles. This ensures temporary V8 objects are garbage collected automatically when the scope exits, preventing memory leaks in your FFI wrapper.

Can I use this C++ V8 FFI approach for interoperability with Zig runtimes?

Yes, this approach specifically supports safe interoperability between C++ and Zig in both small utilities and larger runtimes. It enforces type-safe APIs and clear lifetime semantics to maintain ergonomic boundaries for reliable cross-language execution.

What's the best way to prevent memory leaks in C++ V8 native integrations?

The best way to prevent leaks in C++ V8 native integrations is enforcing RAII and smart pointers for object lifetimes. Properly managing V8 Global and Local handles with explicit HandleScope boundaries ensures safe garbage collection and reliable cleanup.

Why does my C++ V8 wrapper crash when returning Local values across FFI boundaries?

V8 wrapper crashes during FFI returns often occur because Local handles outlive their HandleScope or lack clear ownership semantics. Establishing explicit Global handles, proper context management, and type-safe API boundaries prevents invalid object access during cross-runtime execution.