eval string to function throw exception "function statement requires a name"

RESOLVED INVALID

Status

()

Core
JavaScript Engine
--
major
RESOLVED INVALID
6 years ago
2 years ago

People

(Reporter: Aquila, Unassigned)

Tracking

7 Branch
x86_64
Windows 7
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

6 years ago
User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1
Build ID: 20110928134238

Steps to reproduce:

eval a string to a function:
var func1=eval("function(){alert('Hello World');}");
var func2=eval("function(text){alert(text);}");


Actual results:

The eval function throw the following exception:
"function statement requires a name"


Expected results:

The eval function should return a function.
(Reporter)

Comment 1

6 years ago
This bug prevent me to upgrade to FF 7 because some user scripts and an intranet uses this method. This is working is FF 6, so please fix this bug.
(Reporter)

Updated

6 years ago
Severity: normal → major

Comment 2

5 years ago
Aquila, can you still reproduce when using a current version?
Flags: needinfo?(aquilax)
(Reporter)

Updated

4 years ago
Flags: needinfo?(aquilax)

Comment 3

2 years ago
I see it in Fx44b8. I see throw an error in Chrome 47 & IE11. It may be an illegal statement for JavaScript standard.
Component: General → JavaScript Engine
Product: Firefox → Core
(In reply to YF (Yang) from comment #3)
> It may be an illegal statement for JavaScript standard.

It is, yes. function(){alert('Hello World');} isn't valid, and trying to run it in an eval call doesn't change that.

I'm guessing that content that used to rely on this working has long gone, so we should be able to safely close this.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 2 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.