Commit Graph
4 Commits
Author SHA1 Message Date
Chris Tate a897079be1 Capture onto the target evaluated before a constructorOpt that reassigns it
When Error.captureStackTrace evaluates a JavaScript constructorOpt (a getter,
a call, or this.constructor with a constructor getter), V8 has already
evaluated the target. The lowering kept the target in a local only when its
expression was not a plain read, so a constructorOpt that assigned the target
variable made the capture install the stack on the new value. The target is
now always kept in a local before the constructorOpt runs.
2026-10-27 13:00:48 -05:00
Chris Tate 6c63d8cd10 Run a constructor getter that this.constructor reads in Error.captureStackTrace
Inside a class constructor, Error.captureStackTrace(this, this.constructor) now reads this.constructor before the capture when the class or a base class declares a constructor getter, as V8 evaluates the argument: the getter runs and its exception propagates.
2026-10-26 21:39:37 -05:00
Chris Tate 3121f6909d Evaluate a JavaScript constructorOpt, and keep a non-extensible error's stack
- Error.captureStackTrace in JavaScript discarded a constructorOpt it
  does not recognize (a getter, a call), so its side effects and
  exceptions did not happen. It now evaluates after the target and
  before the capture, as V8 evaluates the call's arguments; the target is
  held in a local when evaluating it twice would not be safe.
- Capturing on an error replaced its saved stack without the checks V8
  makes when it defines `stack`. A frozen, sealed or non-extensible error
  now throws "Cannot define property stack, object is not extensible",
  and one whose `stack` is non-configurable throws "Cannot redefine
  property: stack"; both keep their stack.

Corpus 6874 checks the evaluation order and a constructorOpt that
throws.
2026-10-24 18:43:07 -05:00
Chris Tate c2ec0b989d Capture stack traces with Error.captureStackTrace as Node does 2026-10-22 06:52:18 -05:00