mirror of
https://github.com/tc39/test262.git
synced 2025-07-20 20:44:43 +02:00
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:
parent
e337fc9506
commit
dfc7ce4c28
@ -104,6 +104,10 @@ String.prototype.toWellFormed
|
|||||||
# https://github.com/tc39/proposal-json-parse-with-source
|
# https://github.com/tc39/proposal-json-parse-with-source
|
||||||
json-parse-with-source
|
json-parse-with-source
|
||||||
|
|
||||||
|
# Iterator Helpers
|
||||||
|
# https://github.com/tc39/proposal-iterator-helpers
|
||||||
|
iterator-helpers
|
||||||
|
|
||||||
## Standard language features
|
## Standard language features
|
||||||
#
|
#
|
||||||
# Language features that have been included in a published version of the
|
# Language features that have been included in a published version of the
|
||||||
|
11
test/built-ins/Iterator/constructor.js
Normal file
11
test/built-ins/Iterator/constructor.js
Normal 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"');
|
12
test/built-ins/Iterator/from/callable.js
Normal file
12
test/built-ins/Iterator/from/callable.js
Normal 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());
|
46
test/built-ins/Iterator/from/get-next-method-only-once.js
Normal file
46
test/built-ins/Iterator/from/get-next-method-only-once.js
Normal 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');
|
25
test/built-ins/Iterator/from/get-next-method-throws.js
Normal file
25
test/built-ins/Iterator/from/get-next-method-throws.js
Normal 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);
|
||||||
|
});
|
10
test/built-ins/Iterator/from/is-function.js
Normal file
10
test/built-ins/Iterator/from/is-function.js
Normal 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"');
|
39
test/built-ins/Iterator/from/iterable-primitives.js
Normal file
39
test/built-ins/Iterator/from/iterable-primitives.js
Normal 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']);
|
@ -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]);
|
22
test/built-ins/Iterator/from/length.js
Normal file
22
test/built-ins/Iterator/from/length.js
Normal 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,
|
||||||
|
});
|
29
test/built-ins/Iterator/from/name.js
Normal file
29
test/built-ins/Iterator/from/name.js
Normal 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,
|
||||||
|
});
|
23
test/built-ins/Iterator/from/non-constructible.js
Normal file
23
test/built-ins/Iterator/from/non-constructible.js
Normal 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());
|
||||||
|
});
|
38
test/built-ins/Iterator/from/primitives.js
Normal file
38
test/built-ins/Iterator/from/primitives.js
Normal 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');
|
26
test/built-ins/Iterator/from/prop-desc.js
Normal file
26
test/built-ins/Iterator/from/prop-desc.js
Normal 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,
|
||||||
|
});
|
15
test/built-ins/Iterator/from/proto.js
Normal file
15
test/built-ins/Iterator/from/proto.js
Normal 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'
|
||||||
|
);
|
29
test/built-ins/Iterator/from/result-proto.js
Normal file
29
test/built-ins/Iterator/from/result-proto.js
Normal 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);
|
14
test/built-ins/Iterator/from/supports-iterable.js
Normal file
14
test/built-ins/Iterator/from/supports-iterable.js
Normal 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]);
|
29
test/built-ins/Iterator/from/supports-iterator.js
Normal file
29
test/built-ins/Iterator/from/supports-iterator.js
Normal 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]);
|
26
test/built-ins/Iterator/length.js
Normal file
26
test/built-ins/Iterator/length.js
Normal 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,
|
||||||
|
});
|
30
test/built-ins/Iterator/name.js
Normal file
30
test/built-ins/Iterator/name.js
Normal 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,
|
||||||
|
});
|
@ -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();
|
||||||
|
});
|
27
test/built-ins/Iterator/prop-desc.js
Normal file
27
test/built-ins/Iterator/prop-desc.js
Normal 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,
|
||||||
|
});
|
36
test/built-ins/Iterator/proto-from-ctor-realm.js
Normal file
36
test/built-ins/Iterator/proto-from-ctor-realm.js
Normal 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);
|
16
test/built-ins/Iterator/proto.js
Normal file
16
test/built-ins/Iterator/proto.js
Normal 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'
|
||||||
|
);
|
13
test/built-ins/Iterator/prototype/Symbol.iterator/is-function.js
vendored
Normal file
13
test/built-ins/Iterator/prototype/Symbol.iterator/is-function.js
vendored
Normal 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');
|
@ -2,7 +2,7 @@
|
|||||||
// This code is governed by the BSD license found in the LICENSE file.
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
/*---
|
/*---
|
||||||
es6id: 25.1.2.1
|
es6id: 25.1.2.1
|
||||||
description: Length of IteratorPrototype[ @@iterator ]
|
description: Length of %IteratorPrototype%[ @@iterator ]
|
||||||
info: |
|
info: |
|
||||||
ES6 Section 17:
|
ES6 Section 17:
|
||||||
Every built-in Function object, including constructors, has a length
|
Every built-in Function object, including constructors, has a length
|
||||||
@ -18,13 +18,13 @@ info: |
|
|||||||
features: [Symbol.iterator]
|
features: [Symbol.iterator]
|
||||||
includes: [propertyHelper.js]
|
includes: [propertyHelper.js]
|
||||||
---*/
|
---*/
|
||||||
|
const IteratorPrototype = Object.getPrototypeOf(
|
||||||
var IteratorPrototype = Object.getPrototypeOf(
|
|
||||||
Object.getPrototypeOf([][Symbol.iterator]())
|
Object.getPrototypeOf([][Symbol.iterator]())
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.sameValue(IteratorPrototype[Symbol.iterator].length, 0);
|
verifyProperty(IteratorPrototype[Symbol.iterator], 'length', {
|
||||||
|
value: 0,
|
||||||
verifyNotEnumerable(IteratorPrototype[Symbol.iterator], 'length');
|
writable: false,
|
||||||
verifyNotWritable(IteratorPrototype[Symbol.iterator], 'length');
|
enumerable: false,
|
||||||
verifyConfigurable(IteratorPrototype[Symbol.iterator], 'length');
|
configurable: true,
|
||||||
|
});
|
@ -21,13 +21,13 @@ info: |
|
|||||||
features: [Symbol.iterator]
|
features: [Symbol.iterator]
|
||||||
includes: [propertyHelper.js]
|
includes: [propertyHelper.js]
|
||||||
---*/
|
---*/
|
||||||
|
const IteratorPrototype = Object.getPrototypeOf(
|
||||||
var IteratorPrototype = Object.getPrototypeOf(
|
|
||||||
Object.getPrototypeOf([][Symbol.iterator]())
|
Object.getPrototypeOf([][Symbol.iterator]())
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.sameValue(IteratorPrototype[Symbol.iterator].name, '[Symbol.iterator]');
|
verifyProperty(IteratorPrototype[Symbol.iterator], 'name', {
|
||||||
|
value: '[Symbol.iterator]',
|
||||||
verifyNotEnumerable(IteratorPrototype[Symbol.iterator], 'name');
|
writable: false,
|
||||||
verifyNotWritable(IteratorPrototype[Symbol.iterator], 'name');
|
enumerable: false,
|
||||||
verifyConfigurable(IteratorPrototype[Symbol.iterator], 'name');
|
configurable: true,
|
||||||
|
});
|
@ -12,12 +12,12 @@ info: |
|
|||||||
features: [Symbol.iterator]
|
features: [Symbol.iterator]
|
||||||
includes: [propertyHelper.js]
|
includes: [propertyHelper.js]
|
||||||
---*/
|
---*/
|
||||||
|
const IteratorPrototype = Object.getPrototypeOf(
|
||||||
var IteratorPrototype = Object.getPrototypeOf(
|
|
||||||
Object.getPrototypeOf([][Symbol.iterator]())
|
Object.getPrototypeOf([][Symbol.iterator]())
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.sameValue(typeof IteratorPrototype[Symbol.iterator], 'function');
|
verifyProperty(IteratorPrototype, Symbol.iterator, {
|
||||||
verifyNotEnumerable(IteratorPrototype, Symbol.iterator);
|
writable: true,
|
||||||
verifyWritable(IteratorPrototype, Symbol.iterator);
|
enumerable: false,
|
||||||
verifyConfigurable(IteratorPrototype, Symbol.iterator);
|
configurable: true,
|
||||||
|
});
|
@ -2,31 +2,20 @@
|
|||||||
// This code is governed by the BSD license found in the LICENSE file.
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
/*---
|
/*---
|
||||||
esid: sec-%iteratorprototype%-@@iterator
|
esid: sec-%iteratorprototype%-@@iterator
|
||||||
description: Return value of @@iterator on IteratorPrototype
|
description: Return value of @@iterator on %IteratorPrototype%
|
||||||
info: |
|
info: |
|
||||||
%IteratorPrototype% [ @@iterator ] ( )
|
%IteratorPrototype% [ @@iterator ] ( )
|
||||||
1. Return the this value.
|
1. Return the this value.
|
||||||
features: [Symbol.iterator]
|
features: [Symbol.iterator]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
const IteratorPrototype = Object.getPrototypeOf(
|
const IteratorPrototype = Object.getPrototypeOf(
|
||||||
Object.getPrototypeOf([][Symbol.iterator]())
|
Object.getPrototypeOf([][Symbol.iterator]())
|
||||||
);
|
);
|
||||||
|
|
||||||
const getIterator = IteratorPrototype[Symbol.iterator];
|
const getIterator = IteratorPrototype[Symbol.iterator];
|
||||||
|
|
||||||
const thisValues = [
|
const thisValues = [{}, Symbol(), 4, 4n, true, undefined, null];
|
||||||
{},
|
|
||||||
Symbol(),
|
|
||||||
4,
|
|
||||||
4n,
|
|
||||||
true,
|
|
||||||
undefined,
|
|
||||||
null,
|
|
||||||
];
|
|
||||||
|
|
||||||
for (const thisValue of thisValues) {
|
for (const thisValue of thisValues) {
|
||||||
assert.sameValue(
|
assert.sameValue(getIterator.call(thisValue), thisValue);
|
||||||
getIterator.call(thisValue),
|
|
||||||
thisValue
|
|
||||||
);
|
|
||||||
}
|
}
|
20
test/built-ins/Iterator/prototype/Symbol.toStringTag/prop-desc.js
vendored
Normal file
20
test/built-ins/Iterator/prototype/Symbol.toStringTag/prop-desc.js
vendored
Normal 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,
|
||||||
|
});
|
64
test/built-ins/Iterator/prototype/drop/argument-effect-order.js
vendored
Normal file
64
test/built-ins/Iterator/prototype/drop/argument-effect-order.js
vendored
Normal 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, []);
|
13
test/built-ins/Iterator/prototype/drop/callable.js
vendored
Normal file
13
test/built-ins/Iterator/prototype/drop/callable.js
vendored
Normal 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);
|
60
test/built-ins/Iterator/prototype/drop/exhaustion-does-not-call-return.js
vendored
Normal file
60
test/built-ins/Iterator/prototype/drop/exhaustion-does-not-call-return.js
vendored
Normal 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();
|
41
test/built-ins/Iterator/prototype/drop/get-next-method-only-once.js
vendored
Normal file
41
test/built-ins/Iterator/prototype/drop/get-next-method-only-once.js
vendored
Normal 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);
|
25
test/built-ins/Iterator/prototype/drop/get-next-method-throws.js
vendored
Normal file
25
test/built-ins/Iterator/prototype/drop/get-next-method-throws.js
vendored
Normal 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);
|
||||||
|
});
|
30
test/built-ins/Iterator/prototype/drop/get-return-method-throws.js
vendored
Normal file
30
test/built-ins/Iterator/prototype/drop/get-return-method-throws.js
vendored
Normal 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();
|
||||||
|
});
|
10
test/built-ins/Iterator/prototype/drop/is-function.js
vendored
Normal file
10
test/built-ins/Iterator/prototype/drop/is-function.js
vendored
Normal 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');
|
22
test/built-ins/Iterator/prototype/drop/length.js
vendored
Normal file
22
test/built-ins/Iterator/prototype/drop/length.js
vendored
Normal 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,
|
||||||
|
});
|
22
test/built-ins/Iterator/prototype/drop/limit-equals-total.js
vendored
Normal file
22
test/built-ins/Iterator/prototype/drop/limit-equals-total.js
vendored
Normal 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);
|
37
test/built-ins/Iterator/prototype/drop/limit-greater-than-total.js
vendored
Normal file
37
test/built-ins/Iterator/prototype/drop/limit-greater-than-total.js
vendored
Normal 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);
|
||||||
|
}
|
30
test/built-ins/Iterator/prototype/drop/limit-less-than-total.js
vendored
Normal file
30
test/built-ins/Iterator/prototype/drop/limit-less-than-total.js
vendored
Normal 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);
|
||||||
|
}
|
36
test/built-ins/Iterator/prototype/drop/limit-rangeerror.js
vendored
Normal file
36
test/built-ins/Iterator/prototype/drop/limit-rangeerror.js
vendored
Normal 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);
|
||||||
|
});
|
22
test/built-ins/Iterator/prototype/drop/limit-tonumber-throws.js
vendored
Normal file
22
test/built-ins/Iterator/prototype/drop/limit-tonumber-throws.js
vendored
Normal 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();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
37
test/built-ins/Iterator/prototype/drop/limit-tonumber.js
vendored
Normal file
37
test/built-ins/Iterator/prototype/drop/limit-tonumber.js
vendored
Normal 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);
|
||||||
|
}
|
29
test/built-ins/Iterator/prototype/drop/name.js
vendored
Normal file
29
test/built-ins/Iterator/prototype/drop/name.js
vendored
Normal 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,
|
||||||
|
});
|
33
test/built-ins/Iterator/prototype/drop/next-method-returns-non-object.js
vendored
Normal file
33
test/built-ins/Iterator/prototype/drop/next-method-returns-non-object.js
vendored
Normal 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();
|
||||||
|
});
|
41
test/built-ins/Iterator/prototype/drop/next-method-returns-throwing-done.js
vendored
Normal file
41
test/built-ins/Iterator/prototype/drop/next-method-returns-throwing-done.js
vendored
Normal 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();
|
||||||
|
});
|
36
test/built-ins/Iterator/prototype/drop/next-method-returns-throwing-value-done.js
vendored
Normal file
36
test/built-ins/Iterator/prototype/drop/next-method-returns-throwing-value-done.js
vendored
Normal 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();
|
39
test/built-ins/Iterator/prototype/drop/next-method-returns-throwing-value.js
vendored
Normal file
39
test/built-ins/Iterator/prototype/drop/next-method-returns-throwing-value.js
vendored
Normal 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();
|
||||||
|
});
|
33
test/built-ins/Iterator/prototype/drop/next-method-throws.js
vendored
Normal file
33
test/built-ins/Iterator/prototype/drop/next-method-throws.js
vendored
Normal 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();
|
||||||
|
});
|
28
test/built-ins/Iterator/prototype/drop/non-constructible.js
vendored
Normal file
28
test/built-ins/Iterator/prototype/drop/non-constructible.js
vendored
Normal 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);
|
||||||
|
});
|
25
test/built-ins/Iterator/prototype/drop/prop-desc.js
vendored
Normal file
25
test/built-ins/Iterator/prototype/drop/prop-desc.js
vendored
Normal 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,
|
||||||
|
});
|
11
test/built-ins/Iterator/prototype/drop/proto.js
vendored
Normal file
11
test/built-ins/Iterator/prototype/drop/proto.js
vendored
Normal 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);
|
11
test/built-ins/Iterator/prototype/drop/result-is-iterator.js
vendored
Normal file
11
test/built-ins/Iterator/prototype/drop/result-is-iterator.js
vendored
Normal 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');
|
54
test/built-ins/Iterator/prototype/drop/return-is-forwarded.js
vendored
Normal file
54
test/built-ins/Iterator/prototype/drop/return-is-forwarded.js
vendored
Normal 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);
|
50
test/built-ins/Iterator/prototype/drop/return-is-not-forwarded-after-exhaustion.js
vendored
Normal file
50
test/built-ins/Iterator/prototype/drop/return-is-not-forwarded-after-exhaustion.js
vendored
Normal 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();
|
19
test/built-ins/Iterator/prototype/drop/this-non-callable-next.js
vendored
Normal file
19
test/built-ins/Iterator/prototype/drop/this-non-callable-next.js
vendored
Normal 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();
|
||||||
|
});
|
34
test/built-ins/Iterator/prototype/drop/this-non-object.js
vendored
Normal file
34
test/built-ins/Iterator/prototype/drop/this-non-object.js
vendored
Normal 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);
|
||||||
|
});
|
30
test/built-ins/Iterator/prototype/drop/this-plain-iterator.js
vendored
Normal file
30
test/built-ins/Iterator/prototype/drop/this-plain-iterator.js
vendored
Normal 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);
|
39
test/built-ins/Iterator/prototype/drop/underlying-iterator-advanced-in-parallel.js
vendored
Normal file
39
test/built-ins/Iterator/prototype/drop/underlying-iterator-advanced-in-parallel.js
vendored
Normal 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);
|
26
test/built-ins/Iterator/prototype/drop/underlying-iterator-closed-in-parallel.js
vendored
Normal file
26
test/built-ins/Iterator/prototype/drop/underlying-iterator-closed-in-parallel.js
vendored
Normal 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);
|
26
test/built-ins/Iterator/prototype/drop/underlying-iterator-closed.js
vendored
Normal file
26
test/built-ins/Iterator/prototype/drop/underlying-iterator-closed.js
vendored
Normal 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);
|
30
test/built-ins/Iterator/prototype/every/argument-effect-order.js
vendored
Normal file
30
test/built-ins/Iterator/prototype/every/argument-effect-order.js
vendored
Normal 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, []);
|
13
test/built-ins/Iterator/prototype/every/callable.js
vendored
Normal file
13
test/built-ins/Iterator/prototype/every/callable.js
vendored
Normal 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(() => {});
|
38
test/built-ins/Iterator/prototype/every/get-next-method-only-once.js
vendored
Normal file
38
test/built-ins/Iterator/prototype/every/get-next-method-only-once.js
vendored
Normal 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);
|
25
test/built-ins/Iterator/prototype/every/get-next-method-throws.js
vendored
Normal file
25
test/built-ins/Iterator/prototype/every/get-next-method-throws.js
vendored
Normal 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(() => {});
|
||||||
|
});
|
31
test/built-ins/Iterator/prototype/every/get-return-method-throws.js
vendored
Normal file
31
test/built-ins/Iterator/prototype/every/get-return-method-throws.js
vendored
Normal 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);
|
||||||
|
});
|
10
test/built-ins/Iterator/prototype/every/is-function.js
vendored
Normal file
10
test/built-ins/Iterator/prototype/every/is-function.js
vendored
Normal 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');
|
26
test/built-ins/Iterator/prototype/every/iterator-already-exhausted.js
vendored
Normal file
26
test/built-ins/Iterator/prototype/every/iterator-already-exhausted.js
vendored
Normal 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);
|
27
test/built-ins/Iterator/prototype/every/iterator-has-no-return.js
vendored
Normal file
27
test/built-ins/Iterator/prototype/every/iterator-has-no-return.js
vendored
Normal 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);
|
31
test/built-ins/Iterator/prototype/every/iterator-return-method-throws.js
vendored
Normal file
31
test/built-ins/Iterator/prototype/every/iterator-return-method-throws.js
vendored
Normal 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);
|
||||||
|
});
|
22
test/built-ins/Iterator/prototype/every/length.js
vendored
Normal file
22
test/built-ins/Iterator/prototype/every/length.js
vendored
Normal 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,
|
||||||
|
});
|
29
test/built-ins/Iterator/prototype/every/name.js
vendored
Normal file
29
test/built-ins/Iterator/prototype/every/name.js
vendored
Normal 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,
|
||||||
|
});
|
25
test/built-ins/Iterator/prototype/every/next-method-returns-non-object.js
vendored
Normal file
25
test/built-ins/Iterator/prototype/every/next-method-returns-non-object.js
vendored
Normal 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(() => {});
|
||||||
|
});
|
33
test/built-ins/Iterator/prototype/every/next-method-returns-throwing-done.js
vendored
Normal file
33
test/built-ins/Iterator/prototype/every/next-method-returns-throwing-done.js
vendored
Normal 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(() => {});
|
||||||
|
});
|
30
test/built-ins/Iterator/prototype/every/next-method-returns-throwing-value-done.js
vendored
Normal file
30
test/built-ins/Iterator/prototype/every/next-method-returns-throwing-value-done.js
vendored
Normal 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(() => {});
|
33
test/built-ins/Iterator/prototype/every/next-method-returns-throwing-value.js
vendored
Normal file
33
test/built-ins/Iterator/prototype/every/next-method-returns-throwing-value.js
vendored
Normal 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(() => {});
|
||||||
|
});
|
25
test/built-ins/Iterator/prototype/every/next-method-throws.js
vendored
Normal file
25
test/built-ins/Iterator/prototype/every/next-method-throws.js
vendored
Normal 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(() => {});
|
||||||
|
});
|
22
test/built-ins/Iterator/prototype/every/non-callable-predicate.js
vendored
Normal file
22
test/built-ins/Iterator/prototype/every/non-callable-predicate.js
vendored
Normal 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);
|
||||||
|
});
|
28
test/built-ins/Iterator/prototype/every/non-constructible.js
vendored
Normal file
28
test/built-ins/Iterator/prototype/every/non-constructible.js
vendored
Normal 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(() => {});
|
||||||
|
});
|
43
test/built-ins/Iterator/prototype/every/predicate-args.js
vendored
Normal file
43
test/built-ins/Iterator/prototype/every/predicate-args.js
vendored
Normal 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);
|
33
test/built-ins/Iterator/prototype/every/predicate-returns-falsey.js
vendored
Normal file
33
test/built-ins/Iterator/prototype/every/predicate-returns-falsey.js
vendored
Normal 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);
|
30
test/built-ins/Iterator/prototype/every/predicate-returns-non-boolean.js
vendored
Normal file
30
test/built-ins/Iterator/prototype/every/predicate-returns-non-boolean.js
vendored
Normal 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);
|
34
test/built-ins/Iterator/prototype/every/predicate-returns-truthy-then-falsey.js
vendored
Normal file
34
test/built-ins/Iterator/prototype/every/predicate-returns-truthy-then-falsey.js
vendored
Normal 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);
|
24
test/built-ins/Iterator/prototype/every/predicate-returns-truthy.js
vendored
Normal file
24
test/built-ins/Iterator/prototype/every/predicate-returns-truthy.js
vendored
Normal 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);
|
33
test/built-ins/Iterator/prototype/every/predicate-this.js
vendored
Normal file
33
test/built-ins/Iterator/prototype/every/predicate-this.js
vendored
Normal 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);
|
39
test/built-ins/Iterator/prototype/every/predicate-throws-then-closing-iterator-also-throws.js
vendored
Normal file
39
test/built-ins/Iterator/prototype/every/predicate-throws-then-closing-iterator-also-throws.js
vendored
Normal 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);
|
43
test/built-ins/Iterator/prototype/every/predicate-throws.js
vendored
Normal file
43
test/built-ins/Iterator/prototype/every/predicate-throws.js
vendored
Normal 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);
|
25
test/built-ins/Iterator/prototype/every/prop-desc.js
vendored
Normal file
25
test/built-ins/Iterator/prototype/every/prop-desc.js
vendored
Normal 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,
|
||||||
|
});
|
11
test/built-ins/Iterator/prototype/every/proto.js
vendored
Normal file
11
test/built-ins/Iterator/prototype/every/proto.js
vendored
Normal 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);
|
11
test/built-ins/Iterator/prototype/every/result-is-boolean.js
vendored
Normal file
11
test/built-ins/Iterator/prototype/every/result-is-boolean.js
vendored
Normal 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');
|
17
test/built-ins/Iterator/prototype/every/this-non-callable-next.js
vendored
Normal file
17
test/built-ins/Iterator/prototype/every/this-non-callable-next.js
vendored
Normal 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);
|
||||||
|
});
|
26
test/built-ins/Iterator/prototype/every/this-non-object.js
vendored
Normal file
26
test/built-ins/Iterator/prototype/every/this-non-object.js
vendored
Normal 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, () => {});
|
||||||
|
});
|
32
test/built-ins/Iterator/prototype/every/this-plain-iterator.js
vendored
Normal file
32
test/built-ins/Iterator/prototype/every/this-plain-iterator.js
vendored
Normal 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);
|
30
test/built-ins/Iterator/prototype/filter/argument-effect-order.js
vendored
Normal file
30
test/built-ins/Iterator/prototype/filter/argument-effect-order.js
vendored
Normal 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, []);
|
13
test/built-ins/Iterator/prototype/filter/callable.js
vendored
Normal file
13
test/built-ins/Iterator/prototype/filter/callable.js
vendored
Normal 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);
|
37
test/built-ins/Iterator/prototype/filter/exhaustion-does-not-call-return.js
vendored
Normal file
37
test/built-ins/Iterator/prototype/filter/exhaustion-does-not-call-return.js
vendored
Normal 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();
|
41
test/built-ins/Iterator/prototype/filter/get-next-method-only-once.js
vendored
Normal file
41
test/built-ins/Iterator/prototype/filter/get-next-method-only-once.js
vendored
Normal 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);
|
25
test/built-ins/Iterator/prototype/filter/get-next-method-throws.js
vendored
Normal file
25
test/built-ins/Iterator/prototype/filter/get-next-method-throws.js
vendored
Normal 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);
|
||||||
|
});
|
30
test/built-ins/Iterator/prototype/filter/get-return-method-throws.js
vendored
Normal file
30
test/built-ins/Iterator/prototype/filter/get-return-method-throws.js
vendored
Normal 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();
|
||||||
|
});
|
10
test/built-ins/Iterator/prototype/filter/is-function.js
vendored
Normal file
10
test/built-ins/Iterator/prototype/filter/is-function.js
vendored
Normal 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
Loading…
x
Reference in New Issue
Block a user