Closed
Bug 781422
Opened 13 years ago
Closed 13 years ago
parameters should get defaults whenever they are undefined
Categories
(Core :: JavaScript Engine, defect)
Core
JavaScript Engine
Tracking
()
RESOLVED
FIXED
mozilla18
People
(Reporter: dherman, Assigned: Benjamin)
References
(Blocks 1 open bug)
Details
(Keywords: dev-doc-complete, Whiteboard: [js:p2])
Attachments
(2 files)
914.85 KB,
application/octet-stream
|
Details | |
11.59 KB,
patch
|
jorendorff
:
review+
|
Details | Diff | Splinter Review |
Currently the parameter default values implementation uses the arguments length to determine whether a parameter needs a default value. It should instead be based on whether the argument provided was undefined.
Dave
Comment 1•13 years ago
|
||
In short:
function f(x=3) { return x; }
assertEq(f(undefined), 3); // currently FAILS, f(undefined) === undefined.
In detail:
function f(x=EXPR) { BODY }
will expand to:
function f(x) {
if (x === undefined)
x = EXPR;
BODY
}
This will invalidate a bunch of our existing tests for default parameters. The tests are wrong (i.e. they are testing for what we *thought* the semantics were going to be).
Comment 2•13 years ago
|
||
I haven't yet released a spec. draft with the parameter and destructuring default changes. However, the attached interim draft does have the changes. Use this as the spec. until a release the next official draft sometime in Sept. 2012
Assignee | ||
Updated•13 years ago
|
OS: Mac OS X → All
Hardware: x86 → All
Assignee | ||
Comment 3•13 years ago
|
||
This certainly simplifies the implementation.
I didn't update the decompiler except to delete some lines to make it compile. I'm not sure what you want me to do with it otherwise.
Assignee: general → benjamin
Attachment #659443 -
Flags: review?(jorendorff)
Updated•13 years ago
|
Whiteboard: [js:p2]
Comment 4•13 years ago
|
||
Comment on attachment 659443 [details] [diff] [review]
use defaults when formals are undefined
Review of attachment 659443 [details] [diff] [review]:
-----------------------------------------------------------------
Great.
Attachment #659443 -
Flags: review?(jorendorff) → review+
Comment 5•13 years ago
|
||
That Word document caused Preview to peg the CPU, and Google Docs couldn't render it either, so basically I don't have a good way to view it right now. I'll wait for the September draft.
Assignee | ||
Comment 6•13 years ago
|
||
Assignee | ||
Updated•13 years ago
|
Keywords: dev-doc-needed
Comment 7•13 years ago
|
||
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla18
Comment 8•13 years ago
|
||
I updated https://developer.mozilla.org/en-US/docs/JavaScript/Reference/default_parameters
Tell me if you expect other changes to be documented.
Keywords: dev-doc-needed → dev-doc-complete
Assignee | ||
Comment 9•13 years ago
|
||
I suppose bug 757676 can be dev-doc-complete, too then.,
You need to log in
before you can comment on or make changes to this bug.
Description
•