Skip to content

Commit

Permalink
[patch] remove IsCallable check on NextMethod, deferring errors to ca…
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed May 18, 2023
1 parent ec3e255 commit bbb7efa
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Expand Up @@ -58,6 +58,7 @@
{
"files": "test/**",
"rules": {
"eqeqeq": ["error", "allow-null"],
"max-params": 0,
},
},
Expand Down
9 changes: 2 additions & 7 deletions aos/GetIteratorDirect.js
Expand Up @@ -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) {
Expand All @@ -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
};
4 changes: 2 additions & 2 deletions test/Iterator.from.js
Expand Up @@ -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'
);
Expand All @@ -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'
);
Expand Down
5 changes: 3 additions & 2 deletions test/Iterator.prototype.drop.js
Expand Up @@ -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');
Expand All @@ -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'
);
Expand Down
16 changes: 9 additions & 7 deletions test/Iterator.prototype.take.js
Expand Up @@ -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];
Expand Down

0 comments on commit bbb7efa

Please sign in to comment.