Skip to content

Commit

Permalink
Add a note about builtins
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner committed Feb 9, 2023
1 parent 523b112 commit ad9d4fb
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ The ESM modules in Bun are located in `src/bun.js/*.exports.js`. Unlike other co

The module loader is in `src/bun.js/module_loader.zig`.

### JavaScript Builtins

JavaScript builtins are located in `src/bun.js/builtins/*.js`.

These files support a JavaScriptCore-only syntax for internal slots. `@` is used to access an internal slot. For example: `new @Array(123)` will create a new `Array` similar to `new Array(123)`, except if a library modifies the `Array` global, it will not affect the internal slot (`@Array`). These names must be allow-listed in `BunBuiltinNames.h` (though JavaScriptCore allowlists some names by default).

They can not use or reference ESM-modules. The files that end with `*Internals.js` are automatically loaded globally. Most usage of internals right now are the stream implementations (which share a lot of code from Safari/WebKit) and ImportMetaObject (which is how `require` is implemented in the runtime)

To regenerate the builtins:

```sh
make clean-bindings && make generate-builtins && make bindings -j10
```

It is recommended that you have ccache installed or else you will spend a lot of time waiting for the bindings to compile.

### Memory management in Bun's JavaScript runtime

TODO: fill this out (for now, use `JSC.Strong` in most cases)
Expand Down

0 comments on commit ad9d4fb

Please sign in to comment.