OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --harmony-arrays --harmony-classes | 5 // Flags: --harmony-arrays --harmony-classes |
6 | 6 |
7 (function testArrayConcatArity() { | 7 (function testArrayConcatArity() { |
8 "use strict"; | 8 "use strict"; |
9 assertEquals(1, Array.prototype.concat.length); | 9 assertEquals(1, Array.prototype.concat.length); |
10 })(); | 10 })(); |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 | 297 |
298 | 298 |
299 (function testConcatHoleySloppyArguments() { | 299 (function testConcatHoleySloppyArguments() { |
300 var args = (function(a) { return arguments; })(1,2,3); | 300 var args = (function(a) { return arguments; })(1,2,3); |
301 delete args[1]; | 301 delete args[1]; |
302 args[Symbol.isConcatSpreadable] = true; | 302 args[Symbol.isConcatSpreadable] = true; |
303 assertEquals([1, void 0, 3, 1, void 0, 3], [].concat(args, args)); | 303 assertEquals([1, void 0, 3, 1, void 0, 3], [].concat(args, args)); |
304 })(); | 304 })(); |
305 | 305 |
306 | 306 |
| 307 (function testConcatSpreadableStringWrapper() { |
| 308 "use strict"; |
| 309 var str1 = new String("yuck\uD83D\uDCA9") |
| 310 // String wrapper objects are not concat-spreadable by default |
| 311 assertEquals([str1], [].concat(str1)); |
| 312 |
| 313 // String wrapper objects may be individually concat-spreadable |
| 314 str1[Symbol.isConcatSpreadable] = true; |
| 315 assertEquals(["y", "u", "c", "k", "\uD83D", "\uDCA9"], |
| 316 [].concat(str1)); |
| 317 |
| 318 String.prototype[Symbol.isConcatSpreadable] = true; |
| 319 // String wrapper objects may be concat-spreadable |
| 320 assertEquals(["y", "u", "c", "k", "\uD83D", "\uDCA9"], |
| 321 [].concat(new String("yuck\uD83D\uDCA9"))); |
| 322 |
| 323 // String values are never concat-spreadable |
| 324 assertEquals(["yuck\uD83D\uDCA9"], [].concat("yuck\uD83D\uDCA9")); |
| 325 delete String.prototype[Symbol.isConcatSpreadable]; |
| 326 })(); |
| 327 |
| 328 |
| 329 (function testConcatSpreadableBooleanWrapper() { |
| 330 "use strict"; |
| 331 var bool = new Boolean(true) |
| 332 // Boolean wrapper objects are not concat-spreadable by default |
| 333 assertEquals([bool], [].concat(bool)); |
| 334 |
| 335 // Boolean wrapper objects may be individually concat-spreadable |
| 336 bool[Symbol.isConcatSpreadable] = true; |
| 337 bool.length = 3; |
| 338 bool[0] = 1, bool[1] = 2, bool[2] = 3; |
| 339 assertEquals([1, 2, 3], [].concat(bool)); |
| 340 |
| 341 Boolean.prototype[Symbol.isConcatSpreadable] = true; |
| 342 // Boolean wrapper objects may be concat-spreadable |
| 343 assertEquals([], [].concat(new Boolean(true))); |
| 344 Boolean.prototype[0] = 1; |
| 345 Boolean.prototype[1] = 2; |
| 346 Boolean.prototype[2] = 3; |
| 347 Boolean.prototype.length = 3; |
| 348 assertEquals([1,2,3], [].concat(new Boolean(true))); |
| 349 |
| 350 // Boolean values are never concat-spreadable |
| 351 assertEquals([true], [].concat(true)); |
| 352 delete Boolean.prototype[Symbol.isConcatSpreadable]; |
| 353 delete Boolean.prototype[0]; |
| 354 delete Boolean.prototype[1]; |
| 355 delete Boolean.prototype[2]; |
| 356 delete Boolean.prototype.length; |
| 357 })(); |
| 358 |
| 359 |
| 360 (function testConcatSpreadableNumberWrapper() { |
| 361 "use strict"; |
| 362 var num = new Number(true) |
| 363 // Number wrapper objects are not concat-spreadable by default |
| 364 assertEquals([num], [].concat(num)); |
| 365 |
| 366 // Number wrapper objects may be individually concat-spreadable |
| 367 num[Symbol.isConcatSpreadable] = true; |
| 368 num.length = 3; |
| 369 num[0] = 1, num[1] = 2, num[2] = 3; |
| 370 assertEquals([1, 2, 3], [].concat(num)); |
| 371 |
| 372 Number.prototype[Symbol.isConcatSpreadable] = true; |
| 373 // Number wrapper objects may be concat-spreadable |
| 374 assertEquals([], [].concat(new Number(123))); |
| 375 Number.prototype[0] = 1; |
| 376 Number.prototype[1] = 2; |
| 377 Number.prototype[2] = 3; |
| 378 Number.prototype.length = 3; |
| 379 assertEquals([1,2,3], [].concat(new Number(123))); |
| 380 |
| 381 // Number values are never concat-spreadable |
| 382 assertEquals([true], [].concat(true)); |
| 383 delete Number.prototype[Symbol.isConcatSpreadable]; |
| 384 delete Number.prototype[0]; |
| 385 delete Number.prototype[1]; |
| 386 delete Number.prototype[2]; |
| 387 delete Number.prototype.length; |
| 388 })(); |
| 389 |
| 390 |
| 391 (function testConcatSpreadableFunction() { |
| 392 "use strict"; |
| 393 var fn = function(a, b, c) {} |
| 394 // Functions are not concat-spreadable by default |
| 395 assertEquals([fn], [].concat(fn)); |
| 396 |
| 397 // Functions may be individually concat-spreadable |
| 398 fn[Symbol.isConcatSpreadable] = true; |
| 399 fn[0] = 1, fn[1] = 2, fn[2] = 3; |
| 400 assertEquals([1, 2, 3], [].concat(fn)); |
| 401 |
| 402 Function.prototype[Symbol.isConcatSpreadable] = true; |
| 403 // Functions may be concat-spreadable |
| 404 assertEquals([void 0, void 0, void 0], [].concat(function(a,b,c) {})); |
| 405 Function.prototype[0] = 1; |
| 406 Function.prototype[1] = 2; |
| 407 Function.prototype[2] = 3; |
| 408 assertEquals([1,2,3], [].concat(function(a, b, c) {})); |
| 409 |
| 410 delete Function.prototype[Symbol.isConcatSpreadable]; |
| 411 delete Function.prototype[0]; |
| 412 delete Function.prototype[1]; |
| 413 delete Function.prototype[2]; |
| 414 })(); |
| 415 |
| 416 |
| 417 (function testConcatSpreadableRegExp() { |
| 418 "use strict"; |
| 419 var re = /abc/; |
| 420 // RegExps are not concat-spreadable by default |
| 421 assertEquals([re], [].concat(re)); |
| 422 |
| 423 // RegExps may be individually concat-spreadable |
| 424 re[Symbol.isConcatSpreadable] = true; |
| 425 re[0] = 1, re[1] = 2, re[2] = 3, re.length = 3; |
| 426 assertEquals([1, 2, 3], [].concat(re)); |
| 427 |
| 428 // RegExps may be concat-spreadable |
| 429 RegExp.prototype[Symbol.isConcatSpreadable] = true; |
| 430 RegExp.prototype.length = 3; |
| 431 |
| 432 assertEquals([void 0, void 0, void 0], [].concat(/abc/)); |
| 433 RegExp.prototype[0] = 1; |
| 434 RegExp.prototype[1] = 2; |
| 435 RegExp.prototype[2] = 3; |
| 436 assertEquals([1,2,3], [].concat(/abc/)); |
| 437 |
| 438 delete RegExp.prototype[Symbol.isConcatSpreadable]; |
| 439 delete RegExp.prototype[0]; |
| 440 delete RegExp.prototype[1]; |
| 441 delete RegExp.prototype[2]; |
| 442 delete RegExp.prototype.length; |
| 443 })(); |
| 444 |
| 445 |
| 446 (function testArrayConcatSpreadableSparseObject() { |
| 447 "use strict"; |
| 448 var obj = { length: 5 }; |
| 449 obj[Symbol.isConcatSpreadable] = true; |
| 450 assertEquals([void 0, void 0, void 0, void 0, void 0], [].concat(obj)); |
| 451 |
| 452 obj.length = 4000; |
| 453 assertEquals(new Array(4000), [].concat(obj)); |
| 454 })(); |
| 455 |
| 456 |
307 // ES5 tests | 457 // ES5 tests |
308 (function testArrayConcatES5() { | 458 (function testArrayConcatES5() { |
309 "use strict"; | 459 "use strict"; |
310 var poses; | 460 var poses; |
311 var pos; | 461 var pos; |
312 | 462 |
313 poses = [140, 4000000000]; | 463 poses = [140, 4000000000]; |
314 while (pos = poses.shift()) { | 464 while (pos = poses.shift()) { |
315 var a = new Array(pos); | 465 var a = new Array(pos); |
316 var array_proto = []; | 466 var array_proto = []; |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 arr3.length = 10000; | 658 arr3.length = 10000; |
509 for (var i = 0; i < 100; i++) { | 659 for (var i = 0; i < 100; i++) { |
510 Object.defineProperty(arr3, i * i, {get: mkGetter(i)}); | 660 Object.defineProperty(arr3, i * i, {get: mkGetter(i)}); |
511 expectedTrace[i] = i; | 661 expectedTrace[i] = i; |
512 expectedTrace[100 + i] = i; | 662 expectedTrace[100 + i] = i; |
513 } | 663 } |
514 var r4 = [0].concat(arr3, arr3); | 664 var r4 = [0].concat(arr3, arr3); |
515 assertEquals(1 + arr3.length * 2, r4.length); | 665 assertEquals(1 + arr3.length * 2, r4.length); |
516 assertEquals(expectedTrace, trace); | 666 assertEquals(expectedTrace, trace); |
517 })(); | 667 })(); |
OLD | NEW |