Closed
Bug 1132320
Opened 11 years ago
Closed 11 years ago
Function.name should return empty string for anonymous functions
Categories
(Core :: JavaScript Engine, defect)
Core
JavaScript Engine
Tracking
()
RESOLVED
INVALID
People
(Reporter: fn84b, Unassigned)
References
(Blocks 1 open bug)
Details
User Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729; InfoPath.3; rv:11.0) like Gecko
Expected results:
According to ES6 draft section 19.2.3 and 19.2.4.2, "the value of the name property of the Function prototype object is the empty String" and "anonymous functions objects that do not have a contextual name associated with them by this specification do not have a name own property but inherit the name property of %FunctionPrototype%".
However, the current implementation returns the string "anonymous".
Do you mean this?
js> (new Function).name
"anonymous"
Could you give some examples?
![]() |
||
Comment 2•11 years ago
|
||
> However, the current implementation returns the string "anonymous".
(function(){}).name returns "".
But yes, (new Function).name returns "anonymous".
Per spec, new Function calls http://people.mozilla.org/~jorendorff/es6-draft.html#sec-function-p1-p2-pn-body which calls http://people.mozilla.org/~jorendorff/es6-draft.html#sec-createdynamicfunction which in step 28 does:
28. Perform SetFunctionName(F, "anonymous").
so we seem to be following the spec here.
If you're seeing a case in which we return "anonymous" but the spec doesn't say to do that, can you please attach a testcase showing that case?
Flags: needinfo?(fn84b)
You're right. I did mean that (new Function).name returns "anonymous", which is correct. Sorry I didn't read the spec carefully.
So it's actually a bug of Chrome, which returns empty strings for both (function(){}).name and (new Function).name.
Thank you for your quick replies!
Status: UNCONFIRMED → RESOLVED
Closed: 11 years ago
Flags: needinfo?(fn84b)
Resolution: --- → INVALID
But note that the name property of anonymous functions should be an inherit property:
(function(){}).hasOwnProperty("name") // false
(() => {}).hasOwnProperty("name") // false
(a = () => {}).hasOwnProperty("name") // true, this is not an anonymous function
(a = (1, () => {})).hasOwnProperty("name") // false
Maybe bug 883377 will fix this.
You need to log in
before you can comment on or make changes to this bug.
Description
•