Bug 142903 - Setter should have a single formal parameter, Getter no parameters
Summary: Setter should have a single formal parameter, Getter no parameters
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Joseph Pecoraro
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2015-03-20 01:23 PDT by Joseph Pecoraro
Modified: 2015-03-24 21:28 PDT (History)
6 users (show)

See Also:


Attachments
[PATCH] Proposed Fix (140.69 KB, patch)
2015-03-20 01:41 PDT, Joseph Pecoraro
ggaren: review+
commit-queue: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph Pecoraro 2015-03-20 01:23:48 PDT
* SUMMARY
Setter should have a single formal parameter. It should not allow no parameters or multiple parameters.

This has actually been the case since ES5. ES6 allows that single parameter to be a binding element (deconstructing parameter):
https://people.mozilla.org/~jorendorff/es6-draft.html#sec-method-definitions

> MethodDefinition[Yield] :
>     set PropertyName ( PropertySetParameterList ) { FunctionBody }
> 
> PropertySetParameterList :
>     FormalParameter
> 
> FormalParameter :
>     BindingElement


* TEST
js> var x = { set foo() {} };

* EXPECTED
SyntaxError

* ACTUAL
No error.

* NOTES
- This would be a breaking change, but I'm not worried since other browsers throw errors:
  - Firefox throws an error: SyntaxError: setter functions must have one argument
  - Chrome throws an error: Uncaught SyntaxError: Unexpected token )
Comment 1 Joseph Pecoraro 2015-03-20 01:26:44 PDT
Oh, at the same time, getters should have no parameters:

> MethodDefinition :
>     get PropertyName ( ) { FunctionBody }
Comment 2 Joseph Pecoraro 2015-03-20 01:41:03 PDT
Created attachment 249096 [details]
[PATCH] Proposed Fix
Comment 3 Radar WebKit Bug Importer 2015-03-20 01:42:11 PDT
<rdar://problem/20236675>
Comment 4 Ryosuke Niwa 2015-03-20 10:30:14 PDT
This looks scary. There could be iOS or Mac specific content that rely on our current behavior. Perhaps we should only do it in the strict mode?
Comment 5 Joseph Pecoraro 2015-03-24 13:57:22 PDT
Still needs review!
Comment 6 Geoffrey Garen 2015-03-24 14:07:53 PDT
Comment on attachment 249096 [details]
[PATCH] Proposed Fix

r=me

Is this what other browsers do?
Comment 7 Joseph Pecoraro 2015-03-24 14:11:58 PDT
> Is this what other browsers do?

Yep!

> * NOTES
> - This would be a breaking change, but I'm not worried since other browsers throw errors:
>   - Firefox throws an error: SyntaxError: setter functions must have one argument
>   - Chrome throws an error: Uncaught SyntaxError: Unexpected token )
Comment 8 WebKit Commit Bot 2015-03-24 14:18:52 PDT
Comment on attachment 249096 [details]
[PATCH] Proposed Fix

Rejecting attachment 249096 [details] from commit-queue.

Failed to run "['/Volumes/Data/EWS/WebKit/Tools/Scripts/webkit-patch', '--status-host=webkit-queues.appspot.com', '--bot-id=webkit-cq-02', 'apply-attachment', '--no-update', '--non-interactive', 249096, '--port=mac']" exit_code: 2 cwd: /Volumes/Data/EWS/WebKit

Last 500 characters of output:
1 with fuzz 3.
patching file Source/JavaScriptCore/parser/Parser.cpp
Hunk #1 FAILED at 1316.
1 out of 1 hunk FAILED -- saving rejects to file Source/JavaScriptCore/parser/Parser.cpp.rej
patching file Source/WebInspectorUI/ChangeLog
Hunk #1 succeeded at 1 with fuzz 3.
patching file Source/WebInspectorUI/UserInterface/Views/GradientSlider.js

Failed to run "[u'/Volumes/Data/EWS/WebKit/Tools/Scripts/svn-apply', '--force', '--reviewer', u'Geoffrey Garen']" exit_code: 1 cwd: /Volumes/Data/EWS/WebKit

Full output: http://webkit-queues.appspot.com/results/4632901421367296
Comment 9 Joseph Pecoraro 2015-03-24 21:28:21 PDT
<http://trac.webkit.org/changeset/181929>