-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimplementation.js
68 lines (51 loc) · 1.97 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
'use strict';
// Note: the commented out code is because there is no performant way in userland to do the optimization in step 7.
var $TypeError = require('es-errors/type');
var $Set = require('es-set/polyfill')();
var GetIteratorFromMethod = require('es-abstract/2024/GetIteratorFromMethod');
var GetSetRecord = require('./aos/GetSetRecord');
var IteratorStepValue = require('es-abstract/2024/IteratorStepValue');
// var SetDataHas = require('./aos/SetDataHas');
var isSet = require('is-set');
var tools = require('es-set/tools');
var $setAdd = tools.add;
var $setDelete = tools['delete'];
var $setForEach = tools.forEach;
var $setHas = tools.has;
module.exports = function symmetricDifference(other) {
var O = this; // step 1
// RequireInternalSlot(O, [[SetData]]); // step 2
if (!isSet(O) && !(O instanceof $Set)) {
throw new $TypeError('Method Set.prototype.symmetricDifference called on incompatible receiver ' + O);
}
var otherRec = GetSetRecord(other); // step 3
var keysIter = GetIteratorFromMethod(otherRec['[[SetObject]]'], otherRec['[[Keys]]']); // step 4
var result = new $Set();
$setForEach(O, function (value) {
$setAdd(result, value);
});
var next; // step 6
while (!keysIter['[[Done]]']) { // step 7
next = IteratorStepValue(keysIter); // step 7.a
if (!keysIter['[[Done]]']) { // step 7.b
if (next === 0) { // step 7.b.i
next = +0;
}
// Let resultIndex be SetDataIndex(resultSetData, next). // step 7.b.ii
var inResult = $setHas(result, next);
// if (SetDataHas(O.[[SetData]], next)) { // step 7.b.iii
if ($setHas(O, next)) { // step 7.b.iii
if (inResult) {
// remove next from resultSetData. // step 7.b.iii.1
$setDelete(result, next);
}
} else if (!inResult) {
// append nextValue to resultSetData // step 7.b.iii.2
$setAdd(result, next);
}
}
}
// var result = OrdinaryObjectCreate(%Set.prototype%, « [[SetData]] »); // step 8
// result.[[SetData]] = resultSetData; // step 9
return result; // step 10
};