Bug 1281047 - Properly sort array indexes; r=honza

MozReview-Commit-ID: BWQMkPiMkM7
This commit is contained in:
Michael Ratcliffe 2016-07-12 09:33:07 +01:00
parent a898928047
commit 3e3392e6b3

View File

@ -48,6 +48,7 @@ function onRequestProperties(state, action) {
function onReceiveProperties(cache, action) {
let response = action.response;
let from = response.from;
let className = action.grip.class;
// Properly deal with getters.
mergeProperties(response);
@ -55,7 +56,13 @@ function onReceiveProperties(cache, action) {
// Compute list of requested children.
let previewProps = response.preview ? response.preview.ownProperties : null;
let ownProps = response.ownProperties || previewProps || [];
let props = Object.keys(ownProps).map(key => {
// Array indexes as a special case. We convert any keys that are string
// representations of integers to integers.
if (className === "Array" && isInteger(key)) {
key = parseInt(key, 10);
}
return new Property(key, ownProps[key], key);
});
@ -100,6 +107,11 @@ function sortName(a, b) {
return a.name > b.name ? 1 : -1;
}
function isInteger(n) {
// We use parseInt(n, 10) == n to disregard scientific notation e.g. "3e24"
return isFinite(n) && parseInt(n, 10) == n;
}
function Property(name, value, key) {
this.name = name;
this.value = value;