diff --git a/getCollectionsForEach.js b/getCollectionsForEach.js index bd645d8..3ac28a2 100644 --- a/getCollectionsForEach.js +++ b/getCollectionsForEach.js @@ -1,6 +1,23 @@ module.exports = function () { - var mapForEach = typeof Map === 'function' ? Map.prototype.forEach : null; - var setForEach = typeof Set === 'function' ? Set.prototype.forEach : null; + var mapForEach = (function () { + if (typeof Map !== 'function') { return null; } + try { + Map.prototype.forEach.call({}, function () {}); + } catch (e) { + return Map.prototype.forEach; + } + return null; + }()); + + var setForEach = (function () { + if (typeof Set !== 'function') { return null; } + try { + Set.prototype.forEach.call({}, function () {}); + } catch (e) { + return Set.prototype.forEach; + } + return null; + }()); return { Map: mapForEach, Set: setForEach }; }; diff --git a/package.json b/package.json index a50ef0f..3458a0b 100644 --- a/package.json +++ b/package.json @@ -7,9 +7,10 @@ "main": "index.js", "scripts": { "test": "npm run lint && npm run tests-only && npm run security", - "tests-only": "npm run test:native && npm run test:shimmed", + "tests-only": "npm run test:native && npm run test:shimmed && npm run test:corejs", "test:native": "node test/native.js", "test:shimmed": "node test/shimmed.js", + "test:corejs": "node test/corejs.js", "coverage": "covert test/native.js", "coverage-quiet": "covert test/native.js --quiet", "lint": "npm run jscs && npm run eslint", @@ -58,7 +59,8 @@ "@ljharb/eslint-config": "^1.6.0", "nsp": "^2.1.0", "replace": "^0.3.0", - "es6-shim": "^0.33.13" + "es6-shim": "^0.33.13", + "core-js": "^1.2.6" }, "testling": { "files": "test/native.js", diff --git a/test/corejs.js b/test/corejs.js new file mode 100644 index 0000000..8ca01c0 --- /dev/null +++ b/test/corejs.js @@ -0,0 +1,5 @@ +'use strict'; + +require('core-js'); + +require('./native');