| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 assertEquals(6, a.length); | 194 assertEquals(6, a.length); |
| 195 | 195 |
| 196 a = [1, 2, 3]; | 196 a = [1, 2, 3]; |
| 197 a.findIndex(function(val, key) { a[key] = ++val; return false; }); | 197 a.findIndex(function(val, key) { a[key] = ++val; return false; }); |
| 198 assertArrayEquals([2, 3, 4], a); | 198 assertArrayEquals([2, 3, 4], a); |
| 199 assertEquals(3, a.length); | 199 assertEquals(3, a.length); |
| 200 })(); | 200 })(); |
| 201 | 201 |
| 202 | 202 |
| 203 // | 203 // |
| 204 // Test predicate is only called for existing elements | 204 // Test predicate is called for holes |
| 205 // | 205 // |
| 206 (function() { | 206 (function() { |
| 207 var a = new Array(30); | 207 var a = new Array(30); |
| 208 a[11] = 21; | 208 a[11] = 21; |
| 209 a[7] = 10; | 209 a[7] = 10; |
| 210 a[29] = 31; | 210 a[29] = 31; |
| 211 | 211 |
| 212 var count = 0; | 212 var count = 0; |
| 213 a.findIndex(function() { count++; return false; }); | 213 a.findIndex(function() { count++; return false; }); |
| 214 assertEquals(3, count); | 214 assertEquals(30, count); |
| 215 })(); | 215 })(); |
| 216 | 216 |
| 217 | 217 |
| 218 (function() { |
| 219 var a = [0, 1, , 3]; |
| 220 var count = 0; |
| 221 var index = a.findIndex(function(val) { return val === undefined; }); |
| 222 assertEquals(2, index); |
| 223 })(); |
| 224 |
| 225 |
| 226 (function() { |
| 227 var a = [0, 1, , 3]; |
| 228 a.__proto__ = { |
| 229 __proto__: Array.prototype, |
| 230 2: 42, |
| 231 }; |
| 232 var count = 0; |
| 233 var index = a.findIndex(function(val) { return val === 42; }); |
| 234 assertEquals(2, index); |
| 235 })(); |
| 236 |
| 237 |
| 218 // | 238 // |
| 219 // Test thisArg | 239 // Test thisArg |
| 220 // | 240 // |
| 221 (function() { | 241 (function() { |
| 222 // Test String as a thisArg | 242 // Test String as a thisArg |
| 223 var index = [1, 2, 3].findIndex(function(val, key) { | 243 var index = [1, 2, 3].findIndex(function(val, key) { |
| 224 return this.charAt(Number(key)) === String(val); | 244 return this.charAt(Number(key)) === String(val); |
| 225 }, "321"); | 245 }, "321"); |
| 226 assertEquals(1, index); | 246 assertEquals(1, index); |
| 227 | 247 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 | 309 |
| 290 assertThrows('Array.prototype.findIndex.apply({}, null, [])', TypeError); | 310 assertThrows('Array.prototype.findIndex.apply({}, null, [])', TypeError); |
| 291 assertThrows('Array.prototype.findIndex.apply({}, undefined, [])', TypeError); | 311 assertThrows('Array.prototype.findIndex.apply({}, undefined, [])', TypeError); |
| 292 assertThrows('Array.prototype.findIndex.apply({}, 0, [])', TypeError); | 312 assertThrows('Array.prototype.findIndex.apply({}, 0, [])', TypeError); |
| 293 assertThrows('Array.prototype.findIndex.apply({}, true, [])', TypeError); | 313 assertThrows('Array.prototype.findIndex.apply({}, true, [])', TypeError); |
| 294 assertThrows('Array.prototype.findIndex.apply({}, false, [])', TypeError); | 314 assertThrows('Array.prototype.findIndex.apply({}, false, [])', TypeError); |
| 295 assertThrows('Array.prototype.findIndex.apply({}, "", [])', TypeError); | 315 assertThrows('Array.prototype.findIndex.apply({}, "", [])', TypeError); |
| 296 assertThrows('Array.prototype.findIndex.apply({}, {}, [])', TypeError); | 316 assertThrows('Array.prototype.findIndex.apply({}, {}, [])', TypeError); |
| 297 assertThrows('Array.prototype.findIndex.apply({}, [], [])', TypeError); | 317 assertThrows('Array.prototype.findIndex.apply({}, [], [])', TypeError); |
| 298 assertThrows('Array.prototype.findIndex.apply({}, /\d+/, [])', TypeError); | 318 assertThrows('Array.prototype.findIndex.apply({}, /\d+/, [])', TypeError); |
| OLD | NEW |