set.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. // Big thanks to V8 folks for test ideas.
  2. // v8/test/mjsunit/harmony/collections.js
  3. var Assertion = expect().constructor;
  4. Assertion.addMethod('theSameSet', function (otherArray) {
  5. var array = this._obj;
  6. expect(Array.isArray(array)).to.equal(true);
  7. expect(Array.isArray(otherArray)).to.equal(true);
  8. var diff = array.filter(function (value) {
  9. return otherArray.every(function (otherValue) {
  10. var areBothNaN = typeof value === 'number' && typeof otherValue === 'number' && value !== value && otherValue !== otherValue;
  11. return !areBothNaN && value !== otherValue;
  12. });
  13. });
  14. this.assert(
  15. diff.length === 0,
  16. 'expected #{this} to be equal to #{exp} (as sets, i.e. no order)',
  17. array,
  18. otherArray
  19. );
  20. });
  21. var $iterator$ = typeof Symbol === 'function' ? Symbol.iterator : '_es6-shim iterator_';
  22. if (typeof Set === 'function' && typeof Set.prototype['@@iterator'] === 'function') {
  23. $iterator$ = '@@iterator';
  24. }
  25. Assertion.addMethod('iterations', function (expected) {
  26. var iterator = this._obj[$iterator$]();
  27. expect(Array.isArray(expected)).to.equal(true);
  28. var expectedValues = expected.slice();
  29. var result;
  30. do {
  31. result = iterator.next();
  32. expect(result.value).to.eql(expectedValues.shift());
  33. } while (!result.done);
  34. });
  35. describe('Set', function () {
  36. var functionsHaveNames = (function foo() {}).name === 'foo';
  37. var ifFunctionsHaveNamesIt = functionsHaveNames ? it : xit;
  38. var ifShimIt = (typeof process !== 'undefined' && process.env.NO_ES6_SHIM) ? it.skip : it;
  39. var ifGetPrototypeOfIt = Object.getPrototypeOf ? it : xit;
  40. var range = function (from, to) {
  41. var result = [];
  42. for (var value = from; value < to; value++) {
  43. result.push(value);
  44. }
  45. return result;
  46. };
  47. var prototypePropIsEnumerable = Object.prototype.propertyIsEnumerable.call(function () {}, 'prototype');
  48. var expectNotEnumerable = function (object) {
  49. if (prototypePropIsEnumerable && typeof object === 'function') {
  50. expect(Object.keys(object)).to.eql(['prototype']);
  51. } else {
  52. expect(Object.keys(object)).to.eql([]);
  53. }
  54. };
  55. var Sym = typeof Symbol === 'undefined' ? {} : Symbol;
  56. var isSymbol = function (sym) {
  57. return typeof Sym === 'function' && typeof sym === 'symbol';
  58. };
  59. var ifSymbolIteratorIt = isSymbol(Sym.iterator) ? it : xit;
  60. var testSet = function (set, key) {
  61. expect(set.has(key)).to.equal(false);
  62. expect(set['delete'](key)).to.equal(false);
  63. expect(set.add(key)).to.equal(set);
  64. expect(set.has(key)).to.equal(true);
  65. expect(set['delete'](key)).to.equal(true);
  66. expect(set.has(key)).to.equal(false);
  67. expect(set.add(key)).to.equal(set); // add it back
  68. };
  69. if (typeof Set === 'undefined') {
  70. return it('exists', function () {
  71. expect(typeof Set).to.equal('function');
  72. });
  73. }
  74. var set;
  75. beforeEach(function () {
  76. set = new Set();
  77. });
  78. afterEach(function () {
  79. set = null;
  80. });
  81. it('set iteration', function () {
  82. expect(set.add('a')).to.equal(set);
  83. expect(set.add('b')).to.equal(set);
  84. expect(set.add('c')).to.equal(set);
  85. expect(set.add('d')).to.equal(set);
  86. var keys = [];
  87. var iterator = set.keys();
  88. keys.push(iterator.next().value);
  89. expect(set['delete']('a')).to.equal(true);
  90. expect(set['delete']('b')).to.equal(true);
  91. expect(set['delete']('c')).to.equal(true);
  92. expect(set.add('e')).to.equal(set);
  93. keys.push(iterator.next().value);
  94. keys.push(iterator.next().value);
  95. expect(iterator.next().done).to.equal(true);
  96. expect(set.add('f')).to.equal(set);
  97. expect(iterator.next().done).to.equal(true);
  98. expect(keys).to.eql(['a', 'd', 'e']);
  99. });
  100. ifShimIt('is on the exported object', function () {
  101. var exported = require('../');
  102. expect(exported.Set).to.equal(Set);
  103. });
  104. it('should exist in global namespace', function () {
  105. expect(typeof Set).to.equal('function');
  106. });
  107. it('has the right arity', function () {
  108. expect(Set).to.have.property('length', 0);
  109. });
  110. it('returns the set from #add() for chaining', function () {
  111. expect(set.add({})).to.equal(set);
  112. });
  113. it('should return false when deleting an item not in the set', function () {
  114. expect(set.has('a')).to.equal(false);
  115. expect(set['delete']('a')).to.equal(false);
  116. });
  117. it('should accept an iterable as argument', function () {
  118. testSet(set, 'a');
  119. testSet(set, 'b');
  120. var set2 = new Set(set);
  121. expect(set2.has('a')).to.equal(true);
  122. expect(set2.has('b')).to.equal(true);
  123. expect(set2).to.have.iterations(['a', 'b']);
  124. });
  125. it('accepts an array as an argument', function () {
  126. var arr = ['a', 'b', 'c'];
  127. var setFromArray = new Set(arr);
  128. expect(setFromArray).to.have.iterations(['a', 'b', 'c']);
  129. });
  130. it('should not be callable without "new"', function () {
  131. expect(Set).to['throw'](TypeError);
  132. });
  133. it('should be subclassable', function () {
  134. if (!Object.setPrototypeOf) { return; } // skip test if on IE < 11
  135. var MySet = function MySet() {
  136. var actualSet = new Set(['a', 'b']);
  137. Object.setPrototypeOf(actualSet, MySet.prototype);
  138. return actualSet;
  139. };
  140. Object.setPrototypeOf(MySet, Set);
  141. MySet.prototype = Object.create(Set.prototype, {
  142. constructor: { value: MySet }
  143. });
  144. var mySet = new MySet();
  145. testSet(mySet, 'c');
  146. testSet(mySet, 'd');
  147. expect(mySet).to.have.iterations(['a', 'b', 'c', 'd']);
  148. });
  149. it('should has valid getter and setter calls', function () {
  150. ['add', 'has', 'delete'].forEach(function (method) {
  151. expect(function () {
  152. set[method]({});
  153. }).to.not['throw']();
  154. });
  155. });
  156. it('uses SameValueZero even on a Set of size > 4', function () {
  157. var firstFour = [1, 2, 3, 4];
  158. var fourSet = new Set(firstFour);
  159. expect(fourSet.size).to.equal(4);
  160. expect(fourSet.has(-0)).to.equal(false);
  161. expect(fourSet.has(0)).to.equal(false);
  162. fourSet.add(-0);
  163. expect(fourSet.size).to.equal(5);
  164. expect(fourSet.has(0)).to.equal(true);
  165. expect(fourSet.has(-0)).to.equal(true);
  166. });
  167. it('should work as expected', function () {
  168. // Run this test twice, one with the "fast" implementation (which only
  169. // allows string and numeric keys) and once with the "slow" impl.
  170. [true, false].forEach(function (slowkeys) {
  171. set = new Set();
  172. range(1, 20).forEach(function (number) {
  173. if (slowkeys) { testSet(set, {}); }
  174. testSet(set, number);
  175. testSet(set, number / 100);
  176. testSet(set, 'key-' + number);
  177. testSet(set, String(number));
  178. if (slowkeys) { testSet(set, Object(String(number))); }
  179. });
  180. var testkeys = [+0, Infinity, -Infinity, NaN];
  181. if (slowkeys) {
  182. testkeys.push(true, false, null, undefined);
  183. }
  184. testkeys.forEach(function (number) {
  185. testSet(set, number);
  186. testSet(set, String(number));
  187. });
  188. testSet(set, '');
  189. // -0 and +0 should be the same key (Set uses SameValueZero)
  190. expect(set.has(-0)).to.equal(true);
  191. expect(set['delete'](+0)).to.equal(true);
  192. testSet(set, -0);
  193. expect(set.has(+0)).to.equal(true);
  194. // verify that properties of Object don't peek through.
  195. [
  196. 'hasOwnProperty',
  197. 'constructor',
  198. 'toString',
  199. 'isPrototypeOf',
  200. '__proto__',
  201. '__parent__',
  202. '__count__'
  203. ].forEach(function (prop) { testSet(set, prop); });
  204. });
  205. });
  206. describe('#size', function () {
  207. it('returns the expected size', function () {
  208. expect(set.add(1)).to.equal(set);
  209. expect(set.add(5)).to.equal(set);
  210. expect(set.size).to.equal(2);
  211. });
  212. });
  213. describe('#clear()', function () {
  214. ifFunctionsHaveNamesIt('has the right name', function () {
  215. expect(Set.prototype.clear).to.have.property('name', 'clear');
  216. });
  217. it('is not enumerable', function () {
  218. expect(Set.prototype).ownPropertyDescriptor('clear').to.have.property('enumerable', false);
  219. });
  220. it('has the right arity', function () {
  221. expect(Set.prototype.clear).to.have.property('length', 0);
  222. });
  223. it('clears a Set with only primitives', function () {
  224. expect(set.add(1)).to.equal(set);
  225. expect(set.size).to.equal(1);
  226. expect(set.add(5)).to.equal(set);
  227. expect(set.size).to.equal(2);
  228. expect(set.has(5)).to.equal(true);
  229. set.clear();
  230. expect(set.size).to.equal(0);
  231. expect(set.has(5)).to.equal(false);
  232. });
  233. it('clears a Set with primitives and objects', function () {
  234. expect(set.add(1)).to.equal(set);
  235. expect(set.size).to.equal(1);
  236. var obj = {};
  237. expect(set.add(obj)).to.equal(set);
  238. expect(set.size).to.equal(2);
  239. expect(set.has(obj)).to.equal(true);
  240. set.clear();
  241. expect(set.size).to.equal(0);
  242. expect(set.has(obj)).to.equal(false);
  243. });
  244. });
  245. describe('#keys()', function () {
  246. if (!Object.prototype.hasOwnProperty.call(Set.prototype, 'keys')) {
  247. return it('exists', function () {
  248. expect(Set.prototype).to.have.property('keys');
  249. });
  250. }
  251. it('is the same object as #values()', function () {
  252. expect(Set.prototype.keys).to.equal(Set.prototype.values);
  253. });
  254. ifFunctionsHaveNamesIt('has the right name', function () {
  255. expect(Set.prototype.keys).to.have.property('name', 'values');
  256. });
  257. it('is not enumerable', function () {
  258. expect(Set.prototype).ownPropertyDescriptor('keys').to.have.property('enumerable', false);
  259. });
  260. it('has the right arity', function () {
  261. expect(Set.prototype.keys).to.have.property('length', 0);
  262. });
  263. });
  264. describe('#values()', function () {
  265. if (!Object.prototype.hasOwnProperty.call(Set.prototype, 'values')) {
  266. return it('exists', function () {
  267. expect(Set.prototype).to.have.property('values');
  268. });
  269. }
  270. ifFunctionsHaveNamesIt('has the right name', function () {
  271. expect(Set.prototype.values).to.have.property('name', 'values');
  272. });
  273. it('is not enumerable', function () {
  274. expect(Set.prototype).ownPropertyDescriptor('values').to.have.property('enumerable', false);
  275. });
  276. it('has the right arity', function () {
  277. expect(Set.prototype.values).to.have.property('length', 0);
  278. });
  279. it('throws when called on a non-Set', function () {
  280. var expectedMessage = /^(Method )?Set.prototype.values called on incompatible receiver |^values method called on incompatible |^Cannot create a Set value iterator for a non-Set object.$|^Set.prototype.values: 'this' is not a Set object$|^std_Set_iterator method called on incompatible \w+$|Set.prototype.values requires that \|this\| be Set| is not an object|Set operation called on non-Set object/;
  281. var nonSets = [true, false, 'abc', NaN, new Map([[1, 2]]), { a: true }, [1], Object('abc'), Object(NaN)];
  282. nonSets.forEach(function (nonSet) {
  283. expect(function () { return Set.prototype.values.call(nonSet); }).to['throw'](TypeError, expectedMessage);
  284. });
  285. });
  286. });
  287. describe('#entries()', function () {
  288. if (!Object.prototype.hasOwnProperty.call(Set.prototype, 'entries')) {
  289. return it('exists', function () {
  290. expect(Set.prototype).to.have.property('entries');
  291. });
  292. }
  293. ifFunctionsHaveNamesIt('has the right name', function () {
  294. expect(Set.prototype.entries).to.have.property('name', 'entries');
  295. });
  296. it('is not enumerable', function () {
  297. expect(Set.prototype).ownPropertyDescriptor('entries').to.have.property('enumerable', false);
  298. });
  299. it('has the right arity', function () {
  300. expect(Set.prototype.entries).to.have.property('length', 0);
  301. });
  302. });
  303. describe('#has()', function () {
  304. if (!Object.prototype.hasOwnProperty.call(Set.prototype, 'has')) {
  305. return it('exists', function () {
  306. expect(Set.prototype).to.have.property('has');
  307. });
  308. }
  309. ifFunctionsHaveNamesIt('has the right name', function () {
  310. expect(Set.prototype.has).to.have.property('name', 'has');
  311. });
  312. it('is not enumerable', function () {
  313. expect(Set.prototype).ownPropertyDescriptor('has').to.have.property('enumerable', false);
  314. });
  315. it('has the right arity', function () {
  316. expect(Set.prototype.has).to.have.property('length', 1);
  317. });
  318. });
  319. it('should allow NaN values as keys', function () {
  320. expect(set.has(NaN)).to.equal(false);
  321. expect(set.has(NaN + 1)).to.equal(false);
  322. expect(set.has(23)).to.equal(false);
  323. expect(set.add(NaN)).to.equal(set);
  324. expect(set.has(NaN)).to.equal(true);
  325. expect(set.has(NaN + 1)).to.equal(true);
  326. expect(set.has(23)).to.equal(false);
  327. });
  328. it('should not have [[Enumerable]] props', function () {
  329. expectNotEnumerable(Set);
  330. expectNotEnumerable(Set.prototype);
  331. expectNotEnumerable(new Set());
  332. });
  333. it('should not have an own constructor', function () {
  334. var s = new Set();
  335. expect(s).not.to.haveOwnPropertyDescriptor('constructor');
  336. expect(s.constructor).to.equal(Set);
  337. });
  338. it('should allow common ecmascript idioms', function () {
  339. expect(set instanceof Set).to.equal(true);
  340. expect(typeof Set.prototype.add).to.equal('function');
  341. expect(typeof Set.prototype.has).to.equal('function');
  342. expect(typeof Set.prototype['delete']).to.equal('function');
  343. });
  344. it('should have a unique constructor', function () {
  345. expect(Set.prototype).to.not.equal(Object.prototype);
  346. });
  347. describe('has an iterator that works with Array.from', function () {
  348. if (!Object.prototype.hasOwnProperty.call(Array, 'from')) {
  349. return it('requires Array.from to exist', function () {
  350. expect(Array).to.have.property('from');
  351. });
  352. }
  353. var values = [1, NaN, false, true, null, undefined, 'a'];
  354. it('works with the full set', function () {
  355. expect(new Set(values)).to.have.iterations(values);
  356. });
  357. it('works with Set#keys()', function () {
  358. expect(new Set(values).keys()).to.have.iterations(values);
  359. });
  360. it('works with Set#values()', function () {
  361. expect(new Set(values).values()).to.have.iterations(values);
  362. });
  363. it('works with Set#entries()', function () {
  364. expect(new Set(values).entries()).to.have.iterations([
  365. [1, 1],
  366. [NaN, NaN],
  367. [false, false],
  368. [true, true],
  369. [null, null],
  370. [undefined, undefined],
  371. ['a', 'a']
  372. ]);
  373. });
  374. });
  375. ifSymbolIteratorIt('has the right default iteration function', function () {
  376. // fixed in Webkit https://bugs.webkit.org/show_bug.cgi?id=143838
  377. expect(Set.prototype).to.have.property(Sym.iterator, Set.prototype.values);
  378. });
  379. it('should preserve insertion order', function () {
  380. var arr1 = ['d', 'a', 'b'];
  381. var arr2 = [3, 2, 'z', 'a', 1];
  382. var arr3 = [3, 2, 'z', {}, 'a', 1];
  383. [arr1, arr2, arr3].forEach(function (array) {
  384. expect(new Set(array)).to.have.iterations(array);
  385. });
  386. });
  387. describe('#forEach', function () {
  388. var setToIterate;
  389. beforeEach(function () {
  390. setToIterate = new Set();
  391. expect(setToIterate.add('a')).to.equal(setToIterate);
  392. expect(setToIterate.add('b')).to.equal(setToIterate);
  393. expect(setToIterate.add('c')).to.equal(setToIterate);
  394. });
  395. afterEach(function () {
  396. setToIterate = null;
  397. });
  398. ifFunctionsHaveNamesIt('has the right name', function () {
  399. expect(Set.prototype.forEach).to.have.property('name', 'forEach');
  400. });
  401. it('is not enumerable', function () {
  402. expect(Set.prototype).ownPropertyDescriptor('forEach').to.have.property('enumerable', false);
  403. });
  404. it('has the right arity', function () {
  405. expect(Set.prototype.forEach).to.have.property('length', 1);
  406. });
  407. it('should be iterable via forEach', function () {
  408. var expectedSet = ['a', 'b', 'c'];
  409. var foundSet = [];
  410. setToIterate.forEach(function (value, alsoValue, entireSet) {
  411. expect(entireSet).to.equal(setToIterate);
  412. expect(value).to.equal(alsoValue);
  413. foundSet.push(value);
  414. });
  415. expect(foundSet).to.eql(expectedSet);
  416. });
  417. it('should iterate over empty keys', function () {
  418. var setWithEmptyKeys = new Set();
  419. var expectedKeys = [{}, null, undefined, '', NaN, 0];
  420. expectedKeys.forEach(function (key) {
  421. expect(setWithEmptyKeys.add(key)).to.equal(setWithEmptyKeys);
  422. });
  423. var foundKeys = [];
  424. setWithEmptyKeys.forEach(function (value, key, entireSet) {
  425. expect([key]).to.be.theSameSet([value]); // handles NaN correctly
  426. expect(entireSet.has(key)).to.equal(true);
  427. foundKeys.push(key);
  428. });
  429. expect(foundKeys).to.be.theSameSet(expectedKeys);
  430. });
  431. it('should support the thisArg', function () {
  432. var context = function () {};
  433. setToIterate.forEach(function () {
  434. expect(this).to.equal(context);
  435. }, context);
  436. });
  437. it('should have a length of 1', function () {
  438. expect(Set.prototype.forEach.length).to.equal(1);
  439. });
  440. it('should not revisit modified keys', function () {
  441. var hasModifiedA = false;
  442. setToIterate.forEach(function (value, key) {
  443. if (!hasModifiedA && key === 'a') {
  444. expect(setToIterate.add('a')).to.equal(setToIterate);
  445. hasModifiedA = true;
  446. } else {
  447. expect(key).not.to.equal('a');
  448. }
  449. });
  450. });
  451. it('visits keys added in the iterator', function () {
  452. var hasAdded = false;
  453. var hasFoundD = false;
  454. setToIterate.forEach(function (value, key) {
  455. if (!hasAdded) {
  456. expect(setToIterate.add('d')).to.equal(setToIterate);
  457. hasAdded = true;
  458. } else if (key === 'd') {
  459. hasFoundD = true;
  460. }
  461. });
  462. expect(hasFoundD).to.equal(true);
  463. });
  464. it('visits keys added in the iterator when there is a deletion (slow path)', function () {
  465. var hasSeenFour = false;
  466. var setToMutate = new Set();
  467. expect(setToMutate.add({})).to.equal(setToMutate); // force use of the slow O(N) implementation
  468. expect(setToMutate.add('0')).to.equal(setToMutate);
  469. setToMutate.forEach(function (value, key) {
  470. if (key === '0') {
  471. expect(setToMutate['delete']('0')).to.equal(true);
  472. expect(setToMutate.add('4')).to.equal(setToMutate);
  473. } else if (key === '4') {
  474. hasSeenFour = true;
  475. }
  476. });
  477. expect(hasSeenFour).to.equal(true);
  478. });
  479. it('visits keys added in the iterator when there is a deletion (fast path)', function () {
  480. var hasSeenFour = false;
  481. var setToMutate = new Set();
  482. expect(setToMutate.add('0')).to.equal(setToMutate);
  483. setToMutate.forEach(function (value, key) {
  484. if (key === '0') {
  485. expect(setToMutate['delete']('0')).to.equal(true);
  486. expect(setToMutate.add('4')).to.equal(setToMutate);
  487. } else if (key === '4') {
  488. hasSeenFour = true;
  489. }
  490. });
  491. expect(hasSeenFour).to.equal(true);
  492. });
  493. it('does not visit keys deleted before a visit', function () {
  494. var hasVisitedC = false;
  495. var hasDeletedC = false;
  496. setToIterate.forEach(function (value, key) {
  497. if (key === 'c') {
  498. hasVisitedC = true;
  499. }
  500. if (!hasVisitedC && !hasDeletedC) {
  501. hasDeletedC = setToIterate['delete']('c');
  502. expect(hasDeletedC).to.equal(true);
  503. }
  504. });
  505. expect(hasVisitedC).to.equal(false);
  506. });
  507. it('should work after deletion of the current key', function () {
  508. var expectedSet = {
  509. a: 'a',
  510. b: 'b',
  511. c: 'c'
  512. };
  513. var foundSet = {};
  514. setToIterate.forEach(function (value, key) {
  515. foundSet[key] = value;
  516. expect(setToIterate['delete'](key)).to.equal(true);
  517. });
  518. expect(foundSet).to.eql(expectedSet);
  519. });
  520. it('should convert key -0 to +0', function () {
  521. var zeroSet = new Set();
  522. var result = [];
  523. expect(zeroSet.add(-0)).to.equal(zeroSet);
  524. zeroSet.forEach(function (key) {
  525. result.push(String(1 / key));
  526. });
  527. expect(zeroSet.add(1)).to.equal(zeroSet);
  528. expect(zeroSet.add(0)).to.equal(zeroSet); // shouldn't cause reordering
  529. zeroSet.forEach(function (key) {
  530. result.push(String(1 / key));
  531. });
  532. expect(result.join(', ')).to.equal('Infinity, Infinity, 1');
  533. });
  534. });
  535. it('Set.prototype.size should throw TypeError', function () {
  536. // see https://github.com/paulmillr/es6-shim/issues/176
  537. expect(function () { return Set.prototype.size; }).to['throw'](TypeError);
  538. expect(function () { return Set.prototype.size; }).to['throw'](TypeError);
  539. });
  540. it.skip('should throw proper errors when user invokes methods with wrong types of receiver', function () {
  541. });
  542. ifGetPrototypeOfIt('SetIterator identification test prototype inequality', function () {
  543. var mapEntriesProto = Object.getPrototypeOf(new Map().entries());
  544. var setEntriesProto = Object.getPrototypeOf(new Set().entries());
  545. expect(mapEntriesProto).to.not.equal(setEntriesProto);
  546. });
  547. it('SetIterator identification', function () {
  548. var fnSetValues = Set.prototype.values;
  549. var setSentinel = new Set(['SetSentinel']);
  550. var testSet1 = new Set();
  551. var testSetValues = testSet1.values();
  552. expect(testSetValues.next.call(fnSetValues.call(setSentinel)).value).to.equal('SetSentinel');
  553. var testMap = new Map();
  554. var testMapValues = testMap.values();
  555. expect(function () {
  556. return testMapValues.next.call(fnSetValues.call(setSentinel)).value;
  557. }).to['throw'](TypeError);
  558. });
  559. });