Last Comment Bug 781422 - parameters should get defaults whenever they are undefined
: parameters should get defaults whenever they are undefined
: dev-doc-complete
Product: Core
Classification: Components
Component: JavaScript Engine (show other bugs)
: unspecified
: All All
: -- normal (vote)
: mozilla18
Assigned To: :Benjamin Peterson
: Jason Orendorff [:jorendorff]
Depends on:
Blocks: es6
  Show dependency treegraph
Reported: 2012-08-08 21:54 PDT by Dave Herman [:dherman]
Modified: 2012-10-10 10:02 PDT (History)
6 users (show)
See Also:
Crash Signature:
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---

interim ES6 draft, with desstructuring updates (zipped doc) (914.85 KB, application/octet-stream)
2012-08-31 08:02 PDT, Allen Wirfs-Brock
no flags Details
use defaults when formals are undefined (11.59 KB, patch)
2012-09-07 21:46 PDT, :Benjamin Peterson
jorendorff: review+
Details | Diff | Splinter Review

Description Dave Herman [:dherman] 2012-08-08 21:54:56 PDT
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.

Comment 1 Jason Orendorff [:jorendorff] 2012-08-29 07:38:56 PDT
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;

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 Allen Wirfs-Brock 2012-08-31 08:02:47 PDT
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
Comment 3 :Benjamin Peterson 2012-09-07 21:46:51 PDT
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.
Comment 4 Jason Orendorff [:jorendorff] 2012-09-12 15:04:25 PDT
Comment on attachment 659443 [details] [diff] [review]
use defaults when formals are undefined

Review of attachment 659443 [details] [diff] [review]:

Comment 5 Jason Orendorff [:jorendorff] 2012-09-12 15:06:23 PDT
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.
Comment 7 Ed Morley [:emorley] 2012-09-13 13:08:59 PDT
Comment 8 David Bruant 2012-10-10 06:40:50 PDT
I updated
Tell me if you expect other changes to be documented.
Comment 9 :Benjamin Peterson 2012-10-10 10:02:32 PDT
I suppose bug 757676 can be dev-doc-complete, too then.,

Note You need to log in before you can comment on or make changes to this bug.