Open domenic opened 7 years ago
@domenic sorry for the delay here; can you elaborate on exactly how (and which) some browsers use this property?
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.
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
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
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.