parameters should get defaults whenever they are undefined

RESOLVED FIXED in mozilla18

Status

()

Core
JavaScript Engine
RESOLVED FIXED
5 years ago
5 years ago

People

(Reporter: dherman, Assigned: Benjamin)

Tracking

(Blocks: 1 bug, {dev-doc-complete})

unspecified
mozilla18
dev-doc-complete
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [js:p2])

Attachments

(2 attachments)

(Reporter)

Description

5 years ago
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
(Reporter)

Updated

5 years ago
Blocks: 694100
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

5 years ago
Created attachment 657283 [details]
interim ES6 draft, with desstructuring updates (zipped doc)

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

5 years ago
OS: Mac OS X → All
Hardware: x86 → All
(Assignee)

Comment 3

5 years ago
Created attachment 659443 [details] [diff] [review]
use defaults when formals are undefined

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.
(Assignee)

Comment 6

5 years ago
https://hg.mozilla.org/integration/mozilla-inbound/rev/e9bd85f336b9
(Assignee)

Updated

5 years ago
Keywords: dev-doc-needed

Comment 7

5 years ago
https://hg.mozilla.org/mozilla-central/rev/e9bd85f336b9
Status: NEW → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla18

Comment 8

5 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

5 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.