Skip to content

Commit

Permalink
Remove useless check for getCallSites util.
Browse files Browse the repository at this point in the history
  • Loading branch information
withmask committed Jul 20, 2022
1 parent f39aee8 commit fba5913
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/CallSitesHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,12 @@ Object.defineProperty(Error, "prepareStackTrace", {
});

export function getCallSites(err: Error): NodeJS.CallSite[] {
return (err.stack ? err[callsitesSym] : err[callsitesSym]) || [];
//V8 does not initiate the "stack" property when the Error is constructed.
//However it seems that the "stack" property is a getter that then calls Error.prepareStackTrace.
//So to ensure that the custom "prepareStackTrace" function is executed we must first read the value of "Error.stack" to trigger the getter

// eslint-disable-next-line no-unused-expressions
err.stack;

return err[callsitesSym] || [];
}

0 comments on commit fba5913

Please sign in to comment.