name property for built-in functions??

Brendan Eich brendan at mozilla.com
Thu Mar 5 23:18:02 PST 2009


On Mar 5, 2009, at 9:26 PM, Allen Wirfs-Brock wrote:

>> In their code generation scheme, do they ever require the generated
>> function to have a particular non-global scope, or will global  
>> scope do?
>
> Are you really talking about "scopes" in the formal language sense  
> here?

Yes -- does Objective-J generate lambdas in other functions which  
refer to lexically scoped variables in enclosing functions. At least  
one Ajax library I know of (EXT) does this using eval.


>  Or are you asking whether or not there is a requirement for the  
> values of all the name property to be globally different from each  
> other.

No.


> For the latter, if the debugger API provides function identity  
> information that is distinct from the name then I would expect that  
> name uniqueness would not be required.

Agree, but let's hear from the Obj-J folks.


>> If global only, then the Function constructor could make an instance
>> with mutable name, maybe. Not easy to spec given that in every other
>> respect the object returned by new Function is a function object, if
>> we want the spec to keep name immutable for declared and expressed
>> functions with names.
>
> The spec'ing should be straight forward.  All function construction  
> funnels through the algorithm in 13.2 which already is defined to  
> take a "Name" argument that is currently used to specify the value  
> used to initialize the name property.  It would be easy to extend  
> the algorithm so that undefined means to not create the property, or  
> to create is with a writable name property that is initialized to  
> "anonymous" or whatever.

I'm warmer than ever to this idea ;-).


> Pulling in the list from an earlier message, here is the set of  
> cases that I believe we need to fill in with the value of the name  
> property (if it has one) and whether or not it is writable:
>
>   Defined by                        currently spec'ed name
> FunctionDeclaration                 the identifier from the  
> declaration
> FunctionExpression with name        the identifier from the function  
> expression
> FunctionExpresion w/o name          the empty string

Or no name property at all, in the proposal we're talking about here.


> Object literal get/set              "get <property name>" or "set  
> <property name>"
> Bound function                      "bind <target function name>" or  
> " bind anonymous function"

With _ not space, right?


>
> (new Function)                       "new Function"*

I thought we stuck at "" for this one.


> Built-in                            specified name
>
> Finally, if we have such a (writable) name property is the  
> implication that toString should be required to use it in its  
> generated representation?

The anonymous function expression carries no intrinsic name, so can't  
name itself when decompiled without extra spec machinery.

A function object (remember joined function objects in ES3?) created  
from the compiler-created immutable-shared function may or may not  
have a name property in the proposal, but calling toString on a  
function object created (to form a closure) should not, in my opinion,  
get the value of the "name" property of that particular (or any other)  
closure object.

Setting the name of the compiler-created function by assigning a  
property to one of N (N>=1) unjoined function objects could be done.  
No more "immutable" but the "shared" still applies. I do not favor  
this, but it could be done. I suspect the Obj-J folks want it.

/be


More information about the Es-discuss mailing list