Closed
Bug 1037939
Opened 10 years ago
Closed 9 years ago
`new Function()` args should be parsed as `FormalParameters`, supporting destructuring and defaults
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
RESOLVED
DUPLICATE
of bug 755821
People
(Reporter: Swatinem, Unassigned)
References
(Blocks 1 open bug)
Details
ES6 says:
> 19.2.1.1 Function ( p1, p2, … , pn, body )
> …
> Let P be the result of concatenating the previous value of P, the String "," (a comma), and nextArgString.
> …
> Let parameters be the result of parsing P, interpreted as UTF-16 encoded Unicode text as described in 10.1.1, using FormalParameters as the goal symbol. Throw a SyntaxError exception if the parse fails.
`FormalParameters` boils down to `BindingElement`.
This means that things like `new Function('{a,b}', 'return;')` should work. They currently dont:
```
js> new Function('a = 10','return;')
typein:33:0 SyntaxError: malformed formal parameter
js> new Function('{a,b}','return;')
typein:34:0 SyntaxError: malformed formal parameter
js> new Function('[a,b]','return;')
typein:35:0 SyntaxError: malformed formal parameter
```
(however, they already support rest and multiple params)
```
js> new Function('a,b','return;')
(function anonymous(a, b) {
return;
})
js> new Function('...rest','return;')
(function anonymous(...rest) {
return;
})
```
Comment 1•10 years ago
|
||
Related to bug 755821
Updated•9 years ago
|
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → DUPLICATE
You need to log in
before you can comment on or make changes to this bug.
Description
•