Skip to content
Skills Library
Programming · Building & coding

implementing-jsc-classes-rust

/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.

Repository
bun ↗
Licence
MIT
Last repository change
27.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 27.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

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

Original author 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.

How it works

  1. Schema
  2. Rust
  3. Where the struct lives
  4. What a body may do
  5. Holding JS values
  6. Reference implementations
Original SKILL.md headings · 73 lines, 344 words
SKILL.md preview
---
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

```typescript
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

```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`

Versions

The database has no other skills named implementing-jsc-classes-rust.

Identical content appears in 1 other GitHub folders. We show one copy with the highest score.

Database snapshot: 13.11.2026 · package version f86b2088a822 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100implementing-jsc-classes-cpp
    Implements JavaScript classes in C++ using JavaScriptCore. Use when creating new JS classes with C++ bindings, prototypes, or constructors.
  • 100javascriptcore-garbage-collector
    JSC GC reference for Bun. Use for use-after-free, JS object leaks, "collected too early", or when touching WriteBarrier, visitChildren, visitAdditionalChildren, JSRef, JSC::Strong/Weak, hasPendingActivity, ensureStillAlive, addOpaqueRoot, reportExtraMemoryAllocated, IsoSubspace,…
  • 100audit-performance-frontend
    Low-level frontend performance audit, specialized for WebKit/JSC and embedded or real-time contexts - on a mainstream stack (React/Chrome SPA) many questions are N/A and the grid adapts. Use when auditing frontend rendering performance, WebKit internals, JSC optimization, DOM…
  • 100bun-runtime
    Use when working with Bun's runtime APIs including file I/O, HTTP servers, and native APIs. Covers modern JavaScript/TypeScript execution in Bun's fast runtime environment.
  • 90bun
    Bun runtime and modern JavaScript backend practices, including Bun-native tooling (bun run/test/build) and PostgreSQL usage guidance. Use when building or reviewing Bun-based services, APIs, scripts, or when Bun-specific workflow questions arise.
  • 100bun
    Assists with using Bun as an all-in-one JavaScript/TypeScript runtime, package manager, bundler, and test runner. Use when building HTTP servers, managing packages, running tests, or migrating from Node.js. Trigger words: bun, bun serve, bun install, bun test, bun build,…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.