array_indexOf.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. var x = [1, 2, 2, 4, 5, +0, -0, NaN, 0, true, true , false]
  6. for(i=-3; i < 15;i++)
  7. {
  8. WScript.Echo(x.indexOf(i));
  9. for(j=-3; j< 15;j++)
  10. {
  11. WScript.Echo(x.indexOf(x[i],j));
  12. WScript.Echo(x.indexOf(i,j));
  13. }
  14. }
  15. var b = function(){};
  16. b.prototype = Array.prototype;
  17. var y = new b();
  18. var z = new Object();
  19. var a = new Object();
  20. y[0] = "abc";
  21. y[1] = "def";
  22. y[2] = "efg";
  23. y[3] = true;
  24. y[4] = true;
  25. y[5] = false;
  26. y[6] = a;
  27. y[7] = a;
  28. y[8] = null;
  29. y.length = 10;
  30. WScript.Echo(y.indexOf("abc"));
  31. WScript.Echo(y.indexOf("abc", 3));
  32. WScript.Echo(y.indexOf("abc", 2));
  33. WScript.Echo(y.indexOf("abc", -2));
  34. WScript.Echo(y.indexOf("efg"));
  35. WScript.Echo(y.indexOf("efg", 6));
  36. WScript.Echo(y.indexOf("efg", 1));
  37. WScript.Echo(y.indexOf("efg", -3));
  38. WScript.Echo(y.indexOf("xyg"));
  39. WScript.Echo(y.indexOf("esg", 2));
  40. WScript.Echo(y.indexOf("eag", 2));
  41. WScript.Echo(y.indexOf("", -2));
  42. WScript.Echo(y.indexOf(true));
  43. WScript.Echo(y.indexOf(false));
  44. WScript.Echo(y.indexOf(new Boolean(true)));
  45. WScript.Echo(y.indexOf(a , 6));
  46. WScript.Echo(y.indexOf(a , 1));
  47. WScript.Echo(y.indexOf(a ));
  48. WScript.Echo(y.indexOf(b));
  49. WScript.Echo(y.indexOf(null));
  50. WScript.Echo(y.indexOf());
  51. //implicit calls
  52. var a ;
  53. var arr = [10];
  54. Object.defineProperty(Array.prototype, "4", {configurable : true, get: function(){a = true; return 30;}});
  55. a = false;
  56. arr.length = 6;
  57. var f = arr.indexOf(30);
  58. WScript.Echo(a);
  59. //Float array with gaps
  60. var floatarr = new Array(5.5, 5.6);
  61. floatarr[6] = 5.6;
  62. WScript.Echo(floatarr.indexOf(5.7));
  63. // Cases where we do/don't have to resume after failing to find the value in the head segment.
  64. // Run with -forcearraybtree to really stress these.
  65. var gap = [0, 1];
  66. WScript.Echo(gap.indexOf(4));
  67. Array.prototype[2] = 'foo';
  68. WScript.Echo(gap.indexOf('foo'));
  69. gap[5] = 4;
  70. WScript.Echo(gap.indexOf('foo'));
  71. WScript.Echo(gap.indexOf(4));
  72. gap = [0, 1.1];
  73. WScript.Echo(gap.indexOf(4));
  74. Array.prototype[2] = 'bar';
  75. WScript.Echo(gap.indexOf('bar'));
  76. gap[5] = 4;
  77. WScript.Echo(gap.indexOf(4));
  78. WScript.Echo(gap.indexOf('bar'));
  79. gap = [0, 'test'];
  80. WScript.Echo(gap.indexOf(4));
  81. Array.prototype[2] = 4;
  82. WScript.Echo(gap.indexOf(4));
  83. gap[5] = 4;
  84. WScript.Echo(gap.indexOf(4));
  85. delete Array.prototype[2]
  86. WScript.Echo(gap.indexOf(4));