Skip to content
Development
Skill

/implementing-jsc-classes-rust

Creates JavaScript classes using Bun's bindings generator (.bind.ts). Use when implementing new JS APIs in Rust with JSC integration, prototypes, or constructors.

From plugin
bun
97k8 skills5 commands

Claude Code

$ npx -y skills add oven-sh/bun --skill implementing-jsc-classes-rust --agent claude-code

SKILL.md

implementing-jsc-classes-rust.SKILL.md
name: implementing-jsc-classes-rust
description: Creates JavaScript classes using Bun's bindings generator (.bind.ts). Use when implementing new JS APIs in Rust with JSC integration, prototypes, or constructors.

JavaScript classes implemented in Rust

A class is a `b.class({..})` exported from a `*.bind.ts` file and a Rust struct. `src/codegen/bindgen.ts` generates the C++ cell, prototype and constructor, the argument conversions, and the Rust functions that call the struct's methods. `docs/project/bindgen.mdx` is the reference: read its "Classes" section before writing one.

Schema

import * as b from "../../codegen/bindgen-lib.ts";

export const Matcher = b.class({
  rustPath: "crate::api::matcher::Matcher",
  construct: { args: { pattern: b.string.utf8 } },
  internalFields: ["callback"],
  proto: {
    match: { args: { text: b.string.utf8 }, returns: b.bool },
    pattern: { getter: b.string.utf8, cache: true },
  },
});

Rust

pub struct Matcher {
    pattern: Box<[u8]>,
}

impl Matcher {
    pub fn constructor(pattern: &[u8]) -> Self {
        Self { pattern: pattern.into() }
    }

    pub fn r#match(&self, text: &[u8]) -> bool {
        bun_core::strings::contains(text, &self.pattern)
    }

    pub fn get_pattern(&self) -> &[u8] {
        &self.pattern
    }
}

A missing or mis-typed method is a compile error: the generated code calls it directly.

Where the struct lives

  • Freed when its JS object is freed: it is stored inside the object. This is the default. Cleanup is `Drop`.
  • Can outlive its object (a timer, another thread or a C library still points at it): `refCounted: true`. It is a separate,

refcounted heap allocation, and the object holds one ref.

What a body may do

`capability: "heap"` adds `heap: &JsHeap<'a>` (allocate, throw). `capability: "js"` adds `cx: &mut JsScope<'a>` (also run JavaScript); `cx.global()` is the `&JSGlobalObject` the rest of the tree takes. `throws: true` makes the result a `JsResult<T>`. `passThis: true` adds the object, `this_value: JsWrapper<'a, Self>`.

Every member takes `&self`; state that changes is in `Cell` or `JsCell`.

Holding JS values

Never store a raw `JSValue` in a struct field. Declare an internal field (`internalFields: ["callback"]` or a `cache: true` getter) and use `js_Matcher::callback_set_cached(this_value, global, value)` / `callback_get_cached(this_value)` from `crate::generated_bindgen::<file>`. To reach its own object the struct stores a `JsRef`.

Reference implementations

  • `src/jsc/bindgen_test.bind.ts` + `src/jsc/bindgen_test.rs`: an example of most keys
  • `src/jsc/resolve_message.bind.ts`: cached getters, `prototypeBase`, `construct: "illegal"`
  • `src/runtime/api/cron.bind.ts`: `refCounted`, `finalize`
Read more
@oven-sh
Ships withbun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one

Stars on GitHub

Momentum

stars in total
96.7k
Star history of oven-sh/bun on GitHub, a chart by star-history.com

Other skills on bun.

implementing-jsc-classes-cpp

implementing-jsc-class…

Implements JavaScript classes in C++ using JavaScriptCore. Use when creating new JS classes with C++ bindings, prototypes, or…

@oven-sh@oven-shInstall Skill
rust-system-calls

rust-system-calls

Guides using bun_sys for system calls and file I/O in Rust. Use when implementing file operations, opening fds, or any syscall…

@oven-sh@oven-shInstall Skill
slowest-tests

slowest-tests

Find the top-N slowest test files in CI from a recent BuildKite run, optionally posting the results to a Slack channel as a…

@oven-sh@oven-shInstall Skill
verify

verify

Verify a Bun runtime change by driving the debug binary end-to-end.

@oven-sh@oven-shInstall Skill
writing-bundler-tests

writing-bundler-tests

Guides writing bundler tests using itBundled/expectBundled in test/bundler/. Use when creating or modifying bundler, transpiler,…

@oven-sh@oven-shInstall Skill

More skills from other plugins.

brainstorming
Auto-invoked

brainstorming

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or…

@obra@obraInstall Skill
ask-matt

ask-matt

Ask which skill or flow fits your situation. A router over the skills in this repo.

skills10d309k
@mattpocock@mattpocockInstall Skill
accessibility
Auto-invoked

accessibility

Design, implement, and audit accessible UI to WCAG 2.2 Level AA across Web, iOS, and Android — semantic ARIA roles and labels,…

ecc12d293k
@affaan-m@affaan-mInstall Skill
compiler-commit

compiler-commit

Use when you want to verify compiler changes and commit with the correct convention. Runs tests, lint, and format, then commits…

react1d252k
@facebook@facebookInstall Skill

Questions about implementing-jsc-classes-rust.

Which coding agents can use implementing-jsc-classes-rust?
implementing-jsc-classes-rust installs in Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode and Windsurf with the skills CLI, using each agent's flag shown on this page. Flowy's auto-invocation, which fires a skill when your prompt matches, runs in Claude Code only.