What problem does it solve?
Implementing new JavaScript APIs in Bun's Rust runtime requires bridging JavaScriptCore with native code, which involves repetitive boilerplate for constructors, prototypes, getters, and finalizers. This Skill provides the canonical patterns and signatures for using Bun's .classes.ts bindings generator and #[bun_jsc::JsClass] proc-macro.
Core Features & Use Cases
- Class Definition via
.classes.ts: Declare constructors, prototype methods, getters, finalize hooks, and pending activity flags in a TypeScript schema.
- Rust Implementation Patterns: Apply canonical method signatures for
constructor, host_fn methods, getters, and has_pending_activity that the codegen expects.
- JS Value Handling: Store JavaScript values safely through
WriteBarrier slots using *_set_cached and *_get_cached accessors instead of raw JSValue fields.
- Use Case: When adding a new built-in module like
Glob or Cron to Bun, define the JS surface in a .classes.ts file, implement the Rust struct with #[bun_jsc::JsClass], and run bun bd to regenerate the C++ and Rust bindings.
Quick Start
Create a new .classes.ts file defining the class schema, add the corresponding Rust struct annotated with #[bun_jsc::JsClass], and run bun bd to regenerate the bindings.