mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-12 02:13:04 +08:00
Checking or converting a dyn value whose objects or arrays refer back to each other against a recursive interface (`raw.next = raw; raw as Node`) recursed without end and overflowed the stack. Matchers and builders of record and array types that reach themselves now track the dyn values they visit: - a matcher answers true for a (value, type) pair it is already checking further up the stack, so the outer check decides; - a builder records the record or array it allocated for a dyn value before converting its members, and a later visit of the same value in the conversion answers it, so `n.next === n` holds after the cast and a value reached twice converts once. Only values with more than one reference are tracked, since a value reached twice has at least two; the reference a member read holds is not counted. Capsules materialized during a conversion keep their first view, so a nested visit cannot refresh a view an outer visit is reading, and getters and proxy traps that a member read calls run outside the visit. The cycle analysis treats record shapes that reach themselves and are targets of a dynCheck as mutable, so the cyclic records a conversion builds are collected.