tc39 / proposal-error-stacks

ECMAScript Proposal, specs, and reference implementation for Error.prototype.stack / System.getStack
https://tc39.github.io/proposal-error-stacks/
MIT License
168 stars 13 forks source link

GetStackString should only add the newline if frameString is non-empty #46

Open erights opened 2 years ago

erights commented 2 years ago

GetStackString contains

  1. Let stackString be the concatenation of errorString, the code unit 0x000A (LINE FEED), and frameString.

This is fine in the normal case where frameString is non-empty. But that's up to the host. For security, a host may well decide to omit all stack frame info, which it is allowed to do under this spec. Since this case has no precedent, we are free to define this case to have pleasant behavior.

"non-empty" is not the right corrective if we leave the current spec text as is, because the empty-ish case would actually have frameString be a space. We could fix that by making "only a space" be a condition around adding this newline, but better would be to refactor the spec that frameString, if non-empty, contained an initial newline.

erights commented 2 years ago

See https://github.com/endojs/endo/pull/1171/files

ljharb commented 2 years ago

It seems like we should trim the frameString, and then check if it's empty, and only concat with the newline if it's non-empty?

erights commented 2 years ago

Sounds good to me