1 // |reftest| skip -- set-methods is not supported
2 // Copyright (C) 2023 Anthony Frehner and Kevin Gibbons. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
5 esid: sec-set.prototype.symmetricdifference
6 description: Set.prototype.symmetricDifference calls a Set-like class's methods in order
7 features: [set-methods]
8 includes: [compareArray.js]
11 let observedOrder = [];
13 function observableIterator() {
14 let values = ["a", "b", "c"];
18 observedOrder.push("getting next");
20 observedOrder.push("calling next");
23 observedOrder.push("getting done");
24 return index >= values.length;
27 observedOrder.push("getting value");
28 return values[index++];
38 observedOrder.push("getting size");
40 valueOf: function () {
41 observedOrder.push("ToNumber(size)");
47 observedOrder.push("getting has");
49 throw new Test262Error("Set.prototype.symmetricDifference should not invoke .has on its argument");
53 observedOrder.push("getting keys");
55 observedOrder.push("calling keys");
56 return observableIterator();
61 // this is smaller than argument
65 const s1 = new Set(["a", "d"]);
66 const s2 = new MySetLike();
67 const combined = s1.symmetricDifference(s2);
69 const expectedOrder = [
76 // first iteration, has value
80 // second iteration, has value
84 // third iteration, has value
88 // fourth iteration, no value; ends
93 assert.compareArray([...combined], ["d", "b", "c"]);
94 assert.compareArray(observedOrder, expectedOrder);
97 // this is same size as argument
101 const s1 = new Set(["a", "b", "d"]);
102 const s2 = new MySetLike();
103 const combined = s1.symmetricDifference(s2);
105 const expectedOrder = [
112 // first iteration, has value
116 // second iteration, has value
120 // third iteration, has value
124 // fourth iteration, no value; ends
129 assert.compareArray([...combined], ["d", "c"]);
130 assert.compareArray(observedOrder, expectedOrder);
133 // this is larger than argument
137 const s1 = new Set(["a", "b", "d", "e"]);
138 const s2 = new MySetLike();
139 const combined = s1.symmetricDifference(s2);
141 const expectedOrder = [
148 // first iteration, has value
152 // second iteration, has value
156 // third iteration, has value
160 // fourth iteration, no value; ends
165 assert.compareArray([...combined], ["d", "e", "c"]);
166 assert.compareArray(observedOrder, expectedOrder);