When requiring the stack properties value to be eagerly evaluated in captureStackTrace there is a problematic interaction with the existing accompanying prepareStackTrace. That one allows arbitrarily formatting of the stack trace attached to the error object. This makes it observable when the string content of the stack property is computed.
The proposal here would require eager evaluation of the stack formatting code at captureStackTrace time. Whereas the current implementation does it lazily.
Error.prepareStackTrace = (error, stack) => {console.log("2. prepare")};
let err = {};
Error.captureStackTrace(err);
console.log("1. capture");
err.stack;
Here we would essentially have to swap the order of effect 1 and 2.
I think this is not just a theoretical issue. Next to an observable change in behavior it would also make the prepareStackTrace API prohibitively expensive to use.
There is evidence of effectfull and expensive prepareStackTrace handlers, see e.g., source-map-support for node.
When requiring the
stackproperties value to be eagerly evaluated incaptureStackTracethere is a problematic interaction with the existing accompanyingprepareStackTrace. That one allows arbitrarily formatting of the stack trace attached to the error object. This makes it observable when the string content of thestackproperty is computed.The proposal here would require eager evaluation of the stack formatting code at
captureStackTracetime. Whereas the current implementation does it lazily.Here we would essentially have to swap the order of effect 1 and 2.
I think this is not just a theoretical issue. Next to an observable change in behavior it would also make the
prepareStackTraceAPI prohibitively expensive to use.There is evidence of effectfull and expensive
prepareStackTracehandlers, see e.g., source-map-support for node.