Skip to content

feat(codemode): add the Headers built-in - #49280

Open
rekram1-node wants to merge 3 commits into
v2from
web-headers
Open

rekram1-node wants to merge 3 commits into
v2from
web-headers

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

First of the fetch types (Headers, then Response, then Request), each its own PR. A program object wrapping the host's Headers, the same way URL and URLSearchParams wrap theirs: Bun validates, normalizes, folds case, combines values, and orders iteration; the runtime only converts at the edges.

const h = new Headers({ "Content-Type": "application/json" })
h.append("Accept", "text/html")
for (const [name, value] of h) ...
Object.fromEntries(h)           // { accept: "text/html", "content-type": "application/json" }
program                      host
HeadersObj ───── wraps ────▶ Headers
  new Headers(record | pairs | Map | Headers)
  append delete get getSetCookie has set forEach keys values entries
  for...of, spread, destructuring, yield*   (live, sorted by name)
  String(h) → "[object Headers]"    JSON / result / tool arg → { name: value }
  console.log(h) → Headers(2) {"accept":"…","content-type":"…"}

boundary   Headers ⇄ HeadersObj as copies, both directions
 src/stdlib/
+  headers.ts        118 lines: constructor, methods, host TypeError → program TypeError
   url.ts            readPairs(ctx, init, label) shared with URLSearchParams (was inline)
 src/interpreter/
   objects.ts        HeadersObj, isWrapper
   intrinsics.ts     Headers prototype
   interpreter.ts    iterate / yield* over Headers
   extensions.ts     toHost / fromHost
 src/stdlib/console.ts, value.ts, data.ts, references.ts   printing, coercion, JSON, describe

Left out on purpose: Symbol.iterator (no custom Symbols), iterator objects from keys()/values()/entries() (arrays, as with URLSearchParams).

Tests

  • test/stdlib.test.ts: construction, mutation, iteration everywhere, serialization, every error path.
  • test/extensions.test.ts: Headers cross as copies in both directions.
  • test/web-wpt.test.ts: six fetch/api/headers/*.any.js files adapted near-verbatim over a small testharness.js shim, attributed in the header. Two set-cookie cases dropped because Bun's own Headers sorts set-cookie2 ahead of set-cookie.
check result
packages/codemode bun test 5136 pass / 0 fail (+11)
test262 3858 pass / 426 known gaps (unchanged)
bun run check 35/35

interpreter-support.md updated; Request, Response, Blob listed as open.

README

Second commit. The Values section described an export that no longer exists; it is now an Extension.make section, which the hooks paragraph already referred to without introducing. The "differs from JavaScript" bullet no longer says fetch is unavailable, since a host may add it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant