Duplicate parameter names in non-strict function cause assertion failure in InitializeBinding

# Yusuke Suzuki (13 years ago)

Hello,

In the latest ES.next draft(May 4), section 10.5.3 Function Declaration Instantiation step 5 is following

  1. For each String argName in parameterNames, in list order do
a. Let alreadyDeclared be the result of calling env’s HasBinding

concrete method passing argName as the argument. b. NOTE Duplicate parameter names can only occur in non-strict code. c. If alreadyDeclared is false, then i. Call env’s CreateMutableBinding concrete method passing argName as the argument. d. If strict is false, then i. Call env’s InitializeBinding concrete method passing argName, and undefined as the arguments.

In the step d-i, if strict is false, engine always call env.InitializeBinding(argName, undefined). But if code is non-strict mode, duplicate parameter names may be provided.

And section 10.2.1.1.8, InitializeBinding, step 2 is following

  1. Assert: envRec must have an uninitialised binding for N.

So for example,

// this is non-strict function function test(a, a) { } test(1, 1);

engine execute above script and raise assertion failure because of calling InitializeBinding to the same name twice.

So I suggest changing like this

c. If alreadyDeclared is false, then
  i. Call env’s CreateMutableBinding concrete method passing argName

as the argument. ii. If strict is false, then 1. Call env’s InitializeBinding concrete method passing argName, and undefined as the arguments.

If I missed something, please point out.

, Yusuke Suzuki

# Allen Wirfs-Brock (13 years ago)

Yes, that is an issue. There are some others relating to formal parameter initialization. Basically, I need to make another pass over that algorithm particular in regard to formals.

Thanks for point this out. In the future it would be best to report such issues using bugs.ecmascript.org That makes it easier to track them.

# Yusuke Suzuki (13 years ago)

Thanks for your reply.

So I've filed the issue in ecmascript#368

, Yusuke Suzuki