LengthOfArrayLike.js 447 B

123456789101112131415161718
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var Get = require('./Get');
  4. var ToLength = require('./ToLength');
  5. var Type = require('./Type');
  6. // https://262.ecma-international.org/11.0/#sec-lengthofarraylike
  7. module.exports = function LengthOfArrayLike(obj) {
  8. if (Type(obj) !== 'Object') {
  9. throw new $TypeError('Assertion failed: `obj` must be an Object');
  10. }
  11. return ToLength(Get(obj, 'length'));
  12. };
  13. // TODO: use this all over