iter-map-fn-args.js (2152B)
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: > 6 Arguments of mapping function (traversed via iterator) 7 info: | 8 [...] 9 2. If mapfn is undefined, let mapping be false. 10 3. else 11 a. If IsCallable(mapfn) is false, throw a TypeError exception. 12 b. If thisArg was supplied, let T be thisArg; else let T be undefined. 13 c. Let mapping be true 14 [...] 15 6. If usingIterator is not undefined, then 16 [...] 17 g. Repeat 18 [...] 19 vii. If mapping is true, then 20 1. Let mappedValue be Call(mapfn, T, «nextValue, k»). 21 2. If mappedValue is an abrupt completion, return 22 IteratorClose(iterator, mappedValue). 23 3. Let mappedValue be mappedValue.[[value]]. 24 features: [Symbol.iterator] 25 ---*/ 26 27 var args = []; 28 var firstResult = { 29 done: false, 30 value: {} 31 }; 32 var secondResult = { 33 done: false, 34 value: {} 35 }; 36 var mapFn = function(value, idx) { 37 args.push(arguments); 38 }; 39 var items = {}; 40 var nextResult = firstResult; 41 var nextNextResult = secondResult; 42 43 items[Symbol.iterator] = function() { 44 return { 45 next: function() { 46 var result = nextResult; 47 nextResult = nextNextResult; 48 nextNextResult = { 49 done: true 50 }; 51 52 return result; 53 } 54 }; 55 }; 56 57 Array.from(items, mapFn); 58 59 assert.sameValue(args.length, 2, 'The value of args.length is expected to be 2'); 60 61 assert.sameValue(args[0].length, 2, 'The value of args[0].length is expected to be 2'); 62 assert.sameValue( 63 args[0][0], firstResult.value, 'The value of args[0][0] is expected to equal the value of firstResult.value' 64 ); 65 assert.sameValue(args[0][1], 0, 'The value of args[0][1] is expected to be 0'); 66 67 assert.sameValue(args[1].length, 2, 'The value of args[1].length is expected to be 2'); 68 assert.sameValue( 69 args[1][0], secondResult.value, 'The value of args[1][0] is expected to equal the value of secondResult.value' 70 ); 71 assert.sameValue(args[1][1], 1, 'The value of args[1][1] is expected to be 1'); 72 73 reportCompare(0, 0);