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

`ToString` or `Error.prototype.toString` #47

Closed mhofman closed 1 year ago

mhofman commented 1 year ago

Step 2 of GetStackString currently uses ToString to get the prelude of the stack.

However it seems the implementations that currently include the error description in the stack string currently defer to Error.prototype.toString and ignore any custom toString override, which the ToString steps would trigger.

It would likely be closer to reality to use Error.prototype.toString instead.

Test case

// First line
const err = Error('my message');
err.name = 'CustomError';
err.toString = () => 'overriden';

print(err.stack);

Result

#### JavaScriptCore
global code@/tmp/dxsvy0KPDOBv4jrOpdgh/f-1696257339837-28118-1yi6mn0.k8kil.js:2:2209

#### Moddable XS
CustomError: my message
 at (/tmp/dMm7rKXjWXf5K5xEdYnV/f-1696257339789-28118-i6w9sl.3wpxp.js:16)

#### SpiderMonkey
@/tmp/pCYM45AKy8tqTPAUQyR2/f-1696257339847-28118-121pjez.xowej.js:2:8082

#### V8
CustomError: my message
    at /tmp/cE6Ctkgb01qscSWukwO2/f-1696257339814-28118-1dh041b.2iyq.js:2:5903
ljharb commented 1 year ago

That's an interesting difference to note, thanks. I'll update the spec to reflect that at some point.