OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --harmony-tolength |
| 6 |
| 7 // Test array functions do not cause infinite loops when length is negative, |
| 8 // max_value, etc. |
| 9 |
| 10 // ArrayToString |
| 11 |
| 12 var o = { length: Number.MIN_VALUE }; |
| 13 var result = Array.prototype.toString.call(o); |
| 14 assertEquals("[object Object]", result); |
| 15 |
| 16 // ArrayToLocaleString |
| 17 |
| 18 var o = { length: Number.MIN_VALUE }; |
| 19 var result = Array.prototype.toLocaleString.call(o); |
| 20 assertEquals("", result); |
| 21 |
| 22 // ArrayJoin |
| 23 |
| 24 var o = { length: Number.MIN_VALUE }; |
| 25 var result = Array.prototype.join.call(o); |
| 26 assertEquals(0, result.length); |
| 27 |
| 28 // ArrayPush |
| 29 |
| 30 var o = { length: Number.MIN_VALUE }; |
| 31 Array.prototype.push.call(o, 1); |
| 32 assertEquals(1, o.length); |
| 33 assertEquals(1, o[0]); |
| 34 |
| 35 var o = { length: Number.MAX_VALUE }; |
| 36 Array.prototype.push.call(o, 1); |
| 37 assertEquals(o.length, Number.MAX_SAFE_INTEGER + 1); |
| 38 assertEquals(1, o[Number.MAX_SAFE_INTEGER]); |
| 39 |
| 40 Array.prototype.push.call(o, 2); |
| 41 assertEquals(o.length, Number.MAX_SAFE_INTEGER + 1); |
| 42 assertEquals(2, o[Number.MAX_SAFE_INTEGER]); |
| 43 |
| 44 // ArrayPop |
| 45 |
| 46 var o = { length: 0 }; |
| 47 Array.prototype.pop.call(o); |
| 48 assertEquals(0, o.length); |
| 49 |
| 50 var o = { length: Number.MIN_VALUE }; |
| 51 Array.prototype.pop.call(o); |
| 52 assertEquals(0, o.length); |
| 53 |
| 54 var o = { length: Number.MAX_VALUE }; |
| 55 Array.prototype.pop.call(o); |
| 56 assertEquals(o.length, Number.MAX_SAFE_INTEGER - 1); |
| 57 |
| 58 // ArrayReverse |
| 59 |
| 60 var o = { 0: 'foo', length: Number.MIN_VALUE } |
| 61 var result = Array.prototype.reverse.call(o); |
| 62 assertEquals('object', typeof(result)); |
| 63 assertEquals(Number.MIN_VALUE, result.length); |
| 64 assertEquals(Number.MIN_VALUE, o.length); |
| 65 |
| 66 // ArrayShift |
| 67 |
| 68 var o = { 0: "foo", length: Number.MIN_VALUE } |
| 69 var result = Array.prototype.shift.call(o); |
| 70 assertEquals(undefined, result); |
| 71 assertEquals(0, o.length); |
| 72 |
| 73 // ArrayUnshift |
| 74 |
| 75 var o = { length: 0 }; |
| 76 Array.prototype.unshift.call(o); |
| 77 assertEquals(0, o.length); |
| 78 |
| 79 var o = { length: 0 }; |
| 80 Array.prototype.unshift.call(o, 'foo'); |
| 81 assertEquals('foo', o[0]); |
| 82 assertEquals(1, o.length); |
| 83 |
| 84 var o = { length: Number.MIN_VALUE }; |
| 85 Array.prototype.unshift.call(o); |
| 86 assertEquals(0, o.length); |
| 87 |
| 88 var o = { length: Number.MIN_VALUE }; |
| 89 Array.prototype.unshift.call(o, 'foo'); |
| 90 assertEquals('foo', o[0]); |
| 91 assertEquals(1, o.length); |
| 92 |
| 93 // ArraySplice |
| 94 |
| 95 var o = { length: Number.MIN_VALUE }; |
| 96 Array.prototype.splice.call(o); |
| 97 assertEquals(0, o.length); |
| 98 |
| 99 var o = { length: Number.MIN_VALUE }; |
| 100 Array.prototype.splice.call(o, 0, 10, ['foo']); |
| 101 assertEquals(['foo'], o[0]); |
| 102 assertEquals(1, o.length); |
| 103 |
| 104 var o = { length: Number.MIN_VALUE }; |
| 105 Array.prototype.splice.call(o, -1); |
| 106 assertEquals(0, o.length); |
| 107 |
| 108 var o = { length: Number.MAX_SAFE_INTEGER }; |
| 109 Array.prototype.splice.call(o, -1); |
| 110 assertEquals(Number.MAX_SAFE_INTEGER - 1, o.length); |
| 111 |
| 112 // ArraySlice |
| 113 |
| 114 var o = { length: Number.MIN_VALUE }; |
| 115 var result = Array.prototype.slice.call(o); |
| 116 assertEquals(0, result.length); |
| 117 |
| 118 var o = { length: Number.MIN_VALUE }; |
| 119 var result = Array.prototype.slice.call(o, Number.MAX_VALUE); |
| 120 assertEquals(0, result.length); |
| 121 |
| 122 var o = { length: Number.MAX_VALUE }; |
| 123 var result = Array.prototype.slice.call(o, Number.MAX_VALUE - 1); |
| 124 assertEquals(0, result.length); |
| 125 |
| 126 // ArrayIndexOf |
| 127 |
| 128 var o = { length: Number.MIN_VALUE }; |
| 129 var result = Array.prototype.indexOf.call(o); |
| 130 assertEquals(-1, result); |
| 131 |
| 132 var o = { length: Number.MAX_SAFE_INTEGER } |
| 133 o[Number.MAX_SAFE_INTEGER - 1] = "foo" |
| 134 var result = Array.prototype.indexOf.call(o, |
| 135 "foo", Number.MAX_SAFE_INTEGER - 2); |
| 136 assertEquals(Number.MAX_SAFE_INTEGER - 1, result); |
| 137 |
| 138 var o = { length: Number.MAX_SAFE_INTEGER }; |
| 139 o[Number.MAX_SAFE_INTEGER - 1] = "foo"; |
| 140 var result = Array.prototype.indexOf.call(o, "foo", -1); |
| 141 assertEquals(Number.MAX_SAFE_INTEGER - 1, result); |
| 142 |
| 143 // ArrayLastIndexOf |
| 144 |
| 145 var o = { length: Number.MIN_VALUE }; |
| 146 var result = Array.prototype.lastIndexOf.call(o); |
| 147 assertEquals(-1, result); |
| 148 |
| 149 var o = { length: Number.MAX_SAFE_INTEGER } |
| 150 o[Number.MAX_SAFE_INTEGER - 1] = "foo" |
| 151 var result = Array.prototype.lastIndexOf.call(o, |
| 152 "foo", Number.MAX_SAFE_INTEGER); |
| 153 assertEquals(Number.MAX_SAFE_INTEGER - 1, result); |
| 154 |
| 155 var o = { length: Number.MAX_SAFE_INTEGER }; |
| 156 o[Number.MAX_SAFE_INTEGER - 1] = "foo"; |
| 157 var result = Array.prototype.lastIndexOf.call(o, "foo", -1); |
| 158 assertEquals(Number.MAX_SAFE_INTEGER - 1, result); |
| 159 |
| 160 // ArrayFilter |
| 161 |
| 162 var func = function(v) { return v; } |
| 163 |
| 164 var o = { length: Number.MIN_VALUE }; |
| 165 Array.prototype.filter.call(o, func); |
| 166 assertEquals(Number.MIN_VALUE, o.length); |
| 167 |
| 168 // ArrayForEach |
| 169 |
| 170 var o = { length: Number.MIN_VALUE }; |
| 171 Array.prototype.forEach.call(o, func); |
| 172 assertEquals(Number.MIN_VALUE, o.length); |
| 173 |
| 174 // ArraySome |
| 175 |
| 176 var o = { length: Number.MIN_VALUE }; |
| 177 Array.prototype.some.call(o, func); |
| 178 assertEquals(Number.MIN_VALUE, o.length); |
| 179 |
| 180 // ArrayEvery |
| 181 |
| 182 var o = { length: Number.MIN_VALUE }; |
| 183 Array.prototype.every.call(o, func); |
| 184 assertEquals(Number.MIN_VALUE, o.length); |
| 185 |
| 186 // ArrayMap |
| 187 |
| 188 var o = { length: Number.MIN_VALUE }; |
| 189 Array.prototype.map.call(o, func); |
| 190 assertEquals(Number.MIN_VALUE, o.length); |
| 191 |
| 192 // ArrayReduce |
| 193 |
| 194 var o = { length: Number.MIN_VALUE }; |
| 195 Array.prototype.reduce.call(o, func, 0); |
| 196 assertEquals(Number.MIN_VALUE, o.length); |
| 197 |
| 198 // ArrayReduceRight |
| 199 |
| 200 var o = { length: Number.MIN_VALUE }; |
| 201 Array.prototype.reduceRight.call(o, func, 0); |
| 202 assertEquals(Number.MIN_VALUE, o.length); |
| 203 |
| 204 // ArrayFill |
| 205 |
| 206 var o = { length: Number.MIN_VALUE }; |
| 207 Array.prototype.fill(o, 0); |
| 208 assertEquals(Number.MIN_VALUE, o.length); |
OLD | NEW |