CopyOnAccessArray_bugs.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. //Note: see function ArraySpliceHelper of JavascriptArray.cpp
  6. if (this.WScript && this.WScript.LoadScriptFile) { // Check for running in ch
  7. this.WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
  8. }
  9. var tests = [
  10. {
  11. name: "Calling Array.prototype.slice()",
  12. body: function ()
  13. {
  14. var a=[1,2,3,4,5];
  15. var b=Array.prototype.slice.call(a,1,3);
  16. assert.areEqual([2,3], b, "Incorrect result from Array.prototype.slice()");
  17. }
  18. },
  19. {
  20. name: "Calling Array.prototype.push()",
  21. body: function ()
  22. {
  23. var a=[1,2];
  24. Array.prototype.push.call(a,1);
  25. assert.areEqual([1,2,1], a, "Incorrect result from Array.prototype.push()");
  26. }
  27. },
  28. {
  29. name: "Calling Array.isArray()",
  30. body: function ()
  31. {
  32. var a=[1,2,3,4,5,6,7];
  33. assert.areEqual(true, Array.isArray(a), "Incorrect result from Array.isArray()");
  34. }
  35. },
  36. {
  37. name: "Calling Array.prototype.unshift()",
  38. body: function ()
  39. {
  40. var a=[2,1,3,4];
  41. Array.prototype.unshift.call(a,0);
  42. assert.areEqual([0,2,1,3,4], a, "Incorrect result from Array.prototype.unshift()");
  43. }
  44. },
  45. {
  46. name: "Calling Array.prototype.shift()",
  47. body: function ()
  48. {
  49. var a=[1,2,3,4];
  50. var c=Array.prototype.shift.call(a);
  51. assert.areEqual([2,3,4], a, "Incorrect result from Array.prototype.shift()");
  52. assert.areEqual(1, c, "Incorrect result from Array.prototype.shift()");
  53. }
  54. },
  55. {
  56. name: "Calling Array.prototype.entries()",
  57. body: function ()
  58. {
  59. var a=[1,2,3,4];
  60. var c=Array.prototype.entries.call(a);
  61. for (var e of c)
  62. {
  63. print(e);
  64. }
  65. }
  66. },
  67. {
  68. name: "Calling Array.prototype.keys()",
  69. body: function ()
  70. {
  71. var a=[1,2,3,4];
  72. var c=Array.prototype.keys.call(a);
  73. for (var e of c)
  74. {
  75. print(e);
  76. }
  77. }
  78. },
  79. {
  80. name: "Calling Array.prototype.reverse()",
  81. body: function ()
  82. {
  83. var a=[1,2,3,4];
  84. Array.prototype.reverse.call(a);
  85. assert.areEqual([4,3,2,1], a, "Incorrect result from Array.prototype.reverse()");
  86. }
  87. },
  88. {
  89. name: "Calling Object.prototype.toString()",
  90. body: function ()
  91. {
  92. var a=[1,2,3,4,5,6];
  93. var c=Object.prototype.toString.call(a);
  94. assert.areEqual("[object Array]", c, "Incorrect result from Object.prototype.toString()");
  95. }
  96. },
  97. {
  98. name: "Calling Object.prototype.hasOwnProperty()",
  99. body: function ()
  100. {
  101. var a=[1,2,3,4,5,6];
  102. var c=Object.prototype.hasOwnProperty.call(a, 1);
  103. assert.areEqual(c, true);
  104. }
  105. },
  106. {
  107. name: "OS3713376: Accessing COA through proxy",
  108. body: function ()
  109. {
  110. var p = new Proxy([0,0,0,0,0], {});
  111. p.length = 1;
  112. assert.areEqual('0', p.toString(), 'Setting length of an array through Proxy');
  113. var q = new Proxy([0,0,0,0,0], {});
  114. q[0] = 1;
  115. assert.areEqual('1,0,0,0,0', q.toString(), 'Setting array element through Proxy');
  116. }
  117. },
  118. {
  119. name: "Reflect.defineProperty",
  120. body: function ()
  121. {
  122. var b = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
  123. Reflect.defineProperty(b, "length", {value: 0});
  124. assert.areEqual(b.length, 0, "Setting length property to 0");
  125. }
  126. },
  127. {
  128. name: "Reflect.set",
  129. body: function ()
  130. {
  131. assert.isTrue(Reflect.set([1950, 1960, 1970, 1980, 1990], "0", 1), "Should be able to set property on int array");
  132. assert.isTrue(Reflect.set([1950, 1960.1, 1970, 1980, 1990], "0", 1), "Should be able to set property on float array");
  133. }
  134. },
  135. {
  136. name: "Array.of",
  137. body: function ()
  138. {
  139. var target = [1,2,3,4,5];
  140. function constructor()
  141. {
  142. return target;
  143. }
  144. var a = Array.of.call(constructor);
  145. assert.areEqual(a, [], "Array.of.call with custom constructor");
  146. }
  147. }
  148. ];
  149. testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });