Can strict parameters shadow strict function names?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Can strict parameters shadow strict function names?

Mark S. Miller-2
var foo = function bar(bar) {'use strict'};

On all version of Safari/JSC I just tested, this code gives a SyntaxError: Invalid parameters or function name in strict mode.

On all versions of Chrome/v8 and FF/SpiderMonkey I just tested, this code is accepted without error.

Which behavior is incorrect? Is this an ES5 vs ES2015 issue? Are there currently any existing bug reports about this? Any test262 tests?

We are running into this when loading the output of a minifier as strict code.

--
    Cheers,
    --MarkM

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Can strict parameters shadow strict function names?

Bergi
Mark S. Miller wrote:
> var foo = function bar(bar) {'use strict'};
>
> On all version of Safari/JSC I just tested, this code gives a
> SyntaxError: Invalid parameters or function name in strict mode.
>
> On all versions of Chrome/v8 and FF/SpiderMonkey I just tested, this code
> is accepted without error.
>
> Which behavior is incorrect?

This appears to be a bug in Safari/JSC.

> Is this an ES5 vs ES2015 issue?

No, both ES5 <http://es5.github.io/#x13.1> and ES6
<http://www.ecma-international.org/ecma-262/6.0/#sec-function-definitions-static-semantics-early-errors>
only have a syntax error if there are duplicate *parameter* names,
regardless of the name of the function.

> We are running into this when loading the output of a minifier as strict
> code.

Guess you should file a bug there - it a) doesn't make sense to name a
function expression (does it ever in minified code) and use the same
name for a parameter b) it should not fail in real-world engines even if
the spec says something else.

Regards,
  Bergi
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Can strict parameters shadow strict function names?

Andreas Rossberg-4
On 9 June 2016 at 19:58, Bergi <[hidden email]> wrote:
Mark S. Miller wrote:
var foo = function bar(bar) {'use strict'};

On all version of Safari/JSC I just tested, this code gives a
SyntaxError: Invalid parameters or function name in strict mode.

On all versions of Chrome/v8 and FF/SpiderMonkey I just tested, this code
is accepted without error.

Which behavior is incorrect?

This appears to be a bug in Safari/JSC.

Is this an ES5 vs ES2015 issue?

No, both ES5 <http://es5.github.io/#x13.1> and ES6 <http://www.ecma-international.org/ecma-262/6.0/#sec-function-definitions-static-semantics-early-errors> only have a syntax error if there are duplicate *parameter* names, regardless of the name of the function.

In particular, the function name is in its own singleton scope outside the parameter scope. My guess is that this semantics was chosen so that collision doesn't differ between function declarations and expressions.

/Andreas


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Can strict parameters shadow strict function names?

Allen Wirfs-Brock
In reply to this post by Mark S. Miller-2
Yes, they can.  The JSC behavior is incorrect.

The possibility of shadowing function expression names by parameters (or other local declarations) exists as far back as ES3.  When strict mode was added in ES5 we didn’t include any restrictions on that shadowing (I don’t recall even considering it). Adding such a restriction in ES2015 (or now) would have been a breaking change.

Allen


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Can strict parameters shadow strict function names?

Michael Saboff
I filed <https://bugs.webkit.org/show_bug.cgi?id=158575> “ES6: Reusing function name as a parameter name shouldn't throw Syntax Error”.

- Michael

On Jun 9, 2016, at 11:28 AM, Allen Wirfs-Brock <[hidden email]> wrote:

Yes, they can.  The JSC behavior is incorrect.

The possibility of shadowing function expression names by parameters (or other local declarations) exists as far back as ES3.  When strict mode was added in ES5 we didn’t include any restrictions on that shadowing (I don’t recall even considering it). Adding such a restriction in ES2015 (or now) would have been a breaking change.

Allen


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss