implementing-jsc-classes-cpp

Bind C++ classes to JavaScript in Bun's JSC runtime via prototypes and constructors.

Updated Jan 6, 2026
One-click install
npx skills add https://github.com/zhcndoc/bun --skill implementing-jsc-classes-cpp
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: implementing-jsc-classes-cpp
Source: https://github.com/zhcndoc/bun/tree/main/.claude/skills/implementing-jsc-classes-cpp
Command: npx skills add https://github.com/zhcndoc/bun --skill implementing-jsc-classes-cpp

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill provides a structured approach to exposing native C++ classes to JavaScript in Bun's JavaScriptCore (JSC) runtime, enabling JS code to instantiate and interact with high-performance native objects.

Core Features & Use Cases

  • Bind C++ classes to JS by defining a FooPrototype and a FooConstructor, with a public Foo class and optional internal fields.
  • Create robust prototypes and constructors that integrate with Bun's memory spaces and subspaces to ensure proper lifecycle and performance.
  • Use cases include building native bindings for graphics, data processing, or system-level APIs that require JS-facing wrappers.

Quick Start

Define your C++ class, implement FooPrototype and FooConstructor following the pattern in the example, hook into Bun's Zig registration, and compile Bun to expose the new JS type.

Frequently Asked Questions about implementing-jsc-classes-cpp

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

FAQPage Schema
How do I expose a C++ class to JavaScript in Bun's JSC runtime?

To expose a C++ class to JavaScript in Bun's JSC runtime, define a public class with a corresponding FooPrototype and FooConstructor, then wire them into Bun's Zig registration entry points to create a native JS-visible type.

What is the pattern for binding C++ prototypes and constructors in JavaScriptCore?

Binding C++ prototypes and constructors in JavaScriptCore requires defining separate structures for the prototype and constructor, integrating them with Bun's memory subspaces to ensure proper object lifecycle and performance.

How do I add native JS bindings with public constructors and methods in Bun?

Adding native JS bindings with public constructors and methods in Bun involves implementing the class definition, hooking into Bun's Zig registration system, and compiling Bun to expose the newly defined JavaScript type.

Can I use this C++ to JS binding technique for system-level APIs and data processing?

Yes, binding C++ classes to JS in Bun's JSC runtime is suited for building high-performance native bindings for graphics, data processing, or system-level APIs that require JavaScript-facing wrappers.

Does binding C++ classes in Bun require integrating with memory subspaces?

Yes, creating robust prototypes and constructors when binding C++ classes in Bun requires integrating with Bun's memory spaces and subspaces to ensure proper native object lifecycle and performance.