get-set-record.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. var aCallable = require('../internals/a-callable');
  2. var anObject = require('../internals/an-object');
  3. var call = require('../internals/function-call');
  4. var toIntegerOrInfinity = require('../internals/to-integer-or-infinity');
  5. var $TypeError = TypeError;
  6. var SetRecord = function (set, size, has, keys) {
  7. this.set = set;
  8. this.size = size;
  9. this.has = has;
  10. this.keys = keys;
  11. };
  12. SetRecord.prototype = {
  13. getIterator: function () {
  14. return anObject(call(this.keys, this.set));
  15. },
  16. includes: function (it) {
  17. return call(this.has, this.set, it);
  18. }
  19. };
  20. // `GetSetRecord` abstract operation
  21. // https://tc39.es/proposal-set-methods/#sec-getsetrecord
  22. module.exports = function (obj) {
  23. anObject(obj);
  24. var numSize = +obj.size;
  25. // NOTE: If size is undefined, then numSize will be NaN
  26. // eslint-disable-next-line no-self-compare -- NaN check
  27. if (numSize != numSize) throw $TypeError('Invalid size');
  28. return new SetRecord(
  29. obj,
  30. toIntegerOrInfinity(numSize),
  31. aCallable(obj.has),
  32. aCallable(obj.keys)
  33. );
  34. };