[FR] Javascript Interpreter - add means of retrieving the name of a function

javascript

#1

ECMAScript 2015 describes associating a name property to function objects, accessible via the dot operator. This would be very useful for debugging purposes.

Every built-in Function object, including constructors, that is not identified as an anonymous function has a name property whose value is a String. Unless otherwise specified, this value is the name that is given to the function in this specification. For functions that are specified as properties of objects, the name value is the property name string used to access the function. Functions that are specified as get or set accessor functions of built-in properties have "get " or "set " prepended to the property name string. The value of the name property is explicitly specified for each built-in functions whose property key is a Symbol value.

Mozilla has an example of this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name

I tried having a go at it and it’s easily achievable to store the names of local functions - simply need to store the function name in the FunctionObject as it’s being created.

Sadly, it gets really hairy when trying to look up globally set function names that are built-in/registered to the RootObject: none of them are stored as FunctionObject themselves. Same applies to the functions stored in the pre-registered global object classes.