Bug 158575 - ES5: Reusing function name as a parameter name shouldn't throw Syntax Error
Summary: ES5: Reusing function name as a parameter name shouldn't throw Syntax Error
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Michael Saboff
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2016-06-09 13:09 PDT by Michael Saboff
Modified: 2016-06-09 20:30 PDT (History)
7 users (show)

See Also:


Attachments
Patch (4.33 KB, patch)
2016-06-09 15:36 PDT, Michael Saboff
benjamin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Saboff 2016-06-09 13:09:03 PDT
According to the ES6 spec, <http://www.ecma-international.org/ecma-262/6.0/#sec-function-definitions-static-semantics-early-errors>, reusing the function name of a function as a parameter name should not throw a Syntax Error.  This is was pointed out on the es-discuss mailing list <https://esdiscuss.org/topic/can-strict-parameters-shadow-strict-function-names>, specifically how we differ from V8 and SpiderMonkey.
Comment 1 Michael Saboff 2016-06-09 15:36:59 PDT
Created attachment 280959 [details]
Patch
Comment 2 Radar WebKit Bug Importer 2016-06-09 15:37:58 PDT
<rdar://problem/26729710>
Comment 3 Saam Barati 2016-06-09 15:39:25 PDT
Comment on attachment 280959 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=280959&action=review

r=me with comments

> Source/JavaScriptCore/parser/Parser.h:483
> +        bool isValidStrictMode = (addResult.isNewEntry || !addResult.iterator->value.isParameter())
> +            && m_vm->propertyNames->eval != *ident && !isArgumentsIdent;

Style: one line

> LayoutTests/js/script-tests/basic-strict-mode.js:89
> +shouldBe("(function a(a){'use strict'; return a+2; })(40)", "42");
> +shouldBe("var foo = function a(a){'use strict'; return a+2; }; foo(40)", "42");

Can you also add tests for method style syntax?
Comment 4 Mark Lam 2016-06-09 15:40:05 PDT
Comment on attachment 280959 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=280959&action=review

> Source/JavaScriptCore/ChangeLog:10
> +        The check for a parameter with a duplicate name doesn't take into account the
> +        type of the prior variable.  Added a check that the duplicate is also a
> +        parameter.

Can you add the URL to the spec as a ref here?
Comment 5 Michael Saboff 2016-06-09 16:03:49 PDT
(In reply to comment #3)
> Comment on attachment 280959 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=280959&action=review
> 
> r=me with comments
> 
> > Source/JavaScriptCore/parser/Parser.h:483
> > +        bool isValidStrictMode = (addResult.isNewEntry || !addResult.iterator->value.isParameter())
> > +            && m_vm->propertyNames->eval != *ident && !isArgumentsIdent;
> 
> Style: one line

Our style guide doesn't talk about whether or not we should break long line.  I believe this is more readable.  The breaking is in line with the style guide.
 
> > LayoutTests/js/script-tests/basic-strict-mode.js:89
> > +shouldBe("(function a(a){'use strict'; return a+2; })(40)", "42");
> > +shouldBe("var foo = function a(a){'use strict'; return a+2; }; foo(40)", "42");
> 
> Can you also add tests for method style syntax?

Done.
Comment 6 Michael Saboff 2016-06-09 16:04:05 PDT
(In reply to comment #4)
> Comment on attachment 280959 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=280959&action=review
> 
> > Source/JavaScriptCore/ChangeLog:10
> > +        The check for a parameter with a duplicate name doesn't take into account the
> > +        type of the prior variable.  Added a check that the duplicate is also a
> > +        parameter.
> 
> Can you add the URL to the spec as a ref here?

Done.
Comment 7 Michael Saboff 2016-06-09 16:29:08 PDT
Committed r201892: <http://trac.webkit.org/changeset/201892>