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

Allen Wirfs-Brock allen at wirfs-brock.com
Fri Sep 18 15:07:53 UTC 2015

Note that making this behavior dynamic means that every assignment operation would have to explicitly check whether or not its RHS dynamically evaluated to a function object, and if so whether the function already had a name property. That's real, measurable runtime cost being added to every assignment.

Realistically, that's just not going to happen.


On Sep 18, 2015, at 1:53 AM, Alexander Jones wrote:

> 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.
> Alex
> On Thursday, September 17, 2015, Axel Rauschmayer <rauschma at icloud.com> wrote:
>> 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
> rauschma.de
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150918/95745efe/attachment.html>

More information about the es-discuss mailing list