Skip to content

feat(jsruntime): Response/Request/Headers Web Fetch API globals in V8 fallback#1016

Merged
proggeramlug merged 1 commit into
mainfrom
feat-v8-response-request-headers
May 18, 2026
Merged

feat(jsruntime): Response/Request/Headers Web Fetch API globals in V8 fallback#1016
proggeramlug merged 1 commit into
mainfrom
feat-v8-response-request-headers

Conversation

@proggeramlug
Copy link
Copy Markdown
Contributor

Summary

  • Hoists Headers polyfill out of the if (typeof fetch === 'undefined') guard so it is created unconditionally — deno_core has its own fetch but does not expose Headers, leaving hono's new Headers() calls in context.js to throw ReferenceError.
  • Adds Response and Request polyfills implementing the minimal Web Fetch API surface (status/statusText/headers/ok/body, text()/json()/arrayBuffer()/clone(), static Response.error/redirect/json, full Request shape fields). Headers gains append(), copy-construction, generator-style iteration, and Symbol.toStringTag.
  • Rewires the existing fetch() polyfill to return a real Response instance instead of an ad-hoc object literal, and to accept a passed-in Request as input.

Test plan

  • cargo build --release -p perry-runtime -p perry-stdlib -p perry-jsruntime -p perry
  • test-files/test_v8_response_request.ts (native path through perry-stdlib::fetch) prints 200 / hello / http://example.com/ / POST / text/plain
  • /tmp/perry-compat-sweep/hono/entry.ts rebuilt with --enable-js-runtime: previously threw ReferenceError: Response is not defined, now completes app.fetch(new Request(...)) round-trip and prints body=pong matching expected.txt

… fallback

The next hono blocker after the SIGSEGV fix (v0.5.1005) was
`ReferenceError: Response is not defined` thrown from
`node_modules/hono/dist/context.js`. deno_core does not expose
Response/Request as globals, and the existing Headers polyfill was
nested inside an `if (typeof fetch === 'undefined')` branch that was
skipped on V8 builds (which already have their own fetch).

Hoists Headers out of the fetch guard (now unconditional) and adds
polyfills for Response and Request implementing the minimal Web Fetch
API surface hono needs: status/statusText/headers/ok, text()/json()/
arrayBuffer(), clone(), Response.error()/redirect()/json() statics,
Request shape fields, generator-style Headers iteration.

Hono /tmp/perry-compat-sweep/hono now completes the full round-trip
(app.fetch(req) -> res.text() -> 'pong') matching expected.txt.
@proggeramlug proggeramlug merged commit cef1b8c into main May 18, 2026
4 of 9 checks passed
@proggeramlug proggeramlug deleted the feat-v8-response-request-headers branch May 18, 2026 10:40
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