we (web engine): Experimental web browser project to understand the limits of Claude

Fetch API backed by net crate #284

Open pierrelf.com
targeting main
Open opened by and assigned to pierrelf.com
targeting main

Implements issue 3mhyfoli6gc2g — Fetch API backed by net crate.

Changes #

  • New file: crates/js/src/fetch.rs — Fetch API implementation

    • fetch(url, options?) global function returning Promise<Response>
    • Background thread for non-blocking network I/O via we-net HTTP 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.rs

    • run_event_loop and pump_event_loop now drain completed fetches alongside timers
    • collect_roots includes 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
  • Modified: crates/js/Cargo.toml — Added we-net and we-url dependencies

Tests #

7 new tests covering:

  • fetch is a function global
  • fetch() returns a promise object
  • fetch() 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 ", "

This pull request has no versions submitted yet.