archives

« Bugzilla Issues Index

#4312 — Function.prototype.toString language mysteriously weakened.


From https://mail.mozilla.org/pipermail/es-discuss/2015-April/042525.html

Where the strawman http://wiki.ecmascript.org/doku.php?id=harmony:function_to_string says:

> if eval()uated in an equivalent-enough lexical context, would result in a function
> with the same [[Call]] behavior as the present one. Note that the new function would
> have a fresh identity and none of the original’s properties, not even .prototype.
> (The properties could of course be transferred by other means but the identity will
> remain distinct.)

the spec text at https://people.mozilla.org/~jorendorff/es6-draft.html#sec-function.prototype.tostring says only

> if the string is evaluated, using eval in a lexical context that is equivalent to
> the lexical context used to create the original object, it will result in a new
> functionally equivalent object.

This "functionally equivalent" is bizarrely vaguer than "same [[Call]] behavior" and, if taken literally, is clearly wrong. As the strawman (but not the spec) says clearly, evaling the returned string is not expected to replicate the properties of the original function object. And of course it cannot replicate the original function's identity.

Allen, is this a spec bug, or was this weakening intentional? If so, why?

I'm sure it's too late for ES6 anyway, so feel free to move to ES7 of course.


(In reply to Mark Miller from comment #0)
...
>
> This "functionally equivalent" is bizarrely vaguer than "same [[Call]]
> behavior" and, if taken literally, is clearly wrong

"same [[Call]] behavior" if taken literally in the context of the ES6 spec. is also wrong. In the ES6 spec, that phraae literally means has the same implementation of the [[Call]] internal method. But, this is always the case for ECMAScript language functions. Also, note that the standard [[Call]] internal method simply delegates to the evaluation of the function body. It does not say anything about the actual behavior of the body.

Clearly, your intended to say that (given the appropriate lexical environment) there would be no observable difference in calling the new eval generated function in place of the original function. "functionally equivalent" seems like a plausible statement of that requirement. But you might be able to come up with something better, but any description consisting of a handful of words is going to be vague.


Good point. So perhaps "observably equivalent [[Call]] behavior" or something?

I would like to see language that clearly includes [[Call]] but excludes other properties, internal methods, and identity.


(In reply to Mark Miller from comment #2)

I don't think you are going to find a four or five word sentence that can precisely express you requirements. I think you are going to either have to significantly expand your list of requirements or be content with vagueness.


deferring to ES7