`new Function()` args should be parsed as `FormalParameters`, supporting destructuring and defaults

RESOLVED DUPLICATE of bug 755821

Status

()

defect
RESOLVED DUPLICATE of bug 755821
5 years ago
4 years ago

People

(Reporter: Swatinem, Unassigned)

Tracking

(Blocks 1 bug)

Firefox Tracking Flags

(Not tracked)

Details

Reporter

Description

5 years ago
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;
})
```
Related to bug 755821
Status: NEW → RESOLVED
Closed: 4 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 755821
You need to log in before you can comment on or make changes to this bug.