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

Current interop issue: some browsers use displayName property #14

Open domenic opened 7 years ago

domenic commented 7 years ago

They should only be using name these days, but some still keep it around. Would be good to standardize on this being disallowed and write tests as such.

ljharb commented 5 years ago

@domenic sorry for the delay here; can you elaborate on exactly how (and which) some browsers use this property?

domenic commented 5 years ago

Some browsers use the displayName property of a function, instead of using the function's name property, in stack traces.

As for exactly which, I have the time to raise a known issue for the proposal champions, but not to do the research required to drive the proposal, since I am not a champion myself.

ljharb commented 5 years ago

Thanks; looks like Safari, at least, shows g with:

function f() { return new Error(); }
f.displayName = 'g';
f().stack;

Chrome and Firefox and IE 11 and Edge do not.

cc @msaboff @kmiller68 @erights

loganfsmyth commented 4 years ago

For Firefox/SpiderMonkey, there's also reason to clearly define expectations here because when there is no "name" for a function, SpiderMonkey currently attempts to provide a useful description of where the anonymous function is declared, for example:

function parent() {
  return (() => {
    return new Error().stack;
  })();
}
parent();

results in

parent/<@debugger eval code:3:12
parent@debugger eval code:4:5
@debugger eval code:6:1

with parent/< representing "an anonymous function defined inside 'parent'". There's also other cases like

function parent() {
  return {
    prop: (() => {
      return new Error().stack;
    })()
  }.prop;
}
parent();

which output

parent/<.prop<@debugger eval code:4:14
parent@debugger eval code:5:7
@debugger eval code:8:1