diff --git a/.eslintrc b/.eslintrc index 4754d28..7af084e 100644 --- a/.eslintrc +++ b/.eslintrc @@ -58,6 +58,7 @@ { "files": "test/**", "rules": { + "eqeqeq": ["error", "allow-null"], "max-params": 0, }, }, diff --git a/aos/GetIteratorDirect.js b/aos/GetIteratorDirect.js index 4e560e0..c65313e 100644 --- a/aos/GetIteratorDirect.js +++ b/aos/GetIteratorDirect.js @@ -5,7 +5,6 @@ var GetIntrinsic = require('get-intrinsic'); var $TypeError = GetIntrinsic('%TypeError%'); var Get = require('es-abstract/2022/Get'); -var IsCallable = require('es-abstract/2022/IsCallable'); var Type = require('es-abstract/2022/Type'); module.exports = function GetIteratorDirect(obj) { @@ -15,11 +14,7 @@ module.exports = function GetIteratorDirect(obj) { var nextMethod = Get(obj, 'next'); // step 2 - if (!IsCallable(nextMethod)) { - throw new $TypeError('`nextMethod` must be a function'); // step 3 - } - - var iteratorRecord = { '[[Iterator]]': obj, '[[NextMethod]]': nextMethod, '[[Done]]': false }; // step 4 + var iteratorRecord = { '[[Iterator]]': obj, '[[NextMethod]]': nextMethod, '[[Done]]': false }; // step 3 - return iteratorRecord; // step 5 + return iteratorRecord; // step 4 }; diff --git a/test/Iterator.from.js b/test/Iterator.from.js index bb5cc0c..3a686bc 100644 --- a/test/Iterator.from.js +++ b/test/Iterator.from.js @@ -42,7 +42,7 @@ module.exports = { forEach(v.primitives.concat(v.objects), function (nonIterator) { if (typeof nonIterator !== 'string') { t['throws']( - function () { from(nonIterator); }, + function () { from(nonIterator).next(); }, TypeError, debug(nonIterator) + ' is not an iterable Object' ); @@ -54,7 +54,7 @@ module.exports = { var badIterable = {}; badIterable[Symbol.iterator] = nonFunction; st['throws']( - function () { from(badIterable); }, + function () { from(badIterable).next(); }, TypeError, debug(badIterable) + ' is not a function' ); diff --git a/test/Iterator.prototype.drop.js b/test/Iterator.prototype.drop.js index d4d6999..7946dae 100644 --- a/test/Iterator.prototype.drop.js +++ b/test/Iterator.prototype.drop.js @@ -10,6 +10,7 @@ var debug = require('object-inspect'); var v = require('es-value-fixtures'); var hasSymbols = require('has-symbols/shams')(); var hasPropertyDescriptors = require('has-property-descriptors')(); +var iterate = require('iterate-iterator'); var index = require('../Iterator.prototype.drop'); var impl = require('../Iterator.prototype.drop/implementation'); @@ -24,14 +25,14 @@ module.exports = { tests: function (drop, name, t) { forEach(v.primitives.concat(v.objects), function (nonIterator) { t['throws']( - function () { drop(nonIterator, 0); }, + function () { iterate(drop(nonIterator, 0)); }, TypeError, debug(nonIterator) + ' is not an Object with a callable `next` method' ); var badNext = { next: nonIterator }; t['throws']( - function () { drop(badNext, 0); }, + function () { iterate(drop(badNext, 0)); }, TypeError, debug(badNext) + ' is not an Object with a callable `next` method' ); diff --git a/test/Iterator.prototype.take.js b/test/Iterator.prototype.take.js index ff82793..c898a99 100644 --- a/test/Iterator.prototype.take.js +++ b/test/Iterator.prototype.take.js @@ -23,17 +23,19 @@ module.exports = { tests: function (take, name, t) { forEach(v.primitives.concat(v.objects), function (nonIterator) { t['throws']( - function () { take(nonIterator, 0); }, + function () { take(nonIterator, 1).next(); }, TypeError, debug(nonIterator) + ' is not an Object with a callable `next` method' ); - var badNext = { next: nonIterator }; - t['throws']( - function () { take(badNext, 0); }, - TypeError, - debug(badNext) + ' is not an Object with a callable `next` method' - ); + if (nonIterator != null && typeof nonIterator !== 'string') { + var badNext = { next: nonIterator }; + t['throws']( + function () { take(badNext, 1).next(); }, + TypeError, + debug(badNext) + ' is not an Object with a callable `next` method' + ); + } }); var iterator = [1, 2, 3];