Skip to content

Commit

Permalink
Factor out "get Symbol.iterator" logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Dec 15, 2015
1 parent a22c35f commit 8546880
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
17 changes: 17 additions & 0 deletions getSymbolIterator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

var isSymbol = require('is-symbol');

module.exports = function getSymbolIterator() {
var symbolIterator = typeof Symbol === 'function' && isSymbol(Symbol.iterator) ? Symbol.iterator : null;

if (typeof Object.getOwnPropertyNames === 'function' && typeof Map === 'function' && typeof Map.prototype.entries === 'function') {
Object.getOwnPropertyNames(Map.prototype).forEach(function (name) {
if (name !== 'entries' && name !== 'size' && Map.prototype[name] === Map.prototype.entries) {
symbolIterator = name;
}
});
}

return symbolIterator;
};
10 changes: 2 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,8 @@ var foo = function foo() {};
var functionsHaveNames = foo.name === 'foo';

var symbolValue = typeof Symbol === 'function' ? Symbol.prototype.valueOf : null;
var symbolIterator = typeof Symbol === 'function' && isSymbol(Symbol.iterator) ? Symbol.iterator : null;
if (typeof Object.getOwnPropertyNames === 'function' && typeof Map === 'function' && typeof Map.prototype.entries === 'function') {
Object.getOwnPropertyNames(Map.prototype).forEach(function (name) {
if (name !== 'entries' && name !== 'size' && Map.prototype[name] === Map.prototype.entries) {
symbolIterator = name;
}
});
}
var symbolIterator = require('./getSymbolIterator')();

var mapForEach = typeof Map === 'function' ? Map.prototype.forEach : null;
var setForEach = typeof Set === 'function' ? Set.prototype.forEach : null;

Expand Down

0 comments on commit 8546880

Please sign in to comment.