1 description("This tests that arrays have holes that you can see the prototype through, not just missing values.");
3 function isHole(array, index)
5 if (index >= array.length)
6 return "bad index: past length";
7 // Check if we can see through the hole into another room.
8 Array.prototype[index] = "room";
9 var isHole = array[index] == "room";
10 delete Array.prototype[index];
14 function showHoles(array)
17 for (i = 0; i < array.length; ++i) {
36 function addToArray(arg)
41 function addToArrayReturnFalse(arg)
47 function addToArrayReturnTrue(arg)
53 shouldBe("var a = []; a.length = 1; showHoles(a)", "'[hole]'");
54 shouldBe("var a = []; a[0] = undefined; showHoles(a)", "'[undefined]'");
55 shouldBe("var a = []; a[0] = undefined; delete a[0]; showHoles(a)", "'[hole]'");
57 shouldBe("showHoles([0, , 2])", "'[0, hole, 2]'");
58 shouldBe("showHoles([0, 1, ,])", "'[0, 1, hole]'");
59 shouldBe("showHoles([0, , 2].concat([3, , 5]))", "'[0, hole, 2, 3, hole, 5]'");
60 shouldBe("showHoles([0, , 2, 3].reverse())", "'[3, 2, hole, 0]'");
61 shouldBe("a = [0, , 2, 3]; a.shift(); showHoles(a)", "'[hole, 2, 3]'");
62 shouldBe("showHoles([0, , 2, 3].slice(0, 3))", "'[0, hole, 2]'");
63 shouldBe("showHoles([0, , 2, 3].sort())", "'[0, 2, 3, hole]'");
64 shouldBe("showHoles([0, undefined, 2, 3].sort())", "'[0, 2, 3, undefined]'");
65 shouldBe("a = [0, , 2, 3]; a.splice(2, 3, 5, 6); showHoles(a)", "'[0, hole, 5, 6]'");
66 shouldBe("a = [0, , 2, 3]; a.unshift(4); showHoles(a)", "'[4, 0, hole, 2, 3]'");
67 shouldBe("showHoles([0, , 2, 3].filter(returnTrue))", "'[0, 2, 3]'");
68 shouldBe("showHoles([0, undefined, 2, 3].filter(returnTrue))", "'[0, undefined, 2, 3]'");
69 shouldBe("showHoles([0, , 2, 3].map(returnTrue))", "'[true, hole, true, true]'");
70 shouldBe("showHoles([0, undefined, 2, 3].map(returnTrue))", "'[true, true, true, true]'");
71 shouldBe("a = []; [0, , 2, 3].every(addToArrayReturnTrue); showHoles(a)", "'[0, 2, 3]'");
72 shouldBe("a = []; [0, undefined, 2, 3].every(addToArrayReturnTrue); showHoles(a)", "'[0, undefined, 2, 3]'");
73 shouldBe("a = []; [0, , 2, 3].forEach(addToArray); showHoles(a)", "'[0, 2, 3]'");
74 shouldBe("a = []; [0, undefined, 2, 3].forEach(addToArray); showHoles(a)", "'[0, undefined, 2, 3]'");
75 shouldBe("a = []; [0, , 2, 3].some(addToArrayReturnFalse); showHoles(a)", "'[0, 2, 3]'");
76 shouldBe("a = []; [0, undefined, 2, 3].some(addToArrayReturnFalse); showHoles(a)", "'[0, undefined, 2, 3]'");
77 shouldBe("[0, , 2, 3].indexOf()", "-1");
78 shouldBe("[0, undefined, 2, 3].indexOf()", "1");
79 shouldBe("[0, , 2, 3].lastIndexOf()", "-1");
80 shouldBe("[0, undefined, 2, 3].lastIndexOf()", "1");
82 Object.prototype[1] = "peekaboo";
84 shouldBe("showHoles([0, , 2])", "'[0, hole, 2]'");
85 shouldBe("showHoles([0, 1, ,])", "'[0, 1, hole]'");
86 shouldBe("showHoles([0, , 2].concat([3, , 5]))", "'[0, peekaboo, 2, 3, peekaboo, 5]'");
87 shouldBe("showHoles([0, , 2, 3].reverse())", "'[3, 2, peekaboo, 0]'");
88 shouldBe("a = [0, , 2, 3]; a.shift(); showHoles(a)", "'[peekaboo, 2, 3]'");
89 shouldBe("showHoles([0, , 2, 3].slice(0, 3))", "'[0, peekaboo, 2]'");
90 shouldBe("showHoles([0, , 2, 3].sort())", "'[0, 2, 3, hole]'");
91 shouldBe("showHoles([0, undefined, 2, 3].sort())", "'[0, 2, 3, undefined]'");
92 shouldBe("a = [0, , 2, 3]; a.splice(2, 3, 5, 6); showHoles(a)", "'[0, hole, 5, 6]'");
93 shouldBe("a = [0, , 2, 3]; a.unshift(4); showHoles(a)", "'[4, 0, peekaboo, 2, 3]'");
94 shouldBe("showHoles([0, , 2, 3].filter(returnTrue))", "'[0, peekaboo, 2, 3]'");
95 shouldBe("showHoles([0, undefined, 2, 3].filter(returnTrue))", "'[0, undefined, 2, 3]'");
96 shouldBe("showHoles([0, , 2, 3].map(returnTrue))", "'[true, true, true, true]'");
97 shouldBe("showHoles([0, undefined, 2, 3].map(returnTrue))", "'[true, true, true, true]'");
98 shouldBe("a = []; [0, , 2, 3].every(addToArrayReturnTrue); showHoles(a)", "'[0, peekaboo, 2, 3]'");
99 shouldBe("a = []; [0, undefined, 2, 3].every(addToArrayReturnTrue); showHoles(a)", "'[0, undefined, 2, 3]'");
100 shouldBe("a = []; [0, , 2, 3].forEach(addToArray); showHoles(a)", "'[0, peekaboo, 2, 3]'");
101 shouldBe("a = []; [0, undefined, 2, 3].forEach(addToArray); showHoles(a)", "'[0, undefined, 2, 3]'");
102 shouldBe("a = []; [0, , 2, 3].some(addToArrayReturnFalse); showHoles(a)", "'[0, peekaboo, 2, 3]'");
103 shouldBe("a = []; [0, undefined, 2, 3].some(addToArrayReturnFalse); showHoles(a)", "'[0, undefined, 2, 3]'");
104 shouldBe("[0, , 2, 3].indexOf()", "-1");
105 shouldBe("[0, , 2, 3].indexOf('peekaboo')", "1");
106 shouldBe("[0, undefined, 2, 3].indexOf()", "1");
107 shouldBe("[0, , 2, 3].lastIndexOf()", "-1");
108 shouldBe("[0, , 2, 3].lastIndexOf('peekaboo')", "1");
109 shouldBe("[0, undefined, 2, 3].lastIndexOf()", "1");
111 delete Object.prototype[1];