-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
implementation.js
70 lines (59 loc) · 2.16 KB
/
implementation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
'use strict';
var $TypeError = require('es-errors/type');
var $Set = require('es-set/polyfill')();
var Call = require('es-abstract/2024/Call');
var GetIteratorFromMethod = require('es-abstract/2024/GetIteratorFromMethod');
var GetSetRecord = require('./aos/GetSetRecord');
var IteratorClose = require('es-abstract/2024/IteratorClose');
var IteratorStepValue = require('es-abstract/2024/IteratorStepValue');
var NormalCompletion = require('es-abstract/2024/NormalCompletion');
var ToBoolean = require('es-abstract/2024/ToBoolean');
var isSet = require('is-set');
var tools = require('es-set/tools');
var $setForEach = tools.forEach;
var $setHas = tools.has;
var $setSize = tools.size;
module.exports = function isDisjointFrom(other) {
var O = this; // step 1
// RequireInternalSlot(O, [[SetData]]); // step 2
if (!isSet(O) && !(O instanceof $Set)) {
throw new $TypeError('Method Set.prototype.isDisjointFrom called on incompatible receiver ' + O);
}
var otherRec = GetSetRecord(other); // step 3
var thisSize = $setSize(O); // SetDataSize(O.[[SetData]]); // step 4
if (thisSize <= otherRec['[[Size]]']) { // step 5
try {
$setForEach(O, function (e) {
var index = 0; // step 5.a
if (index < thisSize) { // step 5.a.i
index += 1; // step 5.a.ii
var inOther = ToBoolean(Call(otherRec['[[Has]]'], otherRec['[[SetObject]]'], [e])); // step 5.b.iii.1
if (inOther) {
// eslint-disable-next-line no-throw-literal
throw false; // step 5.b.iii.2, kinda
}
thisSize += $setSize(O); // step 5.b.iii.4
}
});
} catch (e) {
if (e === false) {
return false; // step 5.b.iii.2, the rest
}
throw e;
}
} else { // step 6
var keysIter = GetIteratorFromMethod(otherRec['[[SetObject]]'], otherRec['[[Keys]]']); // step 6.a
var next; // step 6.b
while (!keysIter['[[Done]]']) { // step 6.c
next = IteratorStepValue(keysIter); // step 6.c.i
if (!keysIter['[[Done]]']) { // step 6.c.ii
// if (SetDataHas(O.[[SetData]], nextValue)) { // step 6.c.ii.1
if ($setHas(O, next)) {
IteratorClose(keysIter, NormalCompletion()); // step 6.c.ii.1.a
return false; // step 6.c.ii.1.b
}
}
}
}
return true; // step 7
};