You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Should the stack getter on a non-Error return undefined or an empty string? #3
Your analysis is correct. Is there code on the web that relies on this working? It's very uncommon in the language to have accessors that don't brand check.
What is the appetite for shipping with the check with a pre-agreement to remove it if there's web compat issues?
Meaning, we could easily have two specs - main, plus a PR that removes the checks - and in theory a flag could guard the two variants that could be flipped post-deploy?
So, the only remaining question here is, is it web compatible to return undefined vs an empty string?
Since both are falsy, the only issue would be if something unconditionally called a string method on a .stack from a non-Error that still somehow had the Error.prototype stack getter.
changed the title [-]What about errors on the prototype chain? [/-][+]Should the stack getter on a non-Error return undefined or an empty string?[/+]on Nov 9, 2025
Now that the setter throws on non-strings (per today's plenary), I'm planning to stick with returning undefined. Please let me know if there's telemetry or evidence compelling a different path.
Activity
ljharb commentedon Jan 9, 2025
Your analysis is correct. Is there code on the web that relies on this working? It's very uncommon in the language to have accessors that don't brand check.
mgaudet commentedon Jan 9, 2025
No idea. We don't have telemetry here to tell us.
ljharb commentedon Jan 9, 2025
What is the appetite for shipping with the check with a pre-agreement to remove it if there's web compat issues?
Meaning, we could easily have two specs -
main, plus a PR that removes the checks - and in theory a flag could guard the two variants that could be flipped post-deploy?mgaudet commentedon Jan 9, 2025
My appetite is fairly low; I wouldn't be opposed to trying to get some telemetry but not sure when I can slot that in.
nicolo-ribaudo commentedon Jan 10, 2025
Note that the current spec text returns undefined, rather than throwing.
ljharb commentedon Jan 10, 2025
Indeed, closing makes sense, I believe.
nicolo-ribaudo commentedon Jan 10, 2025
Well, it still behaves differently from Firefox and Chrome where
o.stackreturns a string and not undefined :)(I have no opinion on what we should do, I'd go with the current behavior if it's web-compatible)
mgaudet commentedon Jan 10, 2025
I'd leave this open until we had any idea at all what is web compatible.
ljharb commentedon Jan 10, 2025
Sounds good
mgaudet commentedon Jan 10, 2025
(It does appear that Chrome also works this way)
ljharb commentedon Nov 7, 2025
@mgaudet which way does Chrome work? Returns undefined, or returns a string?
mgaudet commentedon Nov 7, 2025
Returns a string.
ljharb commentedon Nov 9, 2025
So, the only remaining question here is, is it web compatible to return undefined vs an empty string?
Since both are falsy, the only issue would be if something unconditionally called a string method on a .stack from a non-Error that still somehow had the Error.prototype stack getter.
I suspect this is exceedingly unlikely.
[-]What about errors on the prototype chain? [/-][+]Should the stack getter on a non-Error return undefined or an empty string?[/+]mhofman commentedon Nov 9, 2025
It's a little more complicated. The value could simply be serialized and sent. In the case of JSON it'd mean the property would disappear.
I think this constraint means it's very unlikely, but it would be great to get some telemetry on this however.
ljharb commentedon Nov 18, 2025
Now that the setter throws on non-strings (per today's plenary), I'm planning to stick with returning
undefined. Please let me know if there's telemetry or evidence compelling a different path.