Files
bun.sh/test/js/node/v8/error-prepare-stack-default-fixture.js
2024-06-05 00:26:03 -07:00

25 lines
775 B
JavaScript
Generated

// @bun
// This tests that Error.prepareStackTrace behaves the same when it is set to undefined as when it was never set.
const orig = Error.prepareStackTrace;
Error.prepareStackTrace = (err, stack) => {
return orig(err, stack);
};
const err = new Error();
Error.captureStackTrace(err);
const stack = err.stack;
Error.prepareStackTrace = undefined;
const err2 = new Error();
Error.captureStackTrace(err2);
const stack2 = err2.stack;
const stackIgnoringLineAndColumn = stack.replaceAll(":10:24", "N");
const stack2IgnoringLineAndColumn = stack2.replaceAll(":15:24", "N");
if (stackIgnoringLineAndColumn !== stack2IgnoringLineAndColumn) {
console.log(stackIgnoringLineAndColumn);
console.log(stack2IgnoringLineAndColumn);
throw new Error("Stacks are different");
}