Implements issue 3mhyfoli6gc2g — Fetch API backed by net crate.
Changes #
-
New file:
crates/js/src/fetch.rs— Fetch API implementationfetch(url, options?)global function returningPromise<Response>- Background thread for non-blocking network I/O via
we-netHTTP client - Response object with
status,statusText,ok,url,headers,text(),json() - Headers object with
get(),has(),set(),delete()(case-insensitive) - Thread-local pending fetch state with GC root tracking
- Event loop integration: completed fetches resolve/reject promises between ticks
-
Modified:
crates/js/src/vm.rsrun_event_loopandpump_event_loopnow drain completed fetches alongside timerscollect_rootsincludes pending fetch promise GC roots- New
drain_completed_fetches()method
-
Modified:
crates/js/src/builtins.rs- Exposed
json_parse_pub()for Response.json() to reuse JSON parsing - Added
init_promise_proto_for_test()for standalone test setup
- Exposed
-
Modified:
crates/js/Cargo.toml— Addedwe-netandwe-urldependencies
Tests #
7 new tests covering:
fetchis a function globalfetch()returns a promise objectfetch()with no args throws TypeError- Network error (connection refused) rejects the promise
- Response object has correct properties (status, ok, statusText, url)
- Headers case-insensitive storage and lookup
- Duplicate header combining with ", "