Will FP ever have a great Stack Trace story in JS?

Alexander Jones alex at weej.com
Fri Sep 18 08:53:53 UTC 2015

Personally I'm already slightly weirded by the static behaviour - doing
this dynamically would result in cases where a function which is otherwise
anonymous would happen to claim the first name of many that it's assigned
to throughout its lifetime. This would actually be observable at runtime as
`name` changing. Or maybe I'm overlooking something.

Better IMO is if the stack trace would always include the name of the
function *as it was called*, in addition to the function's own `name`,
assuming its presence. That, assuming thoughtfully named variables,
might give a little extra immediate insight into the call stack. Obviously
if the function call had no name, i.e. it was an arbitrary expression, we'd
have to skip this.


On Thursday, September 17, 2015, Axel Rauschmayer <rauschma at icloud.com>

> Not quite, the mechanism which does this in the spec is SetFunctionName (
> http://www.ecma-international.org/ecma-262/6.0/#sec-setfunctionname), and
> it only works for specific syntactic constructs (eg, `foo = function() {}`
> -> anonymous function is named “foo”, let x = () => {} -> anonymous arrow
> is named “x”, etc).
> It does not apply to things like `compose(thingA, thingB)`, which is not
> an anonymous function definition.These function names aren’t set at
> runtime, it’s a parse-time operation, and depends on the productions that
> are parsed.
> Ah, fascinating! That’s something that I overlooked. It is an odd mix of
> static and dynamic, though.
> For example:
> http://www.ecma-international.org/ecma-262/6.0/#sec-assignment-operators-runtime-semantics-evaluation
> My understanding:
> – The actions themselves happen at runtime, not at compile time.
> – (1.e) IsAnonymousFunctionDefinition() is a static check that only holds
> if AssignmentExpression is an anonymous function expression (syntactically).
> – (1.e.i) is a dynamic check, SetFunctionName() happens dynamically, too.
> Wouldn’t it make sense to turn IsAnonymousFunctionDefinition() into a
> dynamic check, too? A check whether _rval_ is a function should suffice
> (given the check whether property `name` exists, later).
> --
> Dr. Axel Rauschmayer
> axel at rauschma.de <javascript:_e(%7B%7D,'cvml','axel at rauschma.de');>
> rauschma.de
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150918/6bd5edeb/attachment.html>

More information about the es-discuss mailing list