SetDataSize.js 689 B

123456789101112131415161718192021222324252627282930
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var forEach = require('../helpers/forEach');
  4. var isArray = require('../helpers/IsArray');
  5. // https://262.ecma-international.org/16.0/#sec-setdatasize
  6. // TODO: when spec enums are unforgeable, uncomment ~EMPTY~ check
  7. module.exports = function SetDataSize(setData) {
  8. if (!isArray(setData) && setData !== 'EMPTY') {
  9. throw new $TypeError('Assertion failed: `setData` must be a List or ~EMPTY~');
  10. }
  11. if (setData === 'EMPTY') {
  12. return 0;
  13. }
  14. var count = 0; // step 1
  15. forEach(setData, function (e, i) { // step 2
  16. if (i in setData /* && e !== ~EMPTY~ */) {
  17. count += 1; // step 2.a
  18. }
  19. });
  20. return count; // step 3
  21. };