Iterator Helpers (#2818)

drop:

property descriptor
name
length
[[Prototype]]
is a function
is not constructible
result instanceof Iterator
limit is given a non-primitive that needs to be converted to a number
  through valueOf
  through toString (array)
limit coercion to number throws
limit converts to NaN
  same as limit not supplied
limit behaves properly
  limit < number of values
  limit = number of values
  limit > number of values
gets the next method from the underlying iterator only once
underlying iterator has throwing next getter
underlying iterator next throws when advancing past dropped items
underlying iterator is advanced after calling drop
underlying iterator is closed after calling drop
underlying iterator is already closed
underlying iterator next returns non-object
underlying iterator next returns object with throwing done/value getters
underlying iterator return is never called when result iterator is closed

every:

property descriptor
name
length
[[Prototype]]
is a function
is callable
is not constructible
result is a Boolean
predicate is non-callable
iterator already exhausted
called on non-object
called on object with "next" method
called on object with non-callable "next" method
predicate returns non-Boolean
predicate returns truthy for all iterated values
  returns true
predicate returns truthy for some iterated values but then falsey for at least one iterated value
  returns false
  iteration stops
  iterator is closed
predicate returns falsey immediately
  returns false
  iteration stops
  iterator is closed
predicate throws
  every throws
  iterator is closed
predicate throws then iterator close also throws
predicate this value is undefined
predicate is passed the yielded value as the first parameter and a counter as second parameter
gets the next method from the iterator only once
iterator has throwing next getter
iterator has throwing return getter
iterator next throws
iterator return throws
iterator next returns non-object
iterator next returns object with throwing done/value getters

Co-authored-by: Michael Ficarra <mficarra@shapesecurity.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
This commit is contained in:
Rick Waldron 2023-06-15 11:07:41 -04:00 committed by GitHub
parent e337fc9506
commit dfc7ce4c28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
374 changed files with 10452 additions and 37 deletions

View File

@ -104,6 +104,10 @@ String.prototype.toWellFormed
# https://github.com/tc39/proposal-json-parse-with-source
json-parse-with-source
# Iterator Helpers
# https://github.com/tc39/proposal-iterator-helpers
iterator-helpers
## Standard language features
#
# Language features that have been included in a published version of the

View File

@ -0,0 +1,11 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator-constructor
description: >
The Iterator constructor is a built-in function
features: [iterator-helpers]
---*/
assert.sameValue(typeof Iterator, 'function', 'The value of `typeof Iterator` is "function"');

View File

@ -0,0 +1,12 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator.from
description: >
Iterator.from is callable
features: [iterator-helpers]
---*/
function* g() {}
Iterator.from(g());
Iterator.from.call(null, g());

View File

@ -0,0 +1,46 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator.from
description: >
Gets the next method from the underlying iterator only once
info: |
Iterator.from ( O )
2. Let iteratorRecord be ? GetIteratorFlattenable(O).
features: [iterator-helpers]
flags: []
---*/
let nextGets = 0;
let nextCalls = 0;
class CountingIterator {
get next() {
++nextGets;
let iter = (function* () {
for (let i = 1; i < 5; ++i) {
yield i;
}
})();
return function () {
++nextCalls;
return iter.next();
};
}
}
let iterator = new CountingIterator();
assert.sameValue(nextGets, 0, 'The value of `nextGets` is 0');
assert.sameValue(nextCalls, 0, 'The value of `nextCalls` is 0');
iterator = Iterator.from(iterator);
assert.sameValue(nextGets, 1, 'The value of `nextGets` is 1');
assert.sameValue(nextCalls, 0, 'The value of `nextCalls` is 0');
iterator.toArray();
assert.sameValue(nextGets, 1, 'The value of `nextGets` is 1');
assert.sameValue(nextCalls, 5, 'The value of `nextCalls` is 5');

View File

@ -0,0 +1,25 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator.from
description: >
Underlying iterator has throwing next getter
info: |
Iterator.from ( O )
4. Let iterated be ? GetIteratorDirect(O).
features: [iterator-helpers]
flags: []
---*/
class ThrowingIterator {
get next() {
throw new Test262Error();
}
}
let iterator = new ThrowingIterator();
assert.throws(Test262Error, function () {
Iterator.from(iterator);
});

View File

@ -0,0 +1,10 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator.from
description: >
Iterator.from is a built-in function
features: [iterator-helpers]
---*/
assert.sameValue(typeof Iterator.from, 'function', 'The value of `typeof Iterator.from` is "function"');

View File

@ -0,0 +1,39 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator.from
description: >
Iterator.from does not respect the iterability of any primitive except Strings
info: |
Iterator.from ( O )
1. If O is a String, set O to ! ToObject(O).
2. Let iteratorRecord be ? GetIteratorFlattenable(O).
includes: [compareArray.js]
features: [iterator-helpers]
flags: []
---*/
function* g() {
yield 0;
}
Number.prototype[Symbol.iterator] = function* () {
let i = 0;
let target = this >>> 0;
while (i < target) {
yield i;
++i;
}
};
assert.compareArray(Array.from(5), [0, 1, 2, 3, 4]);
assert.throws(TypeError, function () {
Iterator.from(5);
});
assert.compareArray(Array.from(Iterator.from(new Number(5))), [0, 1, 2, 3, 4]);
assert.compareArray(Array.from(Iterator.from('string')), ['s', 't', 'r', 'i', 'n', 'g']);

View File

@ -0,0 +1,51 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator.from
description: >
Iterator.from falls back to treating its parameter as an iterator if the Symbol.iterator property is null/undefined
info: |
Iterator.from ( O )
includes: [compareArray.js]
features: [iterator-helpers]
flags: []
---*/
function* g() {
yield 0;
yield 1;
yield 2;
}
let iter = (function () {
let n = g();
return {
[Symbol.iterator]: 0,
next: () => n.next(),
};
})();
assert.throws(TypeError, function () {
Iterator.from(iter);
});
iter = (function () {
let n = g();
return {
[Symbol.iterator]: null,
next: () => n.next(),
};
})();
assert.compareArray(Array.from(Iterator.from(iter)), [0, 1, 2]);
iter = (function () {
let n = g();
return {
[Symbol.iterator]: undefined,
next: () => n.next(),
};
})();
assert.compareArray(Array.from(Iterator.from(iter)), [0, 1, 2]);

View File

@ -0,0 +1,22 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator.from
description: >
Iterator.from has a "length" property whose value is 1.
info: |
ECMAScript Standard Built-in Objects
Unless otherwise specified, the length property of a built-in
Function object has the attributes { [[Writable]]: false, [[Enumerable]]:
false, [[Configurable]]: true }.
features: [iterator-helpers]
includes: [propertyHelper.js]
---*/
verifyProperty(Iterator.from, 'length', {
value: 1,
writable: false,
enumerable: false,
configurable: true,
});

View File

@ -0,0 +1,29 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator.from
description: >
The "name" property of Iterator.from
info: |
17 ECMAScript Standard Built-in Objects
Every built-in Function object, including constructors, that is not
identified as an anonymous function has a name property whose value is a
String. Unless otherwise specified, this value is the name that is given to
the function in this specification.
...
Unless otherwise specified, the name property of a built-in Function
object, if it exists, has the attributes { [[Writable]]: false,
[[Enumerable]]: false, [[Configurable]]: true }.
features: [iterator-helpers]
includes: [propertyHelper.js]
---*/
verifyProperty(Iterator.from, 'name', {
value: 'from',
writable: false,
enumerable: false,
configurable: true,
});

View File

@ -0,0 +1,23 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator.from
description: >
Iterator.from is not constructible.
Built-in function objects that are not identified as constructors do not implement the [[Construct]] internal method unless otherwise specified in the description of a particular function.
features: [iterator-helpers]
---*/
function* g() {}
assert.throws(TypeError, () => {
new Iterator.from();
});
assert.throws(TypeError, () => {
new Iterator.from(g());
});
assert.throws(TypeError, () => {
new class extends Iterator {}.from(g());
});

View File

@ -0,0 +1,38 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator.from
description: >
Iterator.from throws on primitives (except Strings)
info: |
Iterator.from ( O )
features: [iterator-helpers]
flags: []
---*/
assert.throws(TypeError, function () {
Iterator.from(null);
});
assert.throws(TypeError, function () {
Iterator.from(undefined);
});
assert.throws(TypeError, function () {
Iterator.from(0);
});
assert.throws(TypeError, function () {
Iterator.from(0n);
});
assert.throws(TypeError, function () {
Iterator.from(true);
});
assert.throws(TypeError, function () {
Iterator.from(Symbol());
});
Iterator.from('string');

View File

@ -0,0 +1,26 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator.from
description: >
Property descriptor of Iterator.from
info: |
Iterator.from
* is the initial value of the Iterator.from property of the global object.
17 ECMAScript Standard Built-in Objects
Every other data property described in clauses 18 through 26 and in Annex B.2
has the attributes { [[Writable]]: true, [[Enumerable]]: false,
[[Configurable]]: true } unless otherwise specified.
features: [globalThis, iterator-helpers]
includes: [propertyHelper.js]
---*/
verifyProperty(Iterator, 'from', {
value: Iterator.from,
writable: true,
enumerable: false,
configurable: true,
});

View File

@ -0,0 +1,15 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator.from
description: >
The value of the [[Prototype]] internal slot of Iterator.from is the
intrinsic object %FunctionPrototype%.
features: [iterator-helpers]
---*/
assert.sameValue(
Object.getPrototypeOf(Iterator.from),
Function.prototype,
'Object.getPrototypeOf(Iterator.from) must return the value of Function.prototype'
);

View File

@ -0,0 +1,29 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator.from
description: >
The value of the [[Prototype]] internal slot of the return value of Iterator.from is the
intrinsic object %WrapForValidIteratorPrototype%, whose [[Prototype]] is %IteratorHelperPrototype%.
features: [iterator-helpers]
---*/
let iter = {
next() {
return {
done: true,
value: undefined,
};
},
};
const WrapForValidIteratorPrototype = Object.getPrototypeOf(Iterator.from(iter));
assert.sameValue(Object.getPrototypeOf(WrapForValidIteratorPrototype), Iterator.prototype);
class SubIterator extends Iterator {}
assert.sameValue(Object.getPrototypeOf(SubIterator.from(iter)), WrapForValidIteratorPrototype);
function* g() {}
const GeneratorPrototype = Object.getPrototypeOf(g());
assert.sameValue(Object.getPrototypeOf(Iterator.from(g())), GeneratorPrototype);

View File

@ -0,0 +1,14 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator.from
description: >
Iterator.from supports iterables
info: |
Iterator.from ( O )
includes: [compareArray.js]
features: [iterator-helpers]
flags: []
---*/
assert.compareArray(Array.from(Iterator.from([0, 1, 2, 3])), [0, 1, 2, 3]);

View File

@ -0,0 +1,29 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator.from
description: >
Iterator.from supports non-iterable iterators
info: |
Iterator.from ( O )
includes: [compareArray.js]
features: [iterator-helpers]
flags: []
---*/
function* g() {
yield 0;
yield 1;
yield 2;
yield 3;
}
let n = g();
let iter = {
next() {
return n.next();
},
};
assert.compareArray(Array.from(Iterator.from(iter)), [0, 1, 2, 3]);

View File

@ -0,0 +1,26 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator-constructor
description: >
Iterator has a "length" property whose value is 0.
info: |
The Iterator Constructor
The length property of the Iterator constructor function is 0.
...
ES7 section 17: Unless otherwise specified, the length property of a built-in
Function object has the attributes { [[Writable]]: false, [[Enumerable]]:
false, [[Configurable]]: true }.
features: [iterator-helpers]
includes: [propertyHelper.js]
---*/
verifyProperty(Iterator, 'length', {
value: 0,
writable: false,
enumerable: false,
configurable: true,
});

View File

@ -0,0 +1,30 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator-constructor
description: >
The "name" property of Iterator
info: |
17 ECMAScript Standard Built-in Objects
Every built-in Function object, including constructors, that is not
identified as an anonymous function has a name property whose value is a
String. Unless otherwise specified, this value is the name that is given to
the function in this specification.
...
Unless otherwise specified, the name property of a built-in Function
object, if it exists, has the attributes { [[Writable]]: false,
[[Enumerable]]: false, [[Configurable]]: true }.
features: [iterator-helpers]
includes: [propertyHelper.js]
---*/
verifyProperty(Iterator, 'name', {
value: 'Iterator',
writable: false,
enumerable: false,
configurable: true,
});

View File

@ -0,0 +1,22 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator
description: >
Iterator is not callable or constructable
info: |
When the Iterator function is called, the following steps are taken:
If NewTarget is undefined or the active function object, throw a TypeError exception.
features: [iterator-helpers]
---*/
assert.throws(TypeError, () => {
Iterator();
});
assert.throws(TypeError, () => {
new Iterator();
});

View File

@ -0,0 +1,27 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator-constructor
description: >
Property descriptor of Iterator
info: |
The Iterator Constructor
* is the initial value of the Iterator property of the global object.
17 ECMAScript Standard Built-in Objects
Every other data property described in clauses 18 through 26 and in Annex B.2
has the attributes { [[Writable]]: true, [[Enumerable]]: false,
[[Configurable]]: true } unless otherwise specified.
features: [globalThis, iterator-helpers]
includes: [propertyHelper.js]
---*/
verifyProperty(globalThis, 'Iterator', {
value: Iterator,
writable: true,
enumerable: false,
configurable: true,
});

View File

@ -0,0 +1,36 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator
description: Default [[Prototype]] value derived from realm of the NewTarget.
features: [cross-realm, iterator-helpers, Reflect, Symbol]
---*/
let other = $262.createRealm().global;
let newTarget = new other.Function();
let ai;
newTarget.prototype = undefined;
ai = Reflect.construct(Iterator, [1], newTarget);
assert.sameValue(Object.getPrototypeOf(ai), other.Iterator.prototype);
newTarget.prototype = null;
ai = Reflect.construct(Iterator, [1], newTarget);
assert.sameValue(Object.getPrototypeOf(ai), other.Iterator.prototype);
newTarget.prototype = true;
ai = Reflect.construct(Iterator, [1], newTarget);
assert.sameValue(Object.getPrototypeOf(ai), other.Iterator.prototype);
newTarget.prototype = '';
ai = Reflect.construct(Iterator, [1], newTarget);
assert.sameValue(Object.getPrototypeOf(ai), other.Iterator.prototype);
newTarget.prototype = Symbol();
ai = Reflect.construct(Iterator, [1], newTarget);
assert.sameValue(Object.getPrototypeOf(ai), other.Iterator.prototype);
newTarget.prototype = 0;
ai = Reflect.construct(Iterator, [1], newTarget);
assert.sameValue(Object.getPrototypeOf(ai), other.Iterator.prototype);

View File

@ -0,0 +1,16 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-properties-of-the-iterator-constructor
description: >
The value of the [[Prototype]] internal slot of the Iterator constructor is the
intrinsic object %FunctionPrototype%.
features: [iterator-helpers]
---*/
assert.sameValue(
Object.getPrototypeOf(Iterator),
Function.prototype,
'Object.getPrototypeOf(Iterator) must return the value of Function.prototype'
);

View File

@ -0,0 +1,13 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.some
description: >
Iterator.prototype.some is a built-in function
features: [Symbol.iterator]
---*/
const IteratorPrototype = Object.getPrototypeOf(
Object.getPrototypeOf([][Symbol.iterator]())
);
assert.sameValue(typeof IteratorPrototype[Symbol.iterator], 'function');

View File

@ -2,7 +2,7 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 25.1.2.1
description: Length of IteratorPrototype[ @@iterator ]
description: Length of %IteratorPrototype%[ @@iterator ]
info: |
ES6 Section 17:
Every built-in Function object, including constructors, has a length
@ -18,13 +18,13 @@ info: |
features: [Symbol.iterator]
includes: [propertyHelper.js]
---*/
var IteratorPrototype = Object.getPrototypeOf(
const IteratorPrototype = Object.getPrototypeOf(
Object.getPrototypeOf([][Symbol.iterator]())
);
assert.sameValue(IteratorPrototype[Symbol.iterator].length, 0);
verifyNotEnumerable(IteratorPrototype[Symbol.iterator], 'length');
verifyNotWritable(IteratorPrototype[Symbol.iterator], 'length');
verifyConfigurable(IteratorPrototype[Symbol.iterator], 'length');
verifyProperty(IteratorPrototype[Symbol.iterator], 'length', {
value: 0,
writable: false,
enumerable: false,
configurable: true,
});

View File

@ -21,13 +21,13 @@ info: |
features: [Symbol.iterator]
includes: [propertyHelper.js]
---*/
var IteratorPrototype = Object.getPrototypeOf(
const IteratorPrototype = Object.getPrototypeOf(
Object.getPrototypeOf([][Symbol.iterator]())
);
assert.sameValue(IteratorPrototype[Symbol.iterator].name, '[Symbol.iterator]');
verifyNotEnumerable(IteratorPrototype[Symbol.iterator], 'name');
verifyNotWritable(IteratorPrototype[Symbol.iterator], 'name');
verifyConfigurable(IteratorPrototype[Symbol.iterator], 'name');
verifyProperty(IteratorPrototype[Symbol.iterator], 'name', {
value: '[Symbol.iterator]',
writable: false,
enumerable: false,
configurable: true,
});

View File

@ -12,12 +12,12 @@ info: |
features: [Symbol.iterator]
includes: [propertyHelper.js]
---*/
var IteratorPrototype = Object.getPrototypeOf(
const IteratorPrototype = Object.getPrototypeOf(
Object.getPrototypeOf([][Symbol.iterator]())
);
assert.sameValue(typeof IteratorPrototype[Symbol.iterator], 'function');
verifyNotEnumerable(IteratorPrototype, Symbol.iterator);
verifyWritable(IteratorPrototype, Symbol.iterator);
verifyConfigurable(IteratorPrototype, Symbol.iterator);
verifyProperty(IteratorPrototype, Symbol.iterator, {
writable: true,
enumerable: false,
configurable: true,
});

View File

@ -2,31 +2,20 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-%iteratorprototype%-@@iterator
description: Return value of @@iterator on IteratorPrototype
description: Return value of @@iterator on %IteratorPrototype%
info: |
%IteratorPrototype% [ @@iterator ] ( )
1. Return the this value.
features: [Symbol.iterator]
---*/
const IteratorPrototype = Object.getPrototypeOf(
Object.getPrototypeOf([][Symbol.iterator]())
);
const getIterator = IteratorPrototype[Symbol.iterator];
const thisValues = [
{},
Symbol(),
4,
4n,
true,
undefined,
null,
];
const thisValues = [{}, Symbol(), 4, 4n, true, undefined, null];
for (const thisValue of thisValues) {
assert.sameValue(
getIterator.call(thisValue),
thisValue
);
assert.sameValue(getIterator.call(thisValue), thisValue);
}

View File

@ -0,0 +1,20 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 25.1.2.1
description: Property descriptor
info: |
ES6 Section 17
Every other data property described in clauses 18 through 26 and in Annex
B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false,
[[Configurable]]: true } unless otherwise specified.
features: [iterator-helpers]
includes: [propertyHelper.js]
---*/
verifyProperty(Iterator.prototype, Symbol.toStringTag, {
value: 'Iterator',
writable: true,
enumerable: false,
configurable: true,
});

View File

@ -0,0 +1,64 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.drop
description: >
Arguments and this value are evaluated in the correct order
info: |
%Iterator.prototype%.drop ( limit )
includes: [compareArray.js]
features: [iterator-helpers]
flags: []
---*/
let effects = [];
Iterator.prototype.drop.call(
{
get next() {
effects.push('get next');
return function () {
return { done: true, value: undefined };
};
},
},
{
valueOf() {
effects.push('ToNumber limit');
return 0;
},
}
);
assert.compareArray(effects, ['ToNumber limit', 'get next']);
effects = [];
assert.throws(TypeError, function () {
Iterator.prototype.drop.call(null, {
valueOf() {
effects.push('ToNumber limit');
return 0;
},
});
});
assert.compareArray(effects, []);
effects = [];
assert.throws(RangeError, function () {
Iterator.prototype.drop.call(
{
get next() {
effects.push('get next');
return function () {
return { done: true, value: undefined };
};
},
},
NaN
);
});
assert.compareArray(effects, []);

View File

@ -0,0 +1,13 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.drop
description: >
Iterator.prototype.drop is callable
features: [iterator-helpers]
---*/
function* g() {}
Iterator.prototype.drop.call(g(), 0);
let iter = g();
iter.drop(0);

View File

@ -0,0 +1,60 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.drop
description: >
Underlying iterator return is not called when result iterator is exhausted
info: |
%Iterator.prototype%.drop ( limit )
6.b.ii. Let next be ? IteratorStep(iterated).
6.b.iii. If next is false, return undefined.
6.c. Repeat,
6.c.i. Let next be ? IteratorStep(iterated).
6.c.ii. If next is false, return undefined.
features: [iterator-helpers]
flags: []
---*/
function* g() {
yield 0;
yield 1;
yield 2;
}
class TestIterator extends Iterator {
get next() {
let n = g();
return function() {
return n.next();
};
}
return() {
throw new Test262Error();
}
}
let iterator = new TestIterator();
iterator = iterator.drop(0);
iterator.next();
iterator.next();
iterator.next();
iterator.next();
iterator.next();
iterator = new TestIterator();
iterator = iterator.drop(1);
iterator.next();
iterator.next();
iterator.next();
iterator.next();
iterator = new TestIterator();
iterator = iterator.drop(1).drop(1).drop(1).drop(1).drop(1);
iterator.next();
iterator.next();
iterator = new TestIterator();
iterator = iterator.drop(10);
iterator.next();
iterator.next();

View File

@ -0,0 +1,41 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.drop
description: >
Gets the next method from the underlying iterator only once
info: |
%Iterator.prototype%.drop ( limit )
1. Let iterated be ? GetIteratorDirect(this value).
features: [iterator-helpers]
flags: []
---*/
let nextGets = 0;
let nextCalls = 0;
class CountingIterator extends Iterator {
get next() {
++nextGets;
let iter = (function* () {
for (let i = 1; i < 5; ++i) {
yield i;
}
})();
return function () {
++nextCalls;
return iter.next();
};
}
}
let iterator = new CountingIterator();
assert.sameValue(nextGets, 0);
assert.sameValue(nextCalls, 0);
for (const value of iterator.drop(2));
assert.sameValue(nextGets, 1);
assert.sameValue(nextCalls, 5);

View File

@ -0,0 +1,25 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.drop
description: >
Underlying iterator has throwing next getter
info: |
%Iterator.prototype%.drop ( limit )
1. Let iterated be ? GetIteratorDirect(this value).
features: [iterator-helpers]
flags: []
---*/
class ThrowingIterator extends Iterator {
get next() {
throw new Test262Error();
}
}
let iterator = new ThrowingIterator();
assert.throws(Test262Error, function () {
iterator.drop(0);
});

View File

@ -0,0 +1,30 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.drop
description: >
Underlying iterator return is throwing getter
info: |
%Iterator.prototype%.drop ( limit )
features: [iterator-helpers]
flags: []
---*/
class TestIterator extends Iterator {
next() {
return {
done: false,
value: 1,
};
}
get return() {
throw new Test262Error();
}
}
let iterator = new TestIterator().drop(1);
iterator.next();
assert.throws(Test262Error, function () {
iterator.return();
});

View File

@ -0,0 +1,10 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.drop
description: >
Iterator.prototype.drop is a built-in function
features: [iterator-helpers]
---*/
assert.sameValue(typeof Iterator.prototype.drop, 'function');

View File

@ -0,0 +1,22 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.drop
description: >
Iterator.prototype.drop has a "length" property whose value is 1.
info: |
ECMAScript Standard Built-in Objects
Unless otherwise specified, the length property of a built-in
Function object has the attributes { [[Writable]]: false, [[Enumerable]]:
false, [[Configurable]]: true }.
features: [iterator-helpers]
includes: [propertyHelper.js]
---*/
verifyProperty(Iterator.prototype.drop, 'length', {
value: 1,
writable: false,
enumerable: false,
configurable: true,
});

View File

@ -0,0 +1,22 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.drop
description: >
Removes entries from this iterator, specified by limit argument.
info: |
%Iterator.prototype%.drop ( limit )
features: [iterator-helpers]
flags: []
---*/
function* g() {
yield 1;
yield 2;
}
let iterator = g().drop(2);
let { value, done } = iterator.next();
assert.sameValue(value, undefined);
assert.sameValue(done, true);

View File

@ -0,0 +1,37 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.drop
description: >
Removes entries from this iterator, specified by limit argument.
info: |
%Iterator.prototype%.drop ( limit )
features: [iterator-helpers]
flags: []
---*/
function* g() {
yield 1;
yield 2;
}
{
let iterator = g().drop(3);
let { value, done } = iterator.next();
assert.sameValue(value, undefined);
assert.sameValue(done, true);
}
{
let iterator = g().drop(Number.MAX_SAFE_INTEGER);
let { value, done } = iterator.next();
assert.sameValue(value, undefined);
assert.sameValue(done, true);
}
{
let iterator = g().drop(Infinity);
let { value, done } = iterator.next();
assert.sameValue(value, undefined);
assert.sameValue(done, true);
}

View File

@ -0,0 +1,30 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.drop
description: >
Removes entries from this iterator, specified by limit argument.
info: |
%Iterator.prototype%.drop ( limit )
features: [iterator-helpers]
flags: []
---*/
function* g() {
yield 1;
yield 2;
}
let iterator = g().drop(1);
{
let { value, done } = iterator.next();
assert.sameValue(value, 2);
assert.sameValue(done, false);
}
{
let { value, done } = iterator.next();
assert.sameValue(value, undefined);
assert.sameValue(done, true);
}

View File

@ -0,0 +1,36 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.drop
description: >
Throws a RangeError exception when limit argument is NaN or less than 0.
info: |
%Iterator.prototype%.drop ( limit )
3. If numLimit is NaN, throw a RangeError exception.
4. Let integerLimit be ! ToIntegerOrInfinity(numLimit).
5. If integerLimit < 0, throw a RangeError exception.
features: [iterator-helpers]
---*/
let iterator = (function* () {})();
iterator.drop(0);
iterator.drop(-0.5);
iterator.drop(null);
assert.throws(RangeError, () => {
iterator.drop(-1);
});
assert.throws(RangeError, () => {
iterator.drop();
});
assert.throws(RangeError, () => {
iterator.drop(undefined);
});
assert.throws(RangeError, () => {
iterator.drop(NaN);
});

View File

@ -0,0 +1,22 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.drop
description: >
Throws a RangeError exception when limit argument valueOf throws.
info: |
%Iterator.prototype%.drop ( limit )
2. Let numLimit be ? ToNumber(limit).
features: [iterator-helpers]
---*/
let iterator = (function* () {})();
assert.throws(Test262Error, () => {
iterator.drop({
valueOf: function () {
throw new Test262Error();
},
});
});

View File

@ -0,0 +1,37 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.drop
description: >
Converts the limit argument to a Number using ToNumber and valueOf/toString.
info: |
%Iterator.prototype%.drop ( limit )
2. Let numLimit be ? ToNumber(limit).
features: [iterator-helpers]
---*/
function* g() {
yield 1;
yield 2;
}
{
let iterator = g();
let { value, done } = iterator
.drop({
valueOf: function () {
return 1;
},
})
.next();
assert.sameValue(value, 2);
assert.sameValue(done, false);
}
{
let iterator = g();
let { value, done } = iterator.drop([]).drop([1]).next();
assert.sameValue(value, 2);
assert.sameValue(done, false);
}

View File

@ -0,0 +1,29 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.drop
description: >
The "name" property of Iterator.prototype.drop
info: |
17 ECMAScript Standard Built-in Objects
Every built-in Function object, including constructors, that is not
identified as an anonymous function has a name property whose value is a
String. Unless otherwise specified, this value is the name that is given to
the function in this specification.
...
Unless otherwise specified, the name property of a built-in Function
object, if it exists, has the attributes { [[Writable]]: false,
[[Enumerable]]: false, [[Configurable]]: true }.
features: [iterator-helpers]
includes: [propertyHelper.js]
---*/
verifyProperty(Iterator.prototype.drop, 'name', {
value: 'drop',
writable: false,
enumerable: false,
configurable: true,
});

View File

@ -0,0 +1,33 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.drop
description: >
Underlying iterator next returns non-object
info: |
%Iterator.prototype%.drop ( limit )
6.b.ii. Let next be ? IteratorStep(iterated).
6.c.i. Let next be ? IteratorStep(iterated).
features: [iterator-helpers]
flags: []
---*/
class NonObjectIterator extends Iterator {
next() {
return null;
}
}
let iterator = new NonObjectIterator().drop(0);
assert.throws(TypeError, function () {
iterator.next();
});
iterator = new NonObjectIterator().drop(2);
assert.throws(TypeError, function () {
iterator.next();
});

View File

@ -0,0 +1,41 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.drop
description: >
Underlying iterator next returns object with throwing done getter
info: |
%Iterator.prototype%.drop ( limit )
6.b.ii. Let next be ? IteratorStep(iterated).
6.c.i. Let next be ? IteratorStep(iterated).
features: [iterator-helpers]
flags: []
---*/
class ThrowingIterator extends Iterator {
next() {
return {
get done() {
throw new Test262Error();
},
value: 1,
};
}
return() {
throw new Error();
}
}
let iterator = new ThrowingIterator().drop(0);
assert.throws(Test262Error, function () {
iterator.next();
});
iterator = new ThrowingIterator().drop(1);
assert.throws(Test262Error, function () {
iterator.next();
});

View File

@ -0,0 +1,36 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.drop
description: >
Underlying iterator next returns object with throwing value getter, but is already done
info: |
%Iterator.prototype%.drop ( limit )
6.c.ii. If next is false, return undefined.
features: [iterator-helpers]
flags: []
---*/
class ReturnCalledError extends Error {}
class ValueGetterError extends Error {}
class ThrowingIterator extends Iterator {
next() {
return {
done: true,
get value() {
throw new ValueGetterError();
},
};
}
return() {
throw new ReturnCalledError();
}
}
let iterator = new ThrowingIterator().drop(0);
iterator.next();
iterator = new ThrowingIterator().drop(1);
iterator.next();

View File

@ -0,0 +1,39 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.drop
description: >
Underlying iterator next returns object with throwing value getter
info: |
%Iterator.prototype%.drop ( limit )
6.c.iii. Let completion be Completion(Yield(? IteratorValue(next))).
features: [iterator-helpers]
flags: []
---*/
class ThrowingIterator extends Iterator {
next() {
return {
done: false,
get value() {
throw new Test262Error();
},
};
}
return() {
throw new Error();
}
}
let iterator = new ThrowingIterator().drop(0);
assert.throws(Test262Error, function () {
iterator.next();
});
iterator = new ThrowingIterator().drop(1);
assert.throws(Test262Error, function () {
iterator.next();
});

View File

@ -0,0 +1,33 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.drop
description: >
Underlying iterator has throwing next method
info: |
%Iterator.prototype%.drop ( limit )
6.b.ii. Let next be ? IteratorStep(iterated).
6.c.i. Let next be ? IteratorStep(iterated).
features: [iterator-helpers]
flags: []
---*/
class ThrowingIterator extends Iterator {
next() {
throw new Test262Error();
}
}
let iterator = new ThrowingIterator().drop(0);
assert.throws(Test262Error, function () {
iterator.next();
});
iterator = new ThrowingIterator().drop(1);
assert.throws(Test262Error, function () {
iterator.next();
});

View File

@ -0,0 +1,28 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.drop
description: >
Iterator.prototype.drop is not constructible.
Built-in function objects that are not identified as constructors do not implement the [[Construct]] internal method unless otherwise specified in the description of a particular function.
features: [iterator-helpers]
---*/
function* g() {}
let iter = g();
assert.throws(TypeError, () => {
new iter.drop();
});
assert.throws(TypeError, () => {
new iter.drop(0);
});
assert.throws(TypeError, () => {
new Iterator.prototype.drop(0);
});
assert.throws(TypeError, () => {
new class extends Iterator {}.drop(0);
});

View File

@ -0,0 +1,25 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.drop
description: >
Property descriptor of Iterator.prototype.drop
info: |
Iterator.prototype.drop
* is the initial value of the Iterator.prototype.drop property of the global object.
17 ECMAScript Standard Built-in Objects
Every other data property described in clauses 18 through 26 and in Annex B.2
has the attributes { [[Writable]]: true, [[Enumerable]]: false,
[[Configurable]]: true } unless otherwise specified.
features: [globalThis, iterator-helpers]
includes: [propertyHelper.js]
---*/
verifyProperty(Iterator.prototype, 'drop', {
writable: true,
enumerable: false,
configurable: true,
});

View File

@ -0,0 +1,11 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.drop
description: >
The value of the [[Prototype]] internal slot of Iterator.prototype.drop is the
intrinsic object %FunctionPrototype%.
features: [iterator-helpers]
---*/
assert.sameValue(Object.getPrototypeOf(Iterator.prototype.drop), Function.prototype);

View File

@ -0,0 +1,11 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.drop
description: >
The value of the [[Prototype]] internal slot of the return value of Iterator.prototype.drop is the
intrinsic object %IteratorHelperPrototype%.
features: [iterator-helpers]
---*/
assert((function* () {})().drop(0) instanceof Iterator, 'function*(){}().drop(0) must return an Iterator');

View File

@ -0,0 +1,54 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.drop
description: >
Underlying iterator return is called when result iterator is closed
info: |
%Iterator.prototype%.drop ( limit )
6.c.iii. Let completion be Completion(Yield(? IteratorValue(next))).
6.c.iv. IfAbruptCloseIterator(completion, iterated).
features: [iterator-helpers]
flags: []
---*/
let returnCount = 0;
class TestIterator extends Iterator {
next() {
return {
done: false,
value: 1,
};
}
return() {
++returnCount;
return {};
}
}
let iterator = new TestIterator().drop(0);
assert.sameValue(returnCount, 0);
iterator.return();
assert.sameValue(returnCount, 1);
iterator.return();
assert.sameValue(returnCount, 1);
returnCount = 0;
iterator = new TestIterator().drop(1);
assert.sameValue(returnCount, 0);
iterator.return();
assert.sameValue(returnCount, 1);
iterator.return();
assert.sameValue(returnCount, 1);
returnCount = 0;
iterator = new TestIterator().drop(1).drop(1).drop(1).drop(1).drop(1);
assert.sameValue(returnCount, 0);
iterator.return();
assert.sameValue(returnCount, 1);
iterator.return();
assert.sameValue(returnCount, 1);

View File

@ -0,0 +1,50 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.drop
description: >
Underlying iterator return is not called after result iterator observes that underlying iterator is exhausted
info: |
%Iterator.prototype%.drop ( limit )
features: [iterator-helpers]
flags: []
---*/
let returnCount = 0;
class TestIterator extends Iterator {
next() {
return {
done: true,
value: undefined,
};
}
return() {
throw new Test262Error();
}
}
let iterator = new TestIterator().drop(0);
assert.throws(Test262Error, function () {
iterator.return();
});
iterator.next();
iterator.return();
iterator = new TestIterator().drop(1);
iterator.next();
iterator.return();
iterator = new TestIterator().drop(1);
assert.throws(Test262Error, function () {
iterator.return();
});
iterator.next();
iterator.return();
iterator = new TestIterator().drop(1).drop(1).drop(1).drop(1).drop(1);
assert.throws(Test262Error, function () {
iterator.return();
});
iterator.next();
iterator.return();

View File

@ -0,0 +1,19 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.drop
description: >
Iterator.prototype.drop throws TypeError when its this value is an object with a non-callable next
info: |
%Iterator.prototype%.drop ( limit )
1. Let iterated be ? GetIteratorDirect(this value).
features: [iterator-helpers]
flags: []
---*/
let iter = Iterator.prototype.drop.call({ next: 0 }, 1);
assert.throws(TypeError, function () {
iter.next();
});

View File

@ -0,0 +1,34 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.drop
description: >
Iterator.prototype.drop throws TypeError when its this value is a non-object
info: |
%Iterator.prototype%.drop ( limit )
1. Let iterated be ? GetIteratorDirect(this value).
features: [iterator-helpers]
flags: []
---*/
assert.throws(TypeError, function () {
Iterator.prototype.drop.call(null, 1);
});
assert.throws(TypeError, function () {
Iterator.prototype.drop.call(null, {
valueOf: function () {
throw new Test262Error();
},
});
});
Object.defineProperty(Number.prototype, 'next', {
get: function () {
throw new Test262Error();
},
});
assert.throws(TypeError, function () {
Iterator.prototype.drop.call(0, 1);
});

View File

@ -0,0 +1,30 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.drop
description: >
Iterator.prototype.drop supports a this value that does not inherit from Iterator.prototype but implements the iterator protocol
info: |
%Iterator.prototype%.drop ( limit )
1. Let iterated be ? GetIteratorDirect(this value).
features: [iterator-helpers]
flags: []
---*/
let iter = {
get next() {
let count = 3;
return function () {
--count;
return count >= 0 ? { done: false, value: count } : { done: true, value: undefined };
};
},
};
let dropIter = Iterator.prototype.drop.call(iter, 1);
let { done, value } = dropIter.next();
assert.sameValue(done, false);
assert.sameValue(value, 1);

View File

@ -0,0 +1,39 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.drop
description: >
Underlying iterator is advanced after calling drop
info: |
%Iterator.prototype%.drop ( limit )
features: [iterator-helpers]
flags: []
---*/
let iterator = (function* () {
for (let i = 0; i < 5; ++i) {
yield i;
}
})();
let dropped = iterator.drop(2);
let { value, done } = iterator.next();
assert.sameValue(value, 0);
assert.sameValue(done, false);
({ value, done } = dropped.next());
assert.sameValue(value, 3);
assert.sameValue(done, false);
({ value, done } = dropped.next());
assert.sameValue(value, 4);
assert.sameValue(done, false);
({ value, done } = dropped.next());
assert.sameValue(value, undefined);
assert.sameValue(done, true);

View File

@ -0,0 +1,26 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.drop
description: >
Underlying iterator is closed after calling drop
info: |
%Iterator.prototype%.drop ( limit )
features: [iterator-helpers]
flags: []
---*/
let iterator = (function* () {
for (let i = 0; i < 5; ++i) {
yield i;
}
})();
let dropped = iterator.drop(2);
iterator.return();
let { value, done } = dropped.next();
assert.sameValue(value, undefined);
assert.sameValue(done, true);

View File

@ -0,0 +1,26 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.drop
description: >
Underlying iterator is closed before calling drop
info: |
%Iterator.prototype%.drop ( limit )
features: [iterator-helpers]
flags: []
---*/
let iterator = (function* () {
for (let i = 0; i < 5; ++i) {
yield i;
}
})();
iterator.return();
let dropped = iterator.drop(2);
let { value, done } = dropped.next();
assert.sameValue(value, undefined);
assert.sameValue(done, true);

View File

@ -0,0 +1,30 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.every
description: >
Arguments and this value are evaluated in the correct order
info: |
%Iterator.prototype%.every ( predicate )
includes: [compareArray.js]
features: [iterator-helpers]
flags: []
---*/
let effects = [];
assert.throws(TypeError, function () {
Iterator.prototype.every.call(
{
get next() {
effects.push('get next');
return function () {
return { done: true, value: undefined };
};
},
},
null
);
});
assert.compareArray(effects, []);

View File

@ -0,0 +1,13 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.every
description: >
Iterator.prototype.every is callable
features: [iterator-helpers]
---*/
function* g() {}
Iterator.prototype.every.call(g(), () => {});
let iter = g();
iter.every(() => {});

View File

@ -0,0 +1,38 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.every
description: >
Gets the next method from the iterator only once
info: |
%Iterator.prototype%.every ( predicate )
1. Let iterated be ? GetIteratorDirect(this value).
features: [iterator-helpers]
flags: []
---*/
let nextGets = 0;
class TestIterator extends Iterator {
get next() {
++nextGets;
let counter = 5;
return function () {
if (counter < 0) {
return { done: true, value: undefined };
} else {
return { done: false, value: --counter };
}
};
}
}
let iterator = new TestIterator();
assert.sameValue(nextGets, 0);
assert.sameValue(
iterator.every(() => true),
true
);
assert.sameValue(nextGets, 1);

View File

@ -0,0 +1,25 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.every
description: >
Iterator has throwing next getter
info: |
%Iterator.prototype%.every ( predicate )
1. Let iterated be ? GetIteratorDirect(this value).
features: [iterator-helpers]
flags: []
---*/
class IteratorThrows extends Iterator {
get next() {
throw new Test262Error();
}
}
let iterator = new IteratorThrows();
assert.throws(Test262Error, function () {
iterator.every(() => {});
});

View File

@ -0,0 +1,31 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.every
description: >
Iterator has throwing return getter
info: |
%Iterator.prototype%.every ( predicate )
4.f. If ToBoolean(result) is false, return ? IteratorClose(iterated, NormalCompletion(false)).
features: [iterator-helpers]
flags: []
---*/
class IteratorThrows extends Iterator {
next() {
return {
done: false,
value: 0,
};
}
get return() {
throw new Test262Error();
}
}
let iterator = new IteratorThrows([1, 2]);
assert.throws(Test262Error, function () {
iterator.every(() => false);
});

View File

@ -0,0 +1,10 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.every
description: >
Iterator.prototype.every is a built-in function
features: [iterator-helpers]
---*/
assert.sameValue(typeof Iterator.prototype.every, 'function');

View File

@ -0,0 +1,26 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.every
description: >
Iterator.prototype.every returns true when the iterator has already been exhausted
info: |
%Iterator.prototype%.every ( predicate )
4.a. Let next be ? IteratorStep(iterated).
4.b. If next is false, return true.
features: [iterator-helpers]
flags: []
---*/
let iterator = (function* () {})();
let { value, done } = iterator.next();
assert.sameValue(value, undefined);
assert.sameValue(done, true);
let result = iterator.every(() => true);
assert.sameValue(result, true);
result = iterator.every(() => false);
assert.sameValue(result, true);

View File

@ -0,0 +1,27 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.every
description: >
The underlying iterator is sometimes unable to be closed (has no return method)
info: |
%Iterator.prototype%.every ( predicate )
features: [iterator-helpers]
flags: []
---*/
let iterator = [1, 2, 3, 4, 5][Symbol.iterator]();
assert.sameValue(iterator.return, undefined);
let ret = iterator.every(v => v < 4);
assert.sameValue(ret, false);
let { done, value } = iterator.next();
assert.sameValue(done, false);
assert.sameValue(value, 5);
({ done, value } = iterator.next());
assert.sameValue(done, true);
assert.sameValue(value, undefined);

View File

@ -0,0 +1,31 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.every
description: >
Iterator has throwing return
info: |
%Iterator.prototype%.every ( predicate )
4.f. If ToBoolean(result) is false, return ? IteratorClose(iterated, NormalCompletion(false)).
features: [iterator-helpers]
flags: []
---*/
class IteratorThrows extends Iterator {
next() {
return {
done: false,
value: 0,
};
}
return() {
throw new Test262Error();
}
}
let iterator = new IteratorThrows();
assert.throws(Test262Error, function () {
iterator.every(() => false);
});

View File

@ -0,0 +1,22 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.every
description: >
Iterator.prototype.every has a "length" property whose value is 1.
info: |
ECMAScript Standard Built-in Objects
Unless otherwise specified, the length property of a built-in
Function object has the attributes { [[Writable]]: false, [[Enumerable]]:
false, [[Configurable]]: true }.
features: [iterator-helpers]
includes: [propertyHelper.js]
---*/
verifyProperty(Iterator.prototype.every, 'length', {
value: 1,
writable: false,
enumerable: false,
configurable: true,
});

View File

@ -0,0 +1,29 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.every
description: >
The "name" property of Iterator.prototype.every
info: |
17 ECMAScript Standard Built-in Objects
Every built-in Function object, including constructors, that is not
identified as an anonymous function has a name property whose value is a
String. Unless otherwise specified, this value is the name that is given to
the function in this specification.
...
Unless otherwise specified, the name property of a built-in Function
object, if it exists, has the attributes { [[Writable]]: false,
[[Enumerable]]: false, [[Configurable]]: true }.
features: [iterator-helpers]
includes: [propertyHelper.js]
---*/
verifyProperty(Iterator.prototype.every, 'name', {
value: 'every',
writable: false,
enumerable: false,
configurable: true,
});

View File

@ -0,0 +1,25 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.every
description: >
Underlying iterator next returns non-object
info: |
%Iterator.prototype%.every ( predicate )
4.a. Let next be ? IteratorStep(iterated).
features: [iterator-helpers]
flags: []
---*/
class NonObjectIterator extends Iterator {
next() {
return null;
}
}
let iterator = new NonObjectIterator();
assert.throws(TypeError, function () {
iterator.every(() => {});
});

View File

@ -0,0 +1,33 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.every
description: >
Underlying iterator next returns object with throwing done getter
info: |
%Iterator.prototype%.every ( predicate )
4.a. Let next be ? IteratorStep(iterated).
features: [iterator-helpers]
flags: []
---*/
class ThrowingIterator extends Iterator {
next() {
return {
get done() {
throw new Test262Error();
},
value: 1,
};
}
return() {
throw new Error();
}
}
let iterator = new ThrowingIterator();
assert.throws(Test262Error, function () {
iterator.every(() => {});
});

View File

@ -0,0 +1,30 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.every
description: >
Underlying iterator next returns object with throwing value getter, but is already done
info: |
%Iterator.prototype%.every ( predicate )
4.c. Let value be ? IteratorValue(next).
features: [iterator-helpers]
flags: []
---*/
class ThrowingIterator extends Iterator {
next() {
return {
done: true,
get value() {
throw new Test262Error();
},
};
}
return() {
throw new Error();
}
}
let iterator = new ThrowingIterator();
iterator.every(() => {});

View File

@ -0,0 +1,33 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.every
description: >
Underlying iterator next returns object with throwing value getter
info: |
%Iterator.prototype%.every ( predicate )
4.c. Let value be ? IteratorValue(next).
features: [iterator-helpers]
flags: []
---*/
class ThrowingIterator extends Iterator {
next() {
return {
done: false,
get value() {
throw new Test262Error();
},
};
}
return() {
throw new Error();
}
}
let iterator = new ThrowingIterator();
assert.throws(Test262Error, function () {
iterator.every(() => {});
});

View File

@ -0,0 +1,25 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.every
description: >
Underlying iterator has throwing next method
info: |
%Iterator.prototype%.every ( predicate )
4.a. Let next be ? IteratorStep(iterated).
features: [iterator-helpers]
flags: []
---*/
class ThrowingIterator extends Iterator {
next() {
throw new Test262Error();
}
}
let iterator = new ThrowingIterator();
assert.throws(Test262Error, function () {
iterator.every(() => {});
});

View File

@ -0,0 +1,22 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.every
description: >
Iterator.prototype.every expects to be called with a callable argument.
info: |
%Iterator.prototype%.every ( predicate )
2. If IsCallable(predicate) is false, throw a TypeError exception.
features: [iterator-helpers]
flags: []
---*/
let nonCallable = {};
let iterator = (function* () {
yield 1;
})();
assert.throws(TypeError, function () {
iterator.every(nonCallable);
});

View File

@ -0,0 +1,28 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.every
description: >
Iterator.prototype.every is not constructible.
Built-in function objects that are not identified as constructors do not implement the [[Construct]] internal method unless otherwise specified in the description of a particular function.
features: [iterator-helpers]
---*/
function* g() {}
let iter = g();
assert.throws(TypeError, () => {
new iter.every();
});
assert.throws(TypeError, () => {
new iter.every(() => {});
});
assert.throws(TypeError, () => {
new Iterator.prototype.every(() => {});
});
assert.throws(TypeError, () => {
new class extends Iterator {}.every(() => {});
});

View File

@ -0,0 +1,43 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.every
description: >
Iterator.prototype.every predicate is passed the yielded value and a counter as arguments
info: |
%Iterator.prototype%.every ( predicate )
4.d. Let result be Completion(Call(predicate, undefined, « value, 𝔽(counter) »)).
features: [iterator-helpers]
flags: []
---*/
function* g() {
yield 'a';
yield 'b';
yield 'c';
}
let iter = g();
let assertionCount = 0;
let result = iter.every((v, count) => {
switch (v) {
case 'a':
assert.sameValue(count, 0);
break;
case 'b':
assert.sameValue(count, 1);
break;
case 'c':
assert.sameValue(count, 2);
break;
default:
throw new Error();
}
++assertionCount;
return true;
});
assert.sameValue(result, true);
assert.sameValue(assertionCount, 3);

View File

@ -0,0 +1,33 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.every
description: >
Iterator.prototype.every returns false and closes the iterator when the predicate returns falsey immediately
info: |
%Iterator.prototype%.every ( predicate )
4.f. If ToBoolean(result) is false, return ? IteratorClose(iterated, NormalCompletion(false)).
features: [iterator-helpers]
flags: []
---*/
function* g() {
yield 0;
yield 1;
}
let iter = g();
let predicateCalls = 0;
let result = iter.every(v => {
++predicateCalls;
return false;
});
assert.sameValue(result, false);
assert.sameValue(predicateCalls, 1);
let { done, value } = iter.next();
assert.sameValue(done, true);
assert.sameValue(value, undefined);

View File

@ -0,0 +1,30 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.every
description: >
Iterator.prototype.every coerces predicate return value to boolean
info: |
%Iterator.prototype%.every ( predicate )
4.f. If ToBoolean(result) is false, return ? IteratorClose(iterated, NormalCompletion(false)).
features: [iterator-helpers]
flags: []
---*/
function* g() {
for (let i = 4; i >= 0; --i) {
yield i;
}
}
let iter = g();
let predicateCalls = 0;
let result = iter.every(v => {
++predicateCalls;
return v;
});
assert.sameValue(result, false);
assert.sameValue(predicateCalls, 5);

View File

@ -0,0 +1,34 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.every
description: >
Iterator.prototype.every returns false and closes the iterator when the predicate returns truthy for some iterated values and falsey for others
info: |
%Iterator.prototype%.every ( predicate )
4.f. If ToBoolean(result) is false, return ? IteratorClose(iterated, NormalCompletion(false)).
features: [iterator-helpers]
flags: []
---*/
function* g() {
for (let i = 0; i < 5; ++i) {
yield i;
}
}
let iter = g();
let predicateCalls = 0;
let result = iter.every(v => {
++predicateCalls;
return v < 3;
});
assert.sameValue(result, false);
assert.sameValue(predicateCalls, 4);
let { done, value } = iter.next();
assert.sameValue(done, true);
assert.sameValue(value, undefined);

View File

@ -0,0 +1,24 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.every
description: >
Iterator.prototype.every returns true when the predicate returns truthy for all iterated values
info: |
%Iterator.prototype%.every ( predicate )
4.b. If next is false, return true.
features: [iterator-helpers]
flags: []
---*/
function* g() {
yield 0;
yield 1;
yield 2;
yield 3;
yield 4;
}
let result = g().every(() => true);
assert.sameValue(result, true);

View File

@ -0,0 +1,33 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.every
description: >
Iterator.prototype.every predicate this value is undefined
info: |
%Iterator.prototype%.every ( predicate )
4.d. Let result be Completion(Call(predicate, undefined, « value, 𝔽(counter) »)).
features: [iterator-helpers]
flags: []
---*/
function* g() {
yield 0;
}
let iter = g();
let expectedThis = function () {
return this;
}.call(undefined);
let assertionCount = 0;
let result = iter.every(function (v, count) {
assert.sameValue(this, expectedThis);
++assertionCount;
return true;
});
assert.sameValue(result, true);
assert.sameValue(assertionCount, 1);

View File

@ -0,0 +1,39 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.every
description: >
Attempts to close iterator when predicate throws, but that throws
info: |
%Iterator.prototype%.every ( predicate )
4.d. Let result be Completion(Call(predicate, undefined, « value, 𝔽(counter) »)).
4.e. IfAbruptCloseIterator(result, iterated).
features: [iterator-helpers]
flags: []
---*/
let returnCalls = 0;
class TestIterator extends Iterator {
next() {
return {
done: false,
value: 1,
};
}
return() {
++returnCalls;
throw new Error();
}
}
let iterator = new TestIterator();
assert.throws(Test262Error, function () {
iterator.every(() => {
throw new Test262Error();
});
});
assert.sameValue(returnCalls, 1);

View File

@ -0,0 +1,43 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.every
description: >
Closes iterator and throws when predicate throws
info: |
%Iterator.prototype%.every ( predicate )
4.d. Let result be Completion(Call(predicate, undefined, « value, 𝔽(counter) »)).
4.e. IfAbruptCloseIterator(result, iterated).
features: [iterator-helpers]
flags: []
---*/
let returnCalls = 0;
class TestIterator extends Iterator {
next() {
return {
done: false,
value: 1,
};
}
return() {
++returnCalls;
return {};
}
}
let iterator = new TestIterator();
let callbackCalls = 0;
assert.throws(Test262Error, function () {
iterator.every(() => {
++callbackCalls;
throw new Test262Error();
});
});
assert.sameValue(callbackCalls, 1);
assert.sameValue(returnCalls, 1);

View File

@ -0,0 +1,25 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.every
description: >
Property descriptor of Iterator.prototype.every
info: |
Iterator.prototype.every
* is the initial value of the Iterator.prototype.every property of the global object.
17 ECMAScript Standard Built-in Objects
Every other data property described in clauses 18 through 26 and in Annex B.2
has the attributes { [[Writable]]: true, [[Enumerable]]: false,
[[Configurable]]: true } unless otherwise specified.
features: [globalThis, iterator-helpers]
includes: [propertyHelper.js]
---*/
verifyProperty(Iterator.prototype, 'every', {
writable: true,
enumerable: false,
configurable: true,
});

View File

@ -0,0 +1,11 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.every
description: >
The value of the [[Prototype]] internal slot of Iterator.prototype.every is the
intrinsic object %Function%.
features: [iterator-helpers]
---*/
assert.sameValue(Object.getPrototypeOf(Iterator.prototype.every), Function.prototype);

View File

@ -0,0 +1,11 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.every
description: >
Iterator.prototype.every returns a boolean
features: [iterator-helpers]
---*/
function* g() {}
let iter = g();
assert.sameValue(typeof iter.every(() => {}), 'boolean');

View File

@ -0,0 +1,17 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.every
description: >
Iterator.prototype.every throws TypeError when its this value is an object with a non-callable next
info: |
%Iterator.prototype%.every ( predicate )
1. Let iterated be ? GetIteratorDirect(this value).
features: [iterator-helpers]
flags: []
---*/
assert.throws(TypeError, function () {
Iterator.prototype.every.call({ next: 0 }, () => true);
});

View File

@ -0,0 +1,26 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.every
description: >
Iterator.prototype.every throws TypeError when its this value is a non-object
info: |
%Iterator.prototype%.every ( predicate )
1. Let iterated be ? GetIteratorDirect(this value).
features: [iterator-helpers]
flags: []
---*/
assert.throws(TypeError, function () {
Iterator.prototype.every.call(null, () => {});
});
Object.defineProperty(Number.prototype, 'next', {
get: function () {
throw new Test262Error();
},
});
assert.throws(TypeError, function () {
Iterator.prototype.every.call(0, () => {});
});

View File

@ -0,0 +1,32 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.every
description: >
Iterator.prototype.every supports a this value that does not inherit from Iterator.prototype but implements the iterator protocol
info: |
%Iterator.prototype%.every ( predicate )
1. Let iterated be ? GetIteratorDirect(this value).
features: [iterator-helpers]
flags: []
---*/
let iter = {
get next() {
let count = 3;
return function () {
--count;
return count >= 0 ? { done: false, value: count } : { done: true, value: undefined };
};
},
};
let predicateCalls = 0;
let result = Iterator.prototype.every.call(iter, function (v) {
++predicateCalls;
return v;
});
assert.sameValue(result, false);
assert.sameValue(predicateCalls, 3);

View File

@ -0,0 +1,30 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.filter
description: >
Arguments and this value are evaluated in the correct order
info: |
%Iterator.prototype%.filter ( predicate )
includes: [compareArray.js]
features: [iterator-helpers]
flags: []
---*/
let effects = [];
assert.throws(TypeError, function () {
Iterator.prototype.filter.call(
{
get next() {
effects.push('get next');
return function () {
return { done: true, value: undefined };
};
},
},
null
);
});
assert.compareArray(effects, []);

View File

@ -0,0 +1,13 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.filter
description: >
Iterator.prototype.filter is callable
features: [iterator-helpers]
---*/
function* g() {}
Iterator.prototype.filter.call(g(), () => false);
let iter = g();
iter.filter(() => false);

View File

@ -0,0 +1,37 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.filter
description: >
Underlying iterator return is not called when result iterator is exhausted
info: |
%Iterator.prototype%.filter ( predicate )
3.b.i. Let next be ? IteratorStep(iterated).
3.b.ii. If next is false, return undefined.
features: [iterator-helpers]
flags: []
---*/
function* g() {
yield 0;
yield 1;
yield 2;
}
class TestIterator extends Iterator {
get next() {
let n = g();
return function() {
return n.next();
};
}
return() {
throw new Test262Error();
}
}
let iterator = new TestIterator().filter(() => false);
iterator.next();
iterator.next();
iterator.next();

View File

@ -0,0 +1,41 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.filter
description: >
Gets the next method from the underlying iterator only once
info: |
%Iterator.prototype%.filter ( predicate )
1. Let iterated be ? GetIteratorDirect(this value).
features: [iterator-helpers]
flags: []
---*/
let nextGets = 0;
let nextCalls = 0;
class CountingIterator extends Iterator {
get next() {
++nextGets;
let iter = (function* () {
for (let i = 1; i < 5; ++i) {
yield i;
}
})();
return function () {
++nextCalls;
return iter.next();
};
}
}
let iterator = new CountingIterator();
assert.sameValue(nextGets, 0);
assert.sameValue(nextCalls, 0);
for (const value of iterator.filter(() => false));
assert.sameValue(nextGets, 1);
assert.sameValue(nextCalls, 5);

View File

@ -0,0 +1,25 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.filter
description: >
Underlying iterator has throwing next getter
info: |
%Iterator.prototype%.filter ( predicate )
1. Let iterated be ? GetIteratorDirect(this value).
features: [iterator-helpers]
flags: []
---*/
class ThrowingIterator extends Iterator {
get next() {
throw new Test262Error();
}
}
let iterator = new ThrowingIterator();
assert.throws(Test262Error, function () {
iterator.filter(() => false);
});

View File

@ -0,0 +1,30 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.filter
description: >
Underlying iterator return is throwing getter
info: |
%Iterator.prototype%.filter ( predicate )
features: [iterator-helpers]
flags: []
---*/
class TestIterator extends Iterator {
next() {
return {
done: false,
value: 1,
};
}
get return() {
throw new Test262Error();
}
}
let iterator = new TestIterator().filter(() => true);
iterator.next();
assert.throws(Test262Error, function () {
iterator.return();
});

View File

@ -0,0 +1,10 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iteratorprototype.filter
description: >
Iterator.prototype.filter is a built-in function
features: [iterator-helpers]
---*/
assert.sameValue(typeof Iterator.prototype.filter, 'function');

Some files were not shown because too many files have changed in this diff Show More