archives

« Bugzilla Issues Index

#1240 — [10.6] MakeArgGetter/MakeArgGetter does not work well with duplicate arguments


The following expression returns `undefined` per 10.6 MakeArgGetter algorithm, but should return `1`:
---
(function(a,a){return arguments[0]})(1)
---

Reason:
MakeArgGetter creates the following getter function:
---
function() { return a }
---

The getter function resolves `a` to the second argument which is defaulted to `undefined`.


This bug also applies to the ECMAScript 5.1 specification.


Hmm, I guess CompleteMappedArgumentsObject only needs be changed:
---
1-4: <<leave as is>>
5: Let indx = numberOfNonRestFormals - 1.
6: Repeat while indx ≥ 0,
a: Let param be getParameter of formals with argument indx.
b: If param is a BindingIdentifier, then
i : Let name be the sole element of BoundNames of param.
ii: If name is not an element of mappedNames, then
1: Add name as an element of the list mappedNames.
2: If indx is less than len, then
a: Let g be the result of calling the MakeArgGetter abstract operation with arguments name and env.
b: Let p be the result of calling the MakeArgSetter abstract operation with arguments name and env.
c: Call the [[DefineOwnProperty]] internal method of map passing ToString(indx) and the Property Descriptor {[[Set]]: p, [[Get]]: g, [[Configurable]]: true} as arguments.
c: Let indx = indx - 1.
7-9: <<leave as is>>
---


Step 7 also needs to be changed and one additional boolean flag must be added. The complete algorithm:
---
1. Let len be the result of Get(obj, "length").
2. Let mappedNames be an empty List.
3. Let hasMapped be false.
4. Let numberOfNonRestFormals be NumberOfParameters of formals.
5. Let map be the result of the abstract operation ObjectCreate.
6. Let indx = numberOfNonRestFormals - 1.
7. Repeat while indx ≥ 0,
a. Let param be getParameter of formals with argument indx.
b. If param is a BindingIdentifier, then
i. Let name be the sole element of BoundNames of param.
ii. If name is not an element of mappedNames, then
1. Add name as an element of the list mappedNames.
2. If indx is less than len, then
a Let hasMapped be true.
b Let g be the result of calling the MakeArgGetter abstract operation with arguments name and env.
c Let p be the result of calling the MakeArgSetter abstract operation with arguments name and env.
d Call the [[DefineOwnProperty]] internal method of map passing ToString(indx) and the Property Descriptor {[[Set]]: p, [[Get]]: g, [[Configurable]]: true} as arguments.
c. Let indx = indx - 1.
8. If hasMapped is true, then
a. Set the [[ParameterMap]] internal data property of obj to map.
b. Set the [[GetP]], [[GetOwnProperty]], [[DefineOwnProperty]], and [[Delete]] internal methods of obj to the definitions provided below.
9. Call the [[DefineOwnProperty]] internal method on obj passing "callee" and the Property Descriptor
{[[Value]]: func , [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true} as arguments.
10. Return obj
---


fixed in rev23 editor's draft

complex rewrite, should be reviewed again.


fixed in rev23 draft