diff --git a/package.json b/package.json index e528f8d..8b6bdcc 100644 --- a/package.json +++ b/package.json @@ -78,6 +78,7 @@ "evalmd": "^0.0.19", "for-each": "^0.3.3", "functions-have-names": "^1.2.3", + "has-property-descriptors": "^1.0.1", "has-strict-mode": "^1.0.1", "in-publish": "^2.0.1", "npmignore": "^0.3.0", diff --git a/test/tests.js b/test/tests.js index c4534ad..ff830eb 100644 --- a/test/tests.js +++ b/test/tests.js @@ -4,6 +4,7 @@ var $Set = require('es-set/polyfill')(); var forEach = require('for-each'); var v = require('es-value-fixtures'); var debug = require('object-inspect'); +var hasPropertyDescriptors = require('has-property-descriptors')(); module.exports = function (isSubsetOf, t) { t.test('throws on non-set receivers', function (st) { @@ -81,6 +82,66 @@ module.exports = function (isSubsetOf, t) { st.end(); }); + t.test('test262: setlike with equal size', function (st) { + var setLike = { + arr: [42, 44, 45], + size: 3, + keys: function () { + return this.arr[Symbol.iterator](); + }, + has: function (key) { + return this.arr.indexOf(key) !== -1; + } + }; + + var firstSet = new $Set([42, 43, 45]); + + st.equal(isSubsetOf(firstSet, setLike), false); + + st.end(); + }); + + t.test('test262: set method receiver is cleared', { skip: !hasPropertyDescriptors }, function (st) { + var firstSet = new $Set([42, 43]); + + var otherSet = new $Set([42, 43, 47]); + + Object.defineProperty(otherSet, 'size', { + get: function () { + firstSet.clear(); + return 3; + } + }); + + st.equal(isSubsetOf(firstSet, otherSet), true); + + st.end(); + }); + + t.test('test262: set method after table transition in receiver', function (st) { + var firstSet = new Set([42, 43, 44]); + + var setLike = { + size: 5, + keys: function () { + return [1, 2, 3, 4, 5].keys(); + }, + has: function (key) { + if (key === 42) { + // Cause a table transition in the receiver. + firstSet.clear(); + } + // Return true so we keep iterating the transitioned receiver. + return true; + } + }; + + st.equal(firstSet.isSubsetOf(setLike), true); + st.equal(firstSet.size, 0); + + st.end(); + }); + t.test('subsets', function (st) { var set1 = new $Set([1, 2, 3]); var set2 = new $Set([4, 5, 6]);