Debian Codegraph @

js/src/tests/test262/built-ins/Object/fromEntries/iterator-closed-for-throwing-entry-value-accessor.js

raw
1 // Copyright (C) 2018 Kevin Gibbons. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 esid: sec-object.fromentries
6 description: Closes iterators when accessing an entry's value throws.
7 info: |
8 Object.fromEntries ( iterable )
9
10 ...
11 4. Let stepsDefine be the algorithm steps defined in CreateDataPropertyOnObject Functions.
12 5. Let adder be CreateBuiltinFunction(stepsDefine, « »).
13 6. Return ? AddEntriesFromIterable(obj, iterable, adder).
14
15 AddEntriesFromIterable ( target, iterable, adder )
16
17 ...
18 4. Repeat,
19 ...
20 g. Let v be Get(nextItem, "1").
21 h. If v is an abrupt completion, return ? IteratorClose(iteratorRecord, v).
22
23 features: [Symbol.iterator, Object.fromEntries]
24 ---*/
25
26 function DummyError() {}
27
28 var returned = false;
29 var iterable = {
30 [Symbol.iterator]: function() {
31 var advanced = false;
32 return {
33 next: function() {
34 if (advanced) {
35 throw new Test262Error('should only advance once');
36 }
37 advanced = true;
38 return {
39 done: false,
40 value: {
41 get '0'() {
42 return 'key';
43 },
44 get '1'() {
45 throw new DummyError();
46 },
47 },
48 };
49 },
50 return: function() {
51 if (returned) {
52 throw new Test262Error('should only return once');
53 }
54 returned = true;
55 },
56 };
57 },
58 };
59
60 assert.throws(DummyError, function() {
61 Object.fromEntries(iterable);
62 });
63
64 assert(returned, 'iterator should be closed when entry value property access throws');
65
66 reportCompare(0, 0);