mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-28 06:53:42 +08:00
In Node every Error has an own, non-enumerable `stack` accessor, shared by all errors, that formats the stack on first access. Errors that reached checked-dynamic code read `stack` as undefined: the error encoding carried a stack only when a typed read had already formatted one. Reads on instances of Error subclasses found no class arm for it, and assigning `stack` on a subclass instance, typed or through `any`, did not change what a typed read answered. The encoding now lists `stack` first among its own properties as a non-enumerable accessor. Its getter formats the native error's stack on first access, so the heading is the name and message at that point, and its setter stores a string in the native error, which typed reads share. Any other value replaces the accessor with a data property. Objects that inherit from an error read the error's stack, and a getter called on any other receiver answers undefined. A `stack` read on a checked-dynamic value counts as a stack observation, so such programs capture frames as they do for typed reads. Dynamic reads and writes of `stack` on Error subclass instances use the native stack; non-string values are kept with the instance's own properties.