Ticket #267 (closed defect: fixed)

Opened 1 year ago

Last modified 1 year ago

Argument overwritten by named function

Reported by: jresig Assigned to: anonymous
Type: defect Priority: major
Milestone: Component: RefImpl
Version: 4 Keywords:
Cc:

Description

Having an argument with the same name as a named function causes its value to be overwritten by the function itself, for example:

>> function foo(foo){ return foo; }
>> foo(1)
[function Function]

The expected result is '1' (or, at least, that's the expected result in ECMASript 3, and I don't know of anything saying that this is changing).

Attachments

Change History

Changed 1 year ago by jaz

eval.sml, in invokeFunClosure, there is some code that adds the current function's name to the binding environment. This is done *after* the function arguments are bound -- which seems to be the problem. However, it's not obvious (to me) that the function's name has to be added; shouldn't it already be in the outer scope and therefore available to code inside the function (unless shadowed)?

Commenting out the initSelf() call (currently on line 3843), fixes the reported problem and does not prevent a simple recursive function from working as expected:

function foo(foo){ return foo; } foo(1)

1

function fac(n) { if (n == 0) return 1; else return n * fac(n - 1);} fac(5)

120

There is a comment above the call to initSelf, asking about its purpose and referring to "sec 13 ed. 3." Don't know what document this is (working draft of spec?), so I don't feel at all comfortable committing this change.

Changed 1 year ago by graydon

  • status changed from new to closed
  • resolution set to fixed

Fixed in rev 588c0d...

Note: See TracTickets for help on using tickets.