Debian Codegraph @

js/src/tests/test262/built-ins/Array/from/iter-map-fn-err.js

raw
1 // Copyright (C) 2015 the V8 project authors. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3 /*---
4 esid: sec-array.from
5 description: Error invoking map function (traversed via iterator)
6 info: |
7 [...]
8 6. If usingIterator is not undefined, then
9 [...]
10 g. Repeat
11 [...]
12 vii. If mapping is true, then
13 1. Let mappedValue be Call(mapfn, T, «nextValue, k»).
14 2. If mappedValue is an abrupt completion, return
15 IteratorClose(iterator, mappedValue).
16 features: [Symbol.iterator]
17 ---*/
18
19 var closeCount = 0;
20 var mapFn = function() {
21 throw new Test262Error();
22 };
23 var items = {};
24 items[Symbol.iterator] = function() {
25 return {
26 return: function() {
27 closeCount += 1;
28 },
29 next: function() {
30 return {
31 done: false
32 };
33 }
34 };
35 };
36
37 assert.throws(Test262Error, function() {
38 Array.from(items, mapFn);
39 }, 'Array.from(items, mapFn) throws a Test262Error exception');
40
41 assert.sameValue(closeCount, 1, 'The value of closeCount is expected to be 1');
42
43 reportCompare(0, 0);