diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/Iterator/prototype/find/predicate-returns-falsey-then-truthy.js')
-rw-r--r-- | js/src/tests/test262/built-ins/Iterator/prototype/find/predicate-returns-falsey-then-truthy.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Iterator/prototype/find/predicate-returns-falsey-then-truthy.js b/js/src/tests/test262/built-ins/Iterator/prototype/find/predicate-returns-falsey-then-truthy.js new file mode 100644 index 0000000000..7a8e2a5b27 --- /dev/null +++ b/js/src/tests/test262/built-ins/Iterator/prototype/find/predicate-returns-falsey-then-truthy.js @@ -0,0 +1,35 @@ +// |reftest| shell-option(--enable-iterator-helpers) skip-if(!this.hasOwnProperty('Iterator')||!xulRuntime.shell) -- iterator-helpers is not enabled unconditionally, requires shell-options +// Copyright (C) 2023 Michael Ficarra. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-iteratorprototype.find +description: > + Iterator.prototype.find returns the found value and closes the iterator when the predicate returns falsey for some iterated values and truthy for others +info: | + %Iterator.prototype%.find ( predicate ) + +features: [iterator-helpers] +flags: [] +---*/ +function* g() { + for (let i = 0; i < 5; ++i) { + yield i; + } +} + +let iter = g(); + +let predicateCalls = 0; +let result = iter.find(v => { + ++predicateCalls; + return v > 2; +}); + +assert.sameValue(result, 3); +assert.sameValue(predicateCalls, 4); + +let { done, value } = iter.next(); +assert.sameValue(done, true); +assert.sameValue(value, undefined); + +reportCompare(0, 0); |