feat(jsruntime): Response/Request/Headers Web Fetch API globals in V8 fallback#1016
Merged
Merged
Conversation
… 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.
This was referenced May 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Headerspolyfill out of theif (typeof fetch === 'undefined')guard so it is created unconditionally — deno_core has its ownfetchbut does not exposeHeaders, leaving hono'snew Headers()calls incontext.jsto throwReferenceError.ResponseandRequestpolyfills implementing the minimal Web Fetch API surface (status/statusText/headers/ok/body,text()/json()/arrayBuffer()/clone(), staticResponse.error/redirect/json, fullRequestshape fields).Headersgainsappend(), copy-construction, generator-style iteration, andSymbol.toStringTag.fetch()polyfill to return a realResponseinstance instead of an ad-hoc object literal, and to accept a passed-inRequestasinput.Test plan
cargo build --release -p perry-runtime -p perry-stdlib -p perry-jsruntime -p perrytest-files/test_v8_response_request.ts(native path throughperry-stdlib::fetch) prints200 / hello / http://example.com/ / POST / text/plain/tmp/perry-compat-sweep/hono/entry.tsrebuilt with--enable-js-runtime: previously threwReferenceError: Response is not defined, now completesapp.fetch(new Request(...))round-trip and printsbody=pongmatchingexpected.txt