LengthOfArrayLike.js 495 B

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