Closed Bug 781422 Opened 13 years ago Closed 13 years ago

parameters should get defaults whenever they are undefined

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

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)

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
Blocks: es6
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).
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
OS: Mac OS X → All
Hardware: x86 → All
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)
Whiteboard: [js:p2]
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+
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.
Keywords: dev-doc-needed
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla18
I updated https://developer.mozilla.org/en-US/docs/JavaScript/Reference/default_parameters Tell me if you expect other changes to be documented.
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.

Attachment

General

Created:
Updated:
Size: