Bug 1892041 - Part 2: Update test262. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / built-ins / Set / prototype / symmetricDifference / subclass-receiver-methods.js
blob03a30d8b541c29d9b84a8e08ff30ec932bd08c9c
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.
4 /*---
5 esid: sec-set.prototype.symmetricdifference
6 description: Set.prototype.symmetricDifference works on subclasses of Set, but never calls the receiver's size/has/keys methods
7 features: [set-methods]
8 includes: [compareArray.js]
9 ---*/
11 let sizeCount = 0;
12 let hasCount = 0;
13 let keysCount = 0;
15 class MySet extends Set {
16   size(...rest) {
17     sizeCount++;
18     return super.size(...rest);
19   }
21   has(...rest) {
22     hasCount++;
23     return super.has(...rest);
24   }
26   keys(...rest) {
27     keysCount++;
28     return super.keys(...rest);
29   }
32 const s1 = new MySet([1, 2]);
33 const s2 = new Set([2, 3]);
34 const expected = [1, 3];
35 const combined = s1.symmetricDifference(s2);
37 assert.compareArray([...combined], expected);
38 assert.sameValue(combined instanceof Set, true, "The returned object is a Set");
39 assert.sameValue(
40   combined instanceof MySet,
41   false,
42   "The returned object is a Set, not a subclass"
44 assert.sameValue(sizeCount, 0, "size should not be called on the receiver");
45 assert.sameValue(hasCount, 0, "has should not be called on the receiver");
46 assert.sameValue(keysCount, 0, "keys should not be called on the receiver");
48 reportCompare(0, 0);