array_indexOfSparse.js 1.2 KB

123456789101112131415161718192021222324252627
  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. // Verify that the starting index param to indexOf is respected for sparse arrays
  6. var a = new Array(0, 1);
  7. a[4294967294] = 2; // 2^32-2 - is max array element
  8. a[4294967295] = 3; // 2^32-1 added as non-array element property
  9. a[4294967296] = 4; // 2^32 added as non-array element property
  10. a[4294967297] = 5; // 2^32+1 added as non-array element property
  11. print(a.indexOf(2, 4294967290)); // === 4294967294 &&
  12. print(a.indexOf(3, 4294967290)); // === -1 &&
  13. print(a.indexOf(4, 4294967290)); // === -1 &&
  14. print(a.indexOf(5, 4294967290)); // === -1 ) ;
  15. a[1111111] = 2;
  16. a[1111112] = 3;
  17. a[1111113] = 4;
  18. a[1111114] = 5;
  19. print(a.indexOf(2, 4294967290)); // === 4294967294 &&
  20. print(a.indexOf(3, 4294967290)); // === -1 &&
  21. print(a.indexOf(4, 4294967290)); // === -1 &&
  22. print(a.indexOf(5, 4294967290)); // === -1 ) ;