Closed Bug 1281047 Opened 8 years ago Closed 8 years ago

Reps: array indexes aren't sorted properly

Categories

(DevTools :: Shared Components, defect, P1)

defect

Tracking

(firefox50 fixed)

RESOLVED FIXED
Firefox 50
Iteration:
50.3 - Jul 18
Tracking Status
firefox50 --- fixed

People

(Reporter: linclark, Assigned: miker)

References

Details

(Whiteboard: [devtools-html])

Attachments

(2 files, 1 obsolete file)

Attached image array-vals.png
The array indexes seem to be sorted as if they were strings, not numbers.
Whiteboard: [devtools-html] [triage]
Flags: qe-verify-
Priority: -- → P2
Whiteboard: [devtools-html] [triage] → [devtools-html]
Assignee: nobody → mratcliffe
Status: NEW → ASSIGNED
Test string:
[ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" ]
I can reproduce if I enable the DOM panel so I will work on it there.
Flags: needinfo?(lclark)
In summary I needed the patch from bug 1283123 and bug 1283870.
Iteration: --- → 50.3 - Jul 18
Priority: P2 → P1
In devtools/server/actors/object.js::enumArrayProperties() we use the following to get the property names:

```
Object.getOwnPropertyNames([ "a", "b", "c" ])
```

The problem is that this returns [ "1", "2", "3" ] instead of [ 1, 2, 3 ].

Of course, an array can contain object properties e.g. myArr.someProp so we need to support both in this instance.
So it seems that in this instance getOwnPropertyNames() is correct... array indexes are strings internally. It is not obvious because e.g. arr[1] is coerced into arr["1"].

We should still sort arrays as a special case because this is what most users would expect.
Comment on attachment 8769702 [details] [diff] [review]
1281047-fix-array-key-order.diff

Review of attachment 8769702 [details] [diff] [review]:
-----------------------------------------------------------------

Works for me. We should make sure that this is covered by a test (in bug 1264676)

Nit: the commit message should be:
Bug 1281047 - Properly sort array indexes; r=Honza

Thanks Mike!
Honza
Attachment #8769702 - Flags: review?(odvarko) → review+
The test will be added in bug 1286186 so this can be landed.
Attachment #8769702 - Attachment is obsolete: true
Attachment #8770057 - Flags: review+
Pushed by cbook@mozilla.com:
https://hg.mozilla.org/integration/fx-team/rev/4773ee41e97d
Properly sort array indexes; r=honza
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/4773ee41e97d
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 50
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: