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