IsValidIntegerIndex.js 749 B

12345678910111213141516171819202122232425262728
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var IsInteger = require('./IsInteger');
  4. var isNegativeZero = require('../helpers/isNegativeZero');
  5. var typedArrayBuffer = require('typed-array-buffer');
  6. // https://262.ecma-international.org/11.0/#sec-isvalidintegerindex
  7. module.exports = function IsValidIntegerIndex(O, index) {
  8. // Assert: O is an Integer-Indexed exotic object.
  9. typedArrayBuffer(O); // step 1
  10. if (typeof index !== 'number') {
  11. throw new $TypeError('Assertion failed: Type(index) is not Number'); // step 2
  12. }
  13. if (!IsInteger(index)) { return false; } // step 3
  14. if (isNegativeZero(index)) { return false; } // step 4
  15. if (index < 0 || index >= O.length) { return false; } // step 5
  16. return true; // step 6
  17. };