Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

implementing-jsc-classes-rust

/implementing-jsc-classes-rust

Tworzy klasy JavaScript przez generator wiązań Bun (.bind.ts), implementując nowe API JS w Rust z integracją JSC, prototypami i konstruktorami.

Repozytorium
bun ↗
Licencja
MIT
Ostatnia zmiana repozytorium
27.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 27.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Tworzy klasy JavaScript przez generator wiązań Bun (.bind.ts), implementując nowe API JS w Rust z integracją JSC, prototypami i konstruktorami.

Oryginalny opis (EN)

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

Jak działa

  1. Schema
  2. Rust
  3. Where the struct lives
  4. What a body may do
  5. Holding JS values
  6. Reference implementations
Sekcje z nagłówków SKILL.md, w oryginale · 73 linii, 344 słów
Podgląd 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

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

Wersje

W bazie nie ma innych skilli o nazwie implementing-jsc-classes-rust.

Identyczna treść występuje jeszcze w 1 innych folderach na GitHubie. Tu pokazujemy jedną, najlepiej ocenioną kopię.

Migawka bazy z 13.11.2026 · wersja paczki f86b2088a822 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100implementing-jsc-classes-cpp
    Implementuje klasy JavaScript w C++ przez JavaScriptCore, z wiązaniami, prototypami i konstruktorami.
  • 100javascriptcore-garbage-collector
    Opisuje garbage collector JavaScriptCore w Bun: use-after-free, wycieki obiektów JS, zbyt wczesne zebranie oraz WriteBarrier, visitChildren, JSRef, Strong i Weak.
  • 100audit-performance-frontend
    Audytuje niskopoziomową wydajność front-endu, głównie w WebKit/JSC i kontekstach wbudowanych: renderowanie, DOM, potok CSS, pamięć i GC, cache oraz profilowanie.
  • 100bun-runtime
    Obsługuje API runtime Bun, w tym operacje na plikach, serwery HTTP i natywne API, przy nowoczesnym wykonywaniu JavaScript i TypeScript.
  • 90bun
    Podpowiada dobre praktyki dla usług i skryptów w Bun, w tym polecenia bun run, test i build oraz użycie PostgreSQL.
  • 100bun
    Pomaga korzystać z Bun jako uniwersalnego środowiska JavaScript i TypeScript, menedżera pakietów, bundlera i test runnera: serwery HTTP, pakiety, testy i migracja z Node.js.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.