Debian Codegraph @

js/src/tests/test262/built-ins/Array/fromAsync/mapfn-sync-throws-close-sync-iterator.js

raw
1 // |reftest| async
2 // Copyright (C) 2023 Igalia, S.L. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4
5 /*---
6 esid: sec-array.fromasync
7 description: >
8 The iterator of a synchronous iterable is closed when the synchronous mapping
9 function throws.
10 info: |
11 3.j.ii.6. If _mapping_ is *true*, then
12 a. Let _mappedValue_ be Call(_mapfn_, _thisArg_, « _nextValue_, 𝔽(_k_) »).
13 b. IfAbruptCloseAsyncIterator(_mappedValue_, _iteratorRecord_).
14 ...
15 flags: [async]
16 includes: [asyncHelpers.js]
17 features: [Array.fromAsync]
18 ---*/
19
20 let closed = false;
21 const iterator = {
22 next() {
23 return { value: 1, done: false };
24 },
25 return() {
26 closed = true;
27 return { done: true };
28 },
29 [Symbol.iterator]() {
30 return this;
31 }
32 }
33
34 asyncTest(async () => {
35 await assert.throwsAsync(Error, () => Array.fromAsync(iterator, (val) => {
36 assert.sameValue(val, 1, "mapfn receives value from iterator");
37 throw new Error("mapfn throws");
38 }), "sync mapfn throwing should cause fromAsync to reject");
39 assert(closed, "sync mapfn throwing should close iterator")
40 });