concat2.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. function echo(v) {
  6. WScript.Echo(v);
  7. }
  8. function guarded_call(func) {
  9. try {
  10. func();
  11. } catch (e) {
  12. echo(e.name + " : " + e.message);
  13. }
  14. }
  15. function dump_array(arr) {
  16. echo("length: " + arr.length);
  17. for (var p in arr) {
  18. echo(" " + p + ": " + arr[p]);
  19. }
  20. }
  21. function test_concat(size) {
  22. guarded_call(function () {
  23. var arr = new Array(size);
  24. arr[size - 1] = 100;
  25. echo("- concat 101, 102, 103, 104, 105");
  26. arr = arr.concat(101, 102, 103, 104, 105);
  27. dump_array(arr);
  28. echo("- arr.concat(arr)");
  29. arr = arr.concat(arr);
  30. dump_array(arr);
  31. });
  32. }
  33. echo("-------concat Small-------------");
  34. test_concat(500);
  35. // Fix for MSRC 33319 changes concat to skip a fast path if the index we're copying into is a BigIndex.
  36. // Disable the large portion of this test since this change makes such a test run for hours.
  37. //echo("-------concat Large-------------");
  38. //test_concat(4294967294);
  39. echo("-------test prototype lookup-------------");
  40. for (var i = 0; i < 10; i++) {
  41. Array.prototype[i] = 100 + i;
  42. }
  43. delete Array.prototype[3];
  44. var a = [200, 201, 202, 203, 204];
  45. delete a[1];
  46. a[7] = 207;
  47. echo("a: " + a);
  48. var r = a.concat(300, 301, 302, 303, 304);
  49. echo("r: " + r);
  50. delete r[8];
  51. echo("r: " + r); // Now r[8] should come from prototype
  52. for (var i = 0; i < 10; i++) {
  53. delete Array.prototype[i];
  54. }
  55. echo("r: " + r); // r[8] gone, other entries not affected (verify not from prototype)