1 Commits
Author SHA1 Message Date
velzieandClaude Opus 5 684e46cfb2 [core] add client.Intercept and the WebIDL type machinery (#102)
* [core] add client.Intercept and the WebIDL type machinery

Groundwork for replacing the RawProxy/RawTrap interceptors with
declarative, IDL-typed ones. No API is migrated here - this lands the
machinery and the differential tests that cover it, so the per-API
rewrites can land in parallel on top.

- `client/webidl.ts`: the IDL type language. Parses signature strings
  into types at compile time, and compiles them into argument
  validators and brand checkers at runtime. `Arguments`, `Returns`,
  `Type` and `Constructor` annotate an interceptor member; unresolved
  or malformed type names surface as a TS error on the annotation.
- `client.Intercept`: takes a class whose members carry those
  annotations, splices it onto the native prototype chain, and wires
  each member through a trampoline so `error.stack` and
  `Function.prototype.toString` keep reporting the native shape.
- `client/nativeerror.ts` + `shared/error.ts`: identify frames from the
  client bundle by a frame taken inside it rather than by file name, so
  stack cleaning holds however the embedder serves the bundle. This is
  what makes `cleanErrors` safe to turn on by default - with it off,
  every intercepted member leaves `scramjet.js` frames in any stack a
  page reads.
- `shared/snapshot.ts`: more pinned natives, all additive.
- `client/shared/origin.ts` + `client/helpers.ts`: the origin model the
  per-API rewrites build on. Replaces `dom/origin.ts` and
  `dom/protocol.ts`.
- `tools/eslint/brand-check-plugin.mjs`: flags interceptor members
  whose IDL annotation and body disagree about brand checking. Wired in
  at "warn" - it will go to "error" once the APIs are migrated.
- `tools/prettier/intercept-hug.mjs`: keeps the class argument of
  `client.Intercept(...)` hugged, so the migrations don't each
  reformat their own file.
- `allowFailedIntercepts` is gone: an interceptor that fails now throws
  rather than silently calling through with unvalidated input.

Three adversarial tests cover the machinery rather than any one API -
`interceptor-nativeness` (the shape of the patches), `webidl-this`
(brand checks and `this` handling) and `interface-object-identity`.

Verified against origin/develop: rspack builds all bundles; tsc goes
43 -> 32 errors over the same file set; the types build goes 7 -> 4
erroring files; eslint goes 276 -> 261 problems. All remaining failures
are pre-existing.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01U6ry3tx3Z9nWXwLTJBRDMk

* clean up comments

* small fixes

* nits

* preverse __proto__

---------
2026-09-24 16:45:15 -04:00