Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/Array/from/iter-map-fn-this-strict.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 es6id: 22.1.2.1
6 description: >
7 `this` value of mapping function in strict mode (traversed via iterator)
8 info: |
9 [...]
10 2. If mapfn is undefined, let mapping be false.
11 3. else
12 a. If IsCallable(mapfn) is false, throw a TypeError exception.
13 b. If thisArg was supplied, let T be thisArg; else let T be undefined.
14 c. Let mapping be true
15 [...]
16 6. If usingIterator is not undefined, then
17 [...]
18 g. Repeat
19 [...]
20 vii. If mapping is true, then
21 1. Let mappedValue be Call(mapfn, T, «nextValue, k»).
22 features: [Symbol.iterator]
23 flags: [onlyStrict]
24 ---*/
25
26 var thisVals = [];
27 var nextResult = {
28 done: false,
29 value: {}
30 };
31 var nextNextResult = {
32 done: false,
33 value: {}
34 };
35 var mapFn = function() {
36 thisVals.push(this);
37 };
38 var items = {};
39
40 items[Symbol.iterator] = function() {
41 return {
42 next: function() {
43 var result = nextResult;
44 nextResult = nextNextResult;
45 nextNextResult = {
46 done: true
47 };
48
49 return result;
50 }
51 };
52 };
53
54 Array.from(items, mapFn);
55
56 assert.sameValue(thisVals.length, 2);
57 assert.sameValue(thisVals[0], undefined, 'First iteration `this` value');
58 assert.sameValue(thisVals[1], undefined, 'Second iteration `this` value');