| 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 they return entries which are strings. |
| 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 |
d. If Type(nextItem) is not Object, then |
| 21 |
i. Let error be ThrowCompletion(a newly created TypeError object). |
| 22 |
ii. Return ? IteratorClose(iteratorRecord, error). |
| 23 |
|
| 24 |
features: [Symbol.iterator, Object.fromEntries] |
| 25 |
---*/ |
| 26 |
|
| 27 |
var returned = false; |
| 28 |
var iterable = { |
| 29 |
[Symbol.iterator]: function() { |
| 30 |
var advanced = false; |
| 31 |
return { |
| 32 |
next: function() { |
| 33 |
if (advanced) { |
| 34 |
throw new Test262Error('should only advance once'); |
| 35 |
} |
| 36 |
advanced = true; |
| 37 |
return { |
| 38 |
done: false, |
| 39 |
value: 'ab', |
| 40 |
}; |
| 41 |
}, |
| 42 |
return: function() { |
| 43 |
if (returned) { |
| 44 |
throw new Test262Error('should only return once'); |
| 45 |
} |
| 46 |
returned = true; |
| 47 |
}, |
| 48 |
}; |
| 49 |
}, |
| 50 |
}; |
| 51 |
|
| 52 |
assert.sameValue(typeof Object.fromEntries, 'function'); |
| 53 |
assert.throws(TypeError, function() { |
| 54 |
Object.fromEntries(iterable); |
| 55 |
}); |
| 56 |
|
| 57 |
assert(returned, 'iterator should be closed when entry is a string'); |
| 58 |
|
| 59 |
reportCompare(0, 0); |