зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1300336 - Allow pseudo-arrays to have a length property. r=fitzgen
This commit is contained in:
Родитель
5b6d08a081
Коммит
4a071f812f
|
@ -111,7 +111,7 @@ var inputTests = [
|
|||
input: '["' + testStrIn + '", "' + testStrIn + '", "' + testStrIn + '"]',
|
||||
output: 'Array [ "' + testStrOut + '", "' + testStrOut + '", "' +
|
||||
testStrOut + '" ]',
|
||||
inspectable: false,
|
||||
inspectable: true,
|
||||
printOutput: "SHOW\nALL\nOF\nTHIS\nON\nA\nSINGLE\nLINE ONLY. ESCAPE " +
|
||||
"ALL NEWLINE,SHOW\nALL\nOF\nTHIS\nON\nA\nSINGLE\nLINE ONLY. " +
|
||||
"ESCAPE ALL NEWLINE,SHOW\nALL\nOF\nTHIS\nON\nA\nSINGLE\n" +
|
||||
|
@ -124,7 +124,8 @@ var inputTests = [
|
|||
input: '({0: "a", 1: "b"})',
|
||||
output: 'Object [ "a", "b" ]',
|
||||
printOutput: "[object Object]",
|
||||
inspectable: false,
|
||||
inspectable: true,
|
||||
variablesViewLabel: "Object[2]",
|
||||
},
|
||||
|
||||
// 14
|
||||
|
@ -132,7 +133,8 @@ var inputTests = [
|
|||
input: '({0: "a", 42: "b"})',
|
||||
output: 'Object { 0: "a", 42: "b" }',
|
||||
printOutput: "[object Object]",
|
||||
inspectable: false,
|
||||
inspectable: true,
|
||||
variablesViewLabel: "Object",
|
||||
},
|
||||
|
||||
// 15
|
||||
|
@ -165,6 +167,96 @@ var inputTests = [
|
|||
inspectable: true,
|
||||
variablesViewLabel: "Object",
|
||||
},
|
||||
|
||||
// 18
|
||||
{
|
||||
input: '({})',
|
||||
output: 'Object { }',
|
||||
printOutput: "[object Object]",
|
||||
inspectable: true,
|
||||
variablesViewLabel: "Object",
|
||||
},
|
||||
|
||||
// 19
|
||||
{
|
||||
input: '({length: 0})',
|
||||
output: 'Object [ ]',
|
||||
printOutput: "[object Object]",
|
||||
inspectable: true,
|
||||
variablesViewLabel: "Object[0]",
|
||||
},
|
||||
|
||||
// 20
|
||||
{
|
||||
input: '({length: 1})',
|
||||
output: 'Object { length: 1 }',
|
||||
printOutput: "[object Object]",
|
||||
inspectable: true,
|
||||
variablesViewLabel: "Object",
|
||||
},
|
||||
|
||||
// 21
|
||||
{
|
||||
input: '({0: "a", 1: "b", length: 1})',
|
||||
output: 'Object { 1: "b", length: 1, 1 more\u2026 }',
|
||||
printOutput: "[object Object]",
|
||||
inspectable: true,
|
||||
variablesViewLabel: "Object",
|
||||
},
|
||||
|
||||
// 22
|
||||
{
|
||||
input: '({0: "a", 1: "b", length: 2})',
|
||||
output: 'Object [ "a", "b" ]',
|
||||
printOutput: "[object Object]",
|
||||
inspectable: true,
|
||||
variablesViewLabel: "Object[2]",
|
||||
},
|
||||
|
||||
// 23
|
||||
{
|
||||
input: '({0: "a", 1: "b", length: 3})',
|
||||
output: 'Object { length: 3, 2 more\u2026 }',
|
||||
printOutput: "[object Object]",
|
||||
inspectable: true,
|
||||
variablesViewLabel: "Object",
|
||||
},
|
||||
|
||||
// 24
|
||||
{
|
||||
input: '({0: "a", 2: "b", length: 2})',
|
||||
output: 'Object { 2: "b", length: 2, 1 more\u2026 }',
|
||||
printOutput: "[object Object]",
|
||||
inspectable: true,
|
||||
variablesViewLabel: "Object",
|
||||
},
|
||||
|
||||
// 25
|
||||
{
|
||||
input: '({0: "a", 2: "b", length: 3})',
|
||||
output: 'Object { length: 3, 2 more\u2026 }',
|
||||
printOutput: "[object Object]",
|
||||
inspectable: true,
|
||||
variablesViewLabel: "Object",
|
||||
},
|
||||
|
||||
// 26
|
||||
{
|
||||
input: '({0: "a", b: "b", length: 1})',
|
||||
output: 'Object { b: "b", length: 1, 1 more\u2026 }',
|
||||
printOutput: "[object Object]",
|
||||
inspectable: true,
|
||||
variablesViewLabel: "Object",
|
||||
},
|
||||
|
||||
// 27
|
||||
{
|
||||
input: '({0: "a", b: "b", length: 2})',
|
||||
output: 'Object { b: "b", length: 2, 1 more\u2026 }',
|
||||
printOutput: "[object Object]",
|
||||
inspectable: true,
|
||||
variablesViewLabel: "Object",
|
||||
},
|
||||
];
|
||||
|
||||
function test() {
|
||||
|
|
|
@ -1800,13 +1800,27 @@ DebuggerServer.ObjectActorPreviewers.Object = [
|
|||
return false;
|
||||
}
|
||||
|
||||
// Making sure that all keys are array indices, that is:
|
||||
// `ToString(ToUint32(key)) === key && key !== "4294967295"`.
|
||||
// Also ensuring that the keys are consecutive and start at "0",
|
||||
// this implies checking `key !== "4294967295"` is not necessary.
|
||||
// Pseudo-arrays should only have array indices and, optionally, a "length" property.
|
||||
// Since array indices are sorted first, check if the last property is "length".
|
||||
if(keys[keys.length-1] === "length") {
|
||||
keys.pop();
|
||||
// The value of "length" should equal the number of other properties. If eventually
|
||||
// we allow sparse pseudo-arrays, we should check whether it's a Uint32 instead.
|
||||
if(rawObj.length !== keys.length) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure that the keys are consecutive integers starting at "0". If eventually we
|
||||
// allow sparse pseudo-arrays, we should check that they are array indices, that is:
|
||||
// `(key >>> 0) + '' === key && key !== "4294967295"`.
|
||||
// Checking the last property first allows us to avoid useless iterations when
|
||||
// there is any property which is not an array index.
|
||||
if(keys.length && keys[keys.length-1] !== keys.length - 1 + '') {
|
||||
return false;
|
||||
}
|
||||
for (let key of keys) {
|
||||
let numKey = key >>> 0; // ToUint32(key)
|
||||
if (numKey + '' != key || numKey != length++) {
|
||||
if (key !== (length++) + '') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче