---
title: "How Bun supports V8 APIs without using V8 (part 2)"
description: "Bun emulates V8's memory layout on top of JavaScriptCore so that precompiled native addons, which inline V8 functions assuming specific pointer layouts, keep working."
url: "https://swe.quest/articles/how-bun-supports-v8-apis-without-using-v8-part-2-d765ff746fe7a86a"
canonical: "https://bun.com/blog/how-bun-supports-v8-apis-without-using-v8-part-2"
source: "Bun"
published: "2024-11-05"
difficulty: "hard"
kind: "Deep dive"
reading_minutes: 18
tags: ["runtimes","javascript","c-cpp","memory-management"]
---

# How Bun supports V8 APIs without using V8 (part 2)

A post on [Bun](https://swe.quest/sources/bun.md), published 2024-11-05, 18 min read, Deep dive. Original: [https://bun.com/blog/how-bun-supports-v8-apis-without-using-v8-part-2](https://bun.com/blog/how-bun-supports-v8-apis-without-using-v8-part-2)

## Summary

Bun emulates V8's memory layout on top of JavaScriptCore so that precompiled native addons, which inline V8 functions assuming specific pointer layouts, keep working. The approach uses tagged pointers (Smis or heap pointers), a small set of static fake Map objects with instance types at the expected offset, and 24-byte Handles in a handle scope that store the tagged pointer, map pointer and JSCell pointer side by side, avoiding separate allocations outside the GC. Walkthroughs of Local, HandleScope, Number::New/Value and objects with internal fields show how JSC values are presented to V8-compiled code.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Runtimes & VMs](https://swe.quest/tags/runtimes.md) (Compilers & runtimes)
- [JavaScript](https://swe.quest/tags/javascript.md) (Languages)
- [C & C++](https://swe.quest/tags/c-cpp.md) (Languages)
- [Memory management](https://swe.quest/tags/memory-management.md) (Compilers & runtimes)

## Prerequisites

- C++ memory layout and pointers ([easy posts on C & C++](https://swe.quest/tags/c-cpp.md?difficulty=easy))
- JavaScript engine object representation ([easy posts on Runtimes & VMs](https://swe.quest/tags/runtimes.md?difficulty=easy))
- Node.js native addons ([easy posts on JavaScript](https://swe.quest/tags/javascript.md?difficulty=easy))

## Keywords

Bun, V8, JavaScriptCore, Node-API, HandleScope, tagged pointers

## Related posts

- [How Bun supports V8 APIs without using V8 (part 1)](https://swe.quest/articles/how-bun-supports-v8-apis-without-using-v8-part-1-ff8148b61cb465d8.md): Bun · 2024-09-30 · Hard · 19 min read · Runtimes & VMs, C & C++, JavaScript, Memory management
  Bun, which runs on JavaScriptCore, implements a growing subset of V8's C++ embedding API so Node.js native modules like cpu-features load without V8.
- [Bun v0.1.9](https://swe.quest/articles/bun-v0-1-9-4ecfe167e5b29929.md): Bun · 2022-08-18 · Medium · 3 min read · Runtimes & VMs, JavaScript, Zig, Performance engineering, Compilers
  Bun v0.1.9 starts using JavaScriptCore's DOMJIT API to JIT-optimize native functions, making \`ptr()\` in \`bun:ffi\` 6-10x faster and \`TextEncoder.encodeInto\` 1.5-5x faster.
- [V8 release v6.9 · V8](https://swe.quest/articles/v8-release-v6-9-v8-d0efd26e2594b2df.md): V8 · 2018-08-07 · Easy · 4 min read · Runtimes & VMs, JavaScript, Memory management, WebAssembly, Compilers
  V8 v6.9 embeds built-in functions directly into the binary on x64, so all Isolates share one copy instead of each holding up to 700 KB on its own heap.
- [Bun v1.2.17](https://swe.quest/articles/bun-v1-2-17-6bfcdfe2dc03cf80.md): Bun · 2025-06-21 · Medium · 10 min read · JavaScript, Runtimes & VMs, Build systems, Performance engineering
  Bun v1.2.17 adds ahead-of-time bundling for HTML imports in server code, so \`bun build --target=bun\` or \`--compile\` can produce a full-stack build or a single self-contained executable with no runtime bundling.
- [The V8 Sandbox](https://swe.quest/articles/the-v8-sandbox-705346b1934809ad.md): V8 · 2024-04-04 · Hard · 11 min read · Sandboxing & isolation, Runtimes & VMs, Memory safety, Browsers, Vulnerability research
  The V8 Sandbox is a lightweight, in-process software sandbox that isolates the V8 heap so memory corruption from engine bugs cannot spread to the rest of the renderer process.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
