bug_gh5667.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  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. // Test a bug fix for the xplat qsort implementation
  6. // https://github.com/Microsoft/ChakraCore/issues/5667
  7. function testArray(size)
  8. {
  9. // Create an array with all the same value
  10. const arr = new Array(size);
  11. arr.fill(100);
  12. // Change the second to last value to be smaller
  13. arr[arr.length - 2] = 99;
  14. // Sort the array
  15. arr.sort((a, b) => a - b);
  16. // Verify that the array is sorted
  17. for (let i = 1; i < arr.length; ++i)
  18. {
  19. if (arr[i] < arr[i - 1])
  20. {
  21. // Sort has not completed correctly
  22. throw new Error (`Array is not sorted correctly at index '${i}'`);
  23. }
  24. }
  25. }
  26. testArray(512);
  27. testArray(513);
  28. WScript.Echo("PASS");