SliceandConcatAlterOriginalArrayBug.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. if (this.WScript && this.WScript.LoadScriptFile) { // Check for running in ch
  6. this.WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
  7. }
  8. var tests = [
  9. {
  10. name: "concat Bug",
  11. body: function ()
  12. {
  13. Array.prototype.length = 0;
  14. Array.prototype[0]="start";
  15. Array.prototype[1]="p1";
  16. Array.prototype[2]="p2";
  17. Array.prototype[3]="p3";
  18. Array.prototype[4]="p4";
  19. Array.prototype[5]="p5";
  20. Array.prototype[7]="p6";
  21. var arr = new Array();
  22. arr[3]="test";
  23. arr[4]=12;
  24. arr[6]=345;
  25. arr.concat(Array.prototype);
  26. delete Array.prototype[0];
  27. delete Array.prototype[3];
  28. delete Array.prototype[4];
  29. //Resulting Array from concat should look up the prototype
  30. assert.areEqual([,"p1","p2","test",12,"p5",345,"p6","p1","p2",,,"p5",,"p6"], arr.concat(Array.prototype));
  31. }
  32. },
  33. {
  34. name: "slice Bug",
  35. body: function ()
  36. {
  37. var retarr = new Array();
  38. var arr=new Array(2)
  39. arr[0]=0;
  40. Array.prototype[1]="p"+1;
  41. retarr[1]=arr;
  42. var result = retarr[1].slice(-2,2);
  43. for(var i=0;i<Array.prototype.length;i++)
  44. {
  45. delete Array.prototype[i];
  46. }
  47. assert.areEqual([0,undefined].toString(),retarr[1].toString());
  48. }
  49. }
  50. ];
  51. testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });