| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 simpleSparseArray, accumulate, []); | 168 simpleSparseArray, accumulate, []); |
| 169 | 169 |
| 170 | 170 |
| 171 testReduce("reduce", "EmptySparseReduceSumNoInit", 0, [], [,,0,,], sum); | 171 testReduce("reduce", "EmptySparseReduceSumNoInit", 0, [], [,,0,,], sum); |
| 172 testReduce("reduce", "EmptySparseReduceProdNoInit", 1, [], [,,1,,], prod); | 172 testReduce("reduce", "EmptySparseReduceProdNoInit", 1, [], [,,1,,], prod); |
| 173 testReduce("reduce", "EmptySparseReduceDecNoInit", 0, [], [,,0,,], dec); | 173 testReduce("reduce", "EmptySparseReduceDecNoInit", 0, [], [,,0,,], dec); |
| 174 testReduce("reduce", "EmptySparseReduceAccumulateNoInit", | 174 testReduce("reduce", "EmptySparseReduceAccumulateNoInit", |
| 175 [], [], [,,[],,], accumulate); | 175 [], [], [,,[],,], accumulate); |
| 176 | 176 |
| 177 | 177 |
| 178 var verySparseArray = new Array(500000); | 178 var verySparseArray = []; |
| 179 verySparseArray[100000] = 2; | 179 verySparseArray.length = 10000; |
| 180 verySparseArray[250000] = 4; | 180 verySparseArray[2000] = 2; |
| 181 verySparseArray[450000] = 6; | 181 verySparseArray[5000] = 4; |
| 182 var verySparseSlice2 = verySparseArray.slice(0, 100001); | 182 verySparseArray[9000] = 6; |
| 183 var verySparseSlice4 = verySparseArray.slice(0, 250001); | 183 var verySparseSlice2 = verySparseArray.slice(0, 2001); |
| 184 var verySparseSlice6 = verySparseArray.slice(0, 450001); | 184 var verySparseSlice4 = verySparseArray.slice(0, 5001); |
| 185 var verySparseSlice6 = verySparseArray.slice(0, 9001); |
| 185 | 186 |
| 186 testReduce("reduce", "VerySparseReduceSum", 12, | 187 testReduce("reduce", "VerySparseReduceSum", 12, |
| 187 [[0, 2, 100000, verySparseArray, 2], | 188 [[0, 2, 2000, verySparseArray, 2], |
| 188 [2, 4, 250000, verySparseArray, 6], | 189 [2, 4, 5000, verySparseArray, 6], |
| 189 [6, 6, 450000, verySparseArray, 12]], | 190 [6, 6, 9000, verySparseArray, 12]], |
| 190 verySparseArray, sum, 0); | 191 verySparseArray, sum, 0); |
| 191 | 192 |
| 192 testReduce("reduce", "VerySparseReduceProd", 48, | 193 testReduce("reduce", "VerySparseReduceProd", 48, |
| 193 [[1, 2, 100000, verySparseArray, 2], | 194 [[1, 2, 2000, verySparseArray, 2], |
| 194 [2, 4, 250000, verySparseArray, 8], | 195 [2, 4, 5000, verySparseArray, 8], |
| 195 [8, 6, 450000, verySparseArray, 48]], | 196 [8, 6, 9000, verySparseArray, 48]], |
| 196 verySparseArray, prod, 1); | 197 verySparseArray, prod, 1); |
| 197 | 198 |
| 198 testReduce("reduce", "VerySparseReduceDec", Infinity, | 199 testReduce("reduce", "VerySparseReduceDec", Infinity, |
| 199 [[0, 2, 100000, verySparseArray, Infinity], | 200 [[0, 2, 2000, verySparseArray, Infinity], |
| 200 [Infinity, 4, 250000, verySparseArray, Infinity], | 201 [Infinity, 4, 5000, verySparseArray, Infinity], |
| 201 [Infinity, 6, 450000, verySparseArray, Infinity]], | 202 [Infinity, 6, 9000, verySparseArray, Infinity]], |
| 202 verySparseArray, dec, 0); | 203 verySparseArray, dec, 0); |
| 203 | 204 |
| 204 testReduce("reduce", "SimpleSparseReduceAccumulate", | 205 testReduce("reduce", "VerySparseReduceAccumulate", |
| 205 verySparseSlice6, | 206 verySparseSlice6, |
| 206 [[[], 2, 100000, verySparseArray, verySparseSlice2], | 207 [[[], 2, 2000, verySparseArray, verySparseSlice2], |
| 207 [verySparseSlice2, 4, 250000, verySparseArray, verySparseSlice4], | 208 [verySparseSlice2, 4, 5000, verySparseArray, verySparseSlice4], |
| 208 [verySparseSlice4, 6, 450000, verySparseArray, verySparseSlice6]], | 209 [verySparseSlice4, 6, 9000, verySparseArray, verySparseSlice6]], |
| 209 verySparseArray, accumulate, []); | 210 verySparseArray, accumulate, []); |
| 210 | 211 |
| 211 | 212 |
| 212 testReduce("reduce", "VerySparseReduceSumNoInit", 12, | 213 testReduce("reduce", "VerySparseReduceSumNoInit", 12, |
| 213 [[2, 4, 250000, verySparseArray, 6], | 214 [[2, 4, 5000, verySparseArray, 6], |
| 214 [6, 6, 450000, verySparseArray, 12]], | 215 [6, 6, 9000, verySparseArray, 12]], |
| 215 verySparseArray, sum); | 216 verySparseArray, sum); |
| 216 | 217 |
| 217 testReduce("reduce", "VerySparseReduceProdNoInit", 48, | 218 testReduce("reduce", "VerySparseReduceProdNoInit", 48, |
| 218 [[2, 4, 250000, verySparseArray, 8], | 219 [[2, 4, 5000, verySparseArray, 8], |
| 219 [8, 6, 450000, verySparseArray, 48]], | 220 [8, 6, 9000, verySparseArray, 48]], |
| 220 verySparseArray, prod); | 221 verySparseArray, prod); |
| 221 | 222 |
| 222 testReduce("reduce", "VerySparseReduceDecNoInit", Infinity, | 223 testReduce("reduce", "VerySparseReduceDecNoInit", Infinity, |
| 223 [[2, 4, 250000, verySparseArray, Infinity], | 224 [[2, 4, 5000, verySparseArray, Infinity], |
| 224 [Infinity, 6, 450000, verySparseArray, Infinity]], | 225 [Infinity, 6, 9000, verySparseArray, Infinity]], |
| 225 verySparseArray, dec); | 226 verySparseArray, dec); |
| 226 | 227 |
| 227 testReduce("reduce", "SimpleSparseReduceAccumulateNoInit", | 228 testReduce("reduce", "SimpleSparseReduceAccumulateNoInit", |
| 228 2, | 229 2, |
| 229 [[2, 4, 250000, verySparseArray, 2], | 230 [[2, 4, 5000, verySparseArray, 2], |
| 230 [2, 6, 450000, verySparseArray, 2]], | 231 [2, 6, 9000, verySparseArray, 2]], |
| 231 verySparseArray, accumulate); | 232 verySparseArray, accumulate); |
| 232 | 233 |
| 233 | 234 |
| 234 // ---- Test ReduceRight | 235 // ---- Test ReduceRight |
| 235 | 236 |
| 236 testReduce("reduceRight", "SimpleReduceRightSum", 12, | 237 testReduce("reduceRight", "SimpleReduceRightSum", 12, |
| 237 [[0, 6, 2, simpleArray, 6], | 238 [[0, 6, 2, simpleArray, 6], |
| 238 [6, 4, 1, simpleArray, 10], | 239 [6, 4, 1, simpleArray, 10], |
| 239 [10, 2, 0, simpleArray, 12]], | 240 [10, 2, 0, simpleArray, 12]], |
| 240 simpleArray, sum, 0); | 241 simpleArray, sum, 0); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 testReduce("reduceRight", "EmptySparseReduceRightSumNoInit", | 300 testReduce("reduceRight", "EmptySparseReduceRightSumNoInit", |
| 300 0, [], [,,0,,], sum); | 301 0, [], [,,0,,], sum); |
| 301 testReduce("reduceRight", "EmptySparseReduceRightProdNoInit", | 302 testReduce("reduceRight", "EmptySparseReduceRightProdNoInit", |
| 302 1, [], [,,1,,], prod); | 303 1, [], [,,1,,], prod); |
| 303 testReduce("reduceRight", "EmptySparseReduceRightDecNoInit", | 304 testReduce("reduceRight", "EmptySparseReduceRightDecNoInit", |
| 304 0, [], [,,0,,], dec); | 305 0, [], [,,0,,], dec); |
| 305 testReduce("reduceRight", "EmptySparseReduceRightAccumulateNoInit", | 306 testReduce("reduceRight", "EmptySparseReduceRightAccumulateNoInit", |
| 306 [], [], [,,[],,], accumulate); | 307 [], [], [,,[],,], accumulate); |
| 307 | 308 |
| 308 | 309 |
| 309 var verySparseSuffix6 = new Array(450001); | 310 var verySparseSuffix6 = []; |
| 310 verySparseSuffix6[450000] = 6; | 311 verySparseSuffix6[9000] = 6; |
| 311 var verySparseSuffix4 = new Array(450001); | 312 var verySparseSuffix4 = []; |
| 312 verySparseSuffix4[250000] = 4; | 313 verySparseSuffix4[5000] = 4; |
| 313 verySparseSuffix4[450000] = 6; | 314 verySparseSuffix4[9000] = 6; |
| 314 var verySparseSuffix2 = verySparseSlice6; | 315 var verySparseSuffix2 = verySparseSlice6; |
| 315 | 316 |
| 316 | 317 |
| 317 testReduce("reduceRight", "VerySparseReduceRightSum", 12, | 318 testReduce("reduceRight", "VerySparseReduceRightSum", 12, |
| 318 [[0, 6, 450000, verySparseArray, 6], | 319 [[0, 6, 9000, verySparseArray, 6], |
| 319 [6, 4, 250000, verySparseArray, 10], | 320 [6, 4, 5000, verySparseArray, 10], |
| 320 [10, 2, 100000, verySparseArray, 12]], | 321 [10, 2, 2000, verySparseArray, 12]], |
| 321 verySparseArray, sum, 0); | 322 verySparseArray, sum, 0); |
| 322 | 323 |
| 323 testReduce("reduceRight", "VerySparseReduceRightProd", 48, | 324 testReduce("reduceRight", "VerySparseReduceRightProd", 48, |
| 324 [[1, 6, 450000, verySparseArray, 6], | 325 [[1, 6, 9000, verySparseArray, 6], |
| 325 [6, 4, 250000, verySparseArray, 24], | 326 [6, 4, 5000, verySparseArray, 24], |
| 326 [24, 2, 100000, verySparseArray, 48]], | 327 [24, 2, 2000, verySparseArray, 48]], |
| 327 verySparseArray, prod, 1); | 328 verySparseArray, prod, 1); |
| 328 | 329 |
| 329 testReduce("reduceRight", "VerySparseReduceRightDec", Infinity, | 330 testReduce("reduceRight", "VerySparseReduceRightDec", Infinity, |
| 330 [[0, 6, 450000, verySparseArray, Infinity], | 331 [[0, 6, 9000, verySparseArray, Infinity], |
| 331 [Infinity, 4, 250000, verySparseArray, Infinity], | 332 [Infinity, 4, 5000, verySparseArray, Infinity], |
| 332 [Infinity, 2, 100000, verySparseArray, Infinity]], | 333 [Infinity, 2, 2000, verySparseArray, Infinity]], |
| 333 verySparseArray, dec, 0); | 334 verySparseArray, dec, 0); |
| 334 | 335 |
| 335 testReduce("reduceRight", "SimpleSparseReduceRightAccumulate", | 336 testReduce("reduceRight", "VerySparseReduceRightAccumulate", |
| 336 verySparseSuffix2, | 337 verySparseSuffix2, |
| 337 [[[], 6, 450000, verySparseArray, verySparseSuffix6], | 338 [[[], 6, 9000, verySparseArray, verySparseSuffix6], |
| 338 [verySparseSuffix6, 4, 250000, verySparseArray, verySparseSuffix4], | 339 [verySparseSuffix6, 4, 5000, verySparseArray, verySparseSuffix4], |
| 339 [verySparseSuffix4, 2, 100000, verySparseArray, verySparseSuffix2]], | 340 [verySparseSuffix4, 2, 2000, verySparseArray, verySparseSuffix2]], |
| 340 verySparseArray, accumulate, []); | 341 verySparseArray, accumulate, []); |
| 341 | 342 |
| 342 | 343 |
| 343 testReduce("reduceRight", "VerySparseReduceRightSumNoInit", 12, | 344 testReduce("reduceRight", "VerySparseReduceRightSumNoInit", 12, |
| 344 [[6, 4, 250000, verySparseArray, 10], | 345 [[6, 4, 5000, verySparseArray, 10], |
| 345 [10, 2, 100000, verySparseArray, 12]], | 346 [10, 2, 2000, verySparseArray, 12]], |
| 346 verySparseArray, sum); | 347 verySparseArray, sum); |
| 347 | 348 |
| 348 testReduce("reduceRight", "VerySparseReduceRightProdNoInit", 48, | 349 testReduce("reduceRight", "VerySparseReduceRightProdNoInit", 48, |
| 349 [[6, 4, 250000, verySparseArray, 24], | 350 [[6, 4, 5000, verySparseArray, 24], |
| 350 [24, 2, 100000, verySparseArray, 48]], | 351 [24, 2, 2000, verySparseArray, 48]], |
| 351 verySparseArray, prod); | 352 verySparseArray, prod); |
| 352 | 353 |
| 353 testReduce("reduceRight", "VerySparseReduceRightDecNoInit", Infinity, | 354 testReduce("reduceRight", "VerySparseReduceRightDecNoInit", Infinity, |
| 354 [[6, 4, 250000, verySparseArray, Infinity], | 355 [[6, 4, 5000, verySparseArray, Infinity], |
| 355 [Infinity, 2, 100000, verySparseArray, Infinity]], | 356 [Infinity, 2, 2000, verySparseArray, Infinity]], |
| 356 verySparseArray, dec); | 357 verySparseArray, dec); |
| 357 | 358 |
| 358 testReduce("reduceRight", "SimpleSparseReduceRightAccumulateNoInit", | 359 testReduce("reduceRight", "SimpleSparseReduceRightAccumulateNoInit", |
| 359 6, | 360 6, |
| 360 [[6, 4, 250000, verySparseArray, 6], | 361 [[6, 4, 5000, verySparseArray, 6], |
| 361 [6, 2, 100000, verySparseArray, 6]], | 362 [6, 2, 2000, verySparseArray, 6]], |
| 362 verySparseArray, accumulate); | 363 verySparseArray, accumulate); |
| 363 | 364 |
| 364 | 365 |
| 365 // undefined is an element | 366 // undefined is an element |
| 366 var undefArray = [,,undefined,,undefined,,]; | 367 var undefArray = [,,undefined,,undefined,,]; |
| 367 | 368 |
| 368 testReduce("reduce", "SparseUndefinedReduceAdd", NaN, | 369 testReduce("reduce", "SparseUndefinedReduceAdd", NaN, |
| 369 [[0, undefined, 2, undefArray, NaN], | 370 [[0, undefined, 2, undefArray, NaN], |
| 370 [NaN, undefined, 4, undefArray, NaN], | 371 [NaN, undefined, 4, undefArray, NaN], |
| 371 ], | 372 ], |
| 372 undefArray, sum, 0); | 373 undefArray, sum, 0); |
| 373 | 374 |
| 374 testReduce("reduceRight", "SparseUndefinedReduceRightAdd", NaN, | 375 testReduce("reduceRight", "SparseUndefinedReduceRightAdd", NaN, |
| 375 [[0, undefined, 4, undefArray, NaN], | 376 [[0, undefined, 4, undefArray, NaN], |
| 376 [NaN, undefined, 2, undefArray, NaN], | 377 [NaN, undefined, 2, undefArray, NaN], |
| 377 ], undefArray, sum, 0); | 378 ], undefArray, sum, 0); |
| 378 | 379 |
| 379 testReduce("reduce", "SparseUndefinedReduceAddNoInit", NaN, | 380 testReduce("reduce", "SparseUndefinedReduceAddNoInit", NaN, |
| 380 [[undefined, undefined, 4, undefArray, NaN], | 381 [[undefined, undefined, 4, undefArray, NaN], |
| 381 ], undefArray, sum); | 382 ], undefArray, sum); |
| 382 | 383 |
| 383 testReduce("reduceRight", "SparseUndefinedReduceRightAddNoInit", NaN, | 384 testReduce("reduceRight", "SparseUndefinedReduceRightAddNoInit", NaN, |
| 384 [[undefined, undefined, 2, undefArray, NaN], | 385 [[undefined, undefined, 2, undefArray, NaN], |
| 385 ], undefArray, sum); | 386 ], undefArray, sum); |
| 386 | 387 |
| 387 | 388 |
| 389 // Ignore non-array properties: |
| 390 |
| 391 var arrayPlus = [1,2,,3]; |
| 392 arrayPlus[-1] = NaN; |
| 393 arrayPlus[Math.pow(2,32)] = NaN; |
| 394 arrayPlus[NaN] = NaN; |
| 395 arrayPlus["00"] = NaN; |
| 396 arrayPlus["02"] = NaN; |
| 397 arrayPlus["-0"] = NaN; |
| 398 |
| 399 testReduce("reduce", "ArrayWithNonElementPropertiesReduce", 6, |
| 400 [[0, 1, 0, arrayPlus, 1], |
| 401 [1, 2, 1, arrayPlus, 3], |
| 402 [3, 3, 3, arrayPlus, 6], |
| 403 ], arrayPlus, sum, 0); |
| 404 |
| 388 // Test error conditions | 405 // Test error conditions |
| 389 | 406 |
| 390 try { | 407 try { |
| 391 [1].reduce("not a function"); | 408 [1].reduce("not a function"); |
| 392 fail("Reduce callback not a function not throwing"); | 409 fail("Reduce callback not a function not throwing"); |
| 393 } catch (e) { | 410 } catch (e) { |
| 394 assertTrue(e instanceof TypeError, | 411 assertTrue(e instanceof TypeError, |
| 395 "reduce callback not a function not throwing TypeError"); | 412 "reduce callback not a function not throwing TypeError"); |
| 396 assertEquals("called_non_callable", e.type, | 413 assertEquals("called_non_callable", e.type, |
| 397 "reduce non function TypeError type"); | 414 "reduce non function TypeError type"); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 } | 498 } |
| 482 | 499 |
| 483 var arr = [1, 2, 3, 4]; | 500 var arr = [1, 2, 3, 4]; |
| 484 testReduce("reduce", "ArrayManipulationExtender", 10, | 501 testReduce("reduce", "ArrayManipulationExtender", 10, |
| 485 [[0, 1, 0, [1, 2, 3, 4], 1], | 502 [[0, 1, 0, [1, 2, 3, 4], 1], |
| 486 [1, 2, 1, [1, 2, 3, 4, 4], 3], | 503 [1, 2, 1, [1, 2, 3, 4, 4], 3], |
| 487 [3, 3, 2, [1, 2, 3, 4, 4, 5], 6], | 504 [3, 3, 2, [1, 2, 3, 4, 4, 5], 6], |
| 488 [6, 4, 3, [1, 2, 3, 4, 4, 5, 6], 10], | 505 [6, 4, 3, [1, 2, 3, 4, 4, 5, 6], 10], |
| 489 ], arr, extender, 0); | 506 ], arr, extender, 0); |
| 490 | 507 |
| OLD | NEW |