Array Literal - Trailing Elision dropped

RESOLVED INVALID

Status

()

RESOLVED INVALID
11 years ago
11 years ago

People

(Reporter: dhtmlkitchen, Unassigned)

Tracking

({js1.5})

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

11 years ago
[,,].length [,].length, [1,].length

1.
[,].length; 
// IE - 2
// FF - 1
Should be: 1

Explanation: 
The production for ArrayLiteral : Elision is evaluated as follows:
1. Create a new Array as if by the expression new Array()
2. Evaluate Elision; if not present, use the numeric value zero.
3. Call the [[put]] method of result(1) with "length" and Result(2).
4. return Result(1).

Step 2. says Evaluate Elision. 
The production Elision : , is evaluated as follows:
1. Return the numeric value 1.

The array length must be 1.

2.
[1,].length; 
// IE - 2
// FF - 1
Should be: 2

The production ArrayLiteral : [ ElementList, Elistion(opt) ] is evaluated as follows:
1. Evaluate ElementList
2. Evaluate Elistion. if not present, use 0.
3. call [[Get]] method of Result(1) with argument "length"
4. call [[Put]] method of Result(1) with arguments "length" and ( Result(2) + Result(1) )
5. Return result(1).

Step 1 tells us to evaluate ElementList.
The production ElementList : Elision(opt) AssignmentExpression is as follows:
1. Create a new Array as if by the expression new Array()
2. Evaluate Elision; if not present, use the numeric value zero.
3. Evaluate AssignemntExpression
4. Call GetValue(Result(3))
5. Call the [[Put]] method of Result(1) with arguments Result(2) and Result(4)
6. Return Result(1)

Returning to step 2 of production ArrayLiteral : [ ElementList, Elision(opt) ]
2. Evaluate Elistion 
  -- that gives us the numeric value 1 for length.
3. call [[Get]] method of Result(1) with arguments "length" 
  -- that also gives us 1. See section 15.4.2.1
4. call [[Put]] method of Result(1) with arguments "length" and ( Result(2) + Result(1) )
  -- ( 1 + 1 ) = 2?

The production ElementList : Elision(opt) AssignmentExpression is as follows:`

3. 
[,1].length
// IE - 2
// FF - 2
Should be: 2, as explained above.

An trailing elision must create a property whose value is undefined. This affects the length of the array by +1

In the first example, [,], there is an ElementList that has 0 AssignemntExpressions, followed by one Elision. This creates an array whose length is 0. This is followed by an Elision, 
so the Array should have length=1.

In the second example, there is an ElementList with one AssignemtnExpression. This creates an Array whose length is 1. This is followed by an Elision, 
which increments the length of the Array by 1.
so the Array should have length=2.

In the third example, we have an ElementList that has an Elision first, The Elision creates an Array whose length is 1. This is followed by 
an AssignmentExpression, which is assigned to the array index 1, and increments the length of the Array.
This looks like a dupe of bug 219308, at first glance.
Assignee: nobody → general
Component: General → JavaScript Engine
Product: Firefox → Core
QA Contact: general → general
(Reporter)

Comment 2

11 years ago
Yes, Comment #1 addresses the Spec in detail 
https://bugzilla.mozilla.org/show_bug.cgi?id=219308#c1

"...
The way I read all of this is:

1. An Elisionopt is not allowed as the final component of an ElementList.
   An ElementList must end in an AssignmentExpression.

2. Therefore in the example [1,2,3,] the ElementList is 1,2,3

3. The final comma in [1,2,3,] is not an Elision, but rather the
   intermediate comma in the syntax [ElementList , Elisionopt]

4. Therefore we fall into Step 2 of the algorithm:
   2. Evaluate Elision; if not present, use the numeric value zero.

5. Therefore in Step 4, when the length of the array is assigned,
   we assign (length of ElementList) + 0  ===> 3 + 0   ===> 3.
"

I just missed that "," as being part of the production, and interpreted it as ArrayLiteral : [ ElementList Elision ]

When it really is ArrayLiteral : [ ElementList , Elision ] 

It's kind of confusing. It would be clearer if the spec were explicit on this point, perhaps even providing an example.
Status: NEW → RESOLVED
Last Resolved: 11 years ago
Resolution: --- → WONTFIX
INVALID, not WONTFIX.

/be
Status: RESOLVED → REOPENED
Resolution: WONTFIX → ---

Updated

11 years ago
Status: REOPENED → RESOLVED
Last Resolved: 11 years ago11 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.