Skip to content

feat(stdlib,lowering): implement WHATWG IterableIterator and generic Array.from/for..of iterator support - #25

Merged
phamtanminhtien merged 2 commits into
mainfrom
feat/formdata-and-runtime-hardening
Sep 24, 2026
Merged

phamtanminhtien merged 2 commits into
mainfrom
feat/formdata-and-runtime-hardening

Conversation

@phamtanminhtien

Copy link
Copy Markdown
Contributor

Summary

This PR establishes full WHATWG and ECMAScript spec compliance for iterators and collections:

  1. WHATWG IterableIterator Implementation:

    • FormDataIterator<T>, HeadersIterator<T>, and URLSearchParamsIterator<T> implement ECMAScript IterableIterator<T> protocol (.next(): { value: T | undefined; done: boolean } and [Symbol.iterator]()).
    • FormData, Headers, and URLSearchParams methods (keys(), values(), entries(), and [Symbol.iterator]()) return typed iterator instances conforming to WHATWG standards.
    • Updated globals.d.ts interface definitions extending IterableIterator<T>.
  2. Generic for..of & Array.from Iterator Support:

    • Refactored lowerForOf in statements_control.go to dynamically resolve next and Symbol.iterator methods via findMethodInHierarchy.
    • Extended Array.from in builtins_array.go to consume arbitrary iterables/iterators via .next() loop protocol, Set (__set.values), and Map (__map.entries).
    • Dynamically resolves done and value fields by name in shape descriptors instead of hardcoding indices.
  3. Generic Monomorphization & Type System Hardening:

    • Added nested bracket ([]), brace ({}), and paren (()) depth awareness to splitTypeArguments in generics_subst.go.
    • Added object literal type ({ ... }) parsing and substitution to substituteType.
    • Used splitTopLevelUnion instead of blind delimiter splitting for union types.
    • Preserved structured shapes and resolved type aliases during monomorphization.
  4. Verification:

    • Full compiler corpus tests passed (api/formdata.ts, api/headers.ts, api/urlsearchparams.ts, api/fetch.ts, api/request.ts, api/response.ts, etc.).
    • 100% full Node.js v22 parity via cmd/parity.
    • ASAN & UBSAN clean (zero leaks, zero runtime errors).
    • Full repository test suites passed.

@phamtanminhtien
phamtanminhtien force-pushed the feat/formdata-and-runtime-hardening branch from 33b7589 to 860e2e2 Compare September 24, 2026 02:16
@phamtanminhtien
phamtanminhtien merged commit 6a37efb into main Sep 24, 2026
7 checks passed
@phamtanminhtien
phamtanminhtien deleted the feat/formdata-and-runtime-hardening branch September 24, 2026 02:32
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